phpbotgram

MagicData extends Filter
in package

FinalYes

Filter that resolves a `MagicFilter` chain against the dispatch data dict, i.e. `['event' => $event, ...$kwargs]`. Allows chain expressions to reach into both the event payload AND the dispatcher's contextual kwargs (FSM state, storage, bot, anything middleware injected):

F->event->text->equals('hi') // navigate event payload F->state->equals(SomeState::Active) // navigate FSM kwarg (Phase 5+) F->fsm_storage->equals(null) // any kwarg by name

1-for-1 port of upstream aiogram.filters.magic_data.MagicData (aiogram/filters/magic_data.py). Upstream wraps {'event': event, **kwargs} in magic_filter.AttrDict before handing it to MagicFilter.resolve. The PHP port mirrors that exactly — kwargs flow through our own AttrDict (which mirrors magic_filter.AttrDict) so property-style access (F->state) and subscript-style access (F->item('state')) both work transparently.

Distinct from MagicFilterAsFilter: that bridge resolves a chain against the EVENT directly (F->id->equals(...)); this filter resolves against the WIDER kwargs bag with the event keyed under event. Use this filter when a rule needs to depend on contextual kwargs alongside (or instead of) the event payload.

Result interpretation matches the bridge: null/false → reject, kwarg-shaped array → accept with merged kwargs, any other truthy value → plain accept.

Table of Contents

Properties

$magicData  : 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