phpbotgram

MagicFilterAsFilter extends Filter
in package

FinalYes

Bridge that turns a `MagicFilter` chain into a dispatcher-consumable `Filter`. Mirrors the upstream `MagicFilter` → `Filter` adapter behaviour: aiogram passes a `MagicFilter` instance straight where a `Filter` is expected and the dispatcher's `_check` wraps it via `MagicFilter.resolve`. The PHP `Filter` abstract is more rigid (`__invoke(object, array)`); this bridge implements that contract.

Acceptance contract — matches the rules documented in the spec (Layer 1, Utils\MagicFilter\MagicFilter):

  • Chain raised RejectOperations mid-walk → return false.
  • Final value is null → return false.
  • Final value is an array<string, mixed> with at least one entry → return the array verbatim (the dispatcher merges it into handler kwargs).
  • Final value is an empty array → return false (matches the "empty iterable rejects" rule from upstream's AsFilterResultOperation).
  • Any other value → coerce to bool and return.

Table of Contents

Properties

$magic  : MagicFilter

Methods

__construct()  : mixed
__invoke()  : array<string, mixed>|bool
Evaluate the filter against an update.
all()  : AndFilter
Compose an AND across filters: every child must accept, kwargs cascade. PHP equivalent of Python's `f1 & f2`.
any()  : OrFilter
Compose an OR across filters: the first accepting child wins, no cascade. PHP equivalent of Python's `f1 | f2`.
invertOf()  : InvertFilter
Invert a filter's accept/reject decision. Named `invertOf` rather than `not` because PHP forbids a static and an instance method sharing one name in a single class (the instance-side `$f->not()` convenience may land in a later task).

Properties

Methods

__invoke()

Evaluate the filter against an update.

public __invoke(object $event, mixed ...$kwargs) : array<string, mixed>|bool

$kwargs is captured variadically so that CallableObject::prepareKwargs detects the variadic tail and passes through the ENTIRE dispatcher kwargs bag (bot, event_context, state, …) rather than intersecting it down to only the parameter names literally declared here. The variadic capture produces a regular array<string, mixed> inside the method body, so existing accesses like $kwargs['bot'] ?? null continue to work unchanged.

Parameters
$event : object
$kwargs : mixed
Return values
array<string, mixed>|bool

See class docblock for the interpretation contract.

all()

Compose an AND across filters: every child must accept, kwargs cascade. PHP equivalent of Python's `f1 & f2`.

public static all(Filter ...$filters) : AndFilter
Parameters
$filters : Filter
Return values
AndFilter

any()

Compose an OR across filters: the first accepting child wins, no cascade. PHP equivalent of Python's `f1 | f2`.

public static any(Filter ...$filters) : OrFilter
Parameters
$filters : Filter
Return values
OrFilter

invertOf()

Invert a filter's accept/reject decision. Named `invertOf` rather than `not` because PHP forbids a static and an instance method sharing one name in a single class (the instance-side `$f->not()` convenience may land in a later task).

public static invertOf(Filter $filter) : InvertFilter
Parameters
$filter : Filter
Return values
InvertFilter
On this page

Search results