phpbotgram

CallbackQueryFilter extends Filter
in package

FinalYes

Dispatcher-side filter that bridges incoming `CallbackQuery` events to a typed `CallbackData` subclass. Created via `MyCallbackData::filter()`, not instantiated directly by user code (though direct construction is supported for tests and Logic combinator wiring).

Port of aiogram.filters.callback_data.CallbackQueryFilter (aiogram/filters/callback_data.py:152-194).

Behavior

  1. Reject when the event isn't a CallbackQuery or carries no data.
  2. Call $callbackDataClass::unpack($data).
  3. On success → return ['callback_data' => $parsed] so the parsed instance reaches the handler as the $callback_data kwarg. The kwarg name is the snake_case form mirroring upstream's {"callback_data": callback_data} return shape.
  4. On unpack() failure (prefix mismatch, arity mismatch, …) → collapse the exception to false so the dispatcher can move on to the next handler. Matches upstream's except (TypeError, ValueError): return False.

MagicFilter rule

Upstream's __init__(*, callback_data, rule) accepts an optional MagicFilter post-validation rule. Task 4.8 keeps the surface parameter-less; the rule argument lands when Phase 4.5+ wires MagicData/the F-DSL into the filter chain.

Table of Contents

Properties

$callbackDataClass  : string

Methods

__construct()  : mixed
__invoke()  : array<string, mixed>|false
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

__construct()

public __construct(CallbackData> $callbackDataClass) : mixed
Parameters
$callbackDataClass : CallbackData>

The bound subclass that drives unpack(). Pinned at construction so __invoke can dispatch without re-resolving the target type.

__invoke()

Evaluate the filter against an update.

public __invoke(object $event, mixed ...$kwargs) : array<string, mixed>|false
Parameters
$event : object
$kwargs : mixed
Return values
array<string, mixed>|false

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