phpbotgram

FilterObject extends CallableObject
in package

FinalYes

Wraps a filter callback that votes on whether a handler should run for a given update. Mirrors upstream `aiogram.dispatcher.event.handler.FilterObject`.

A filter callback may return:

  • false (or any falsy value: null, 0, '', []) — reject; the handler is skipped and later filters in the same handler don't run.
  • true (or any truthy non-array: 1, non-empty string, object) — accept; no extra kwargs are injected for downstream consumption.
  • array<string, mixed> (associative) — accept and merge the entries into the kwargs bag that flows to subsequent filters and the eventual handler (this is how command/regex match data gets threaded into handlers upstream).

The result-interpretation logic itself lives in HandlerObject::check() — FilterObject is intentionally a thin marker over CallableObject so its inherited call() can be used uniformly inside that pipeline. Phase 4 will widen this class to bind a MagicFilter value into the underlying callback when registered with the F-builder DSL — until then it adds nothing of its own beyond the inheritance.

Table of Contents

Properties

$callback  : Closure

Methods

__construct()  : mixed
call()  : mixed
Invoke the underlying closure. Positional `$args` are forwarded as-is; `$kwargs` is filtered via `prepareKwargs()` so a closure declaring only `$a` won't choke on an extra `bot:` kwarg the dispatcher injected.
isVariadic()  : bool
Whether the callback declares a variadic tail (`...$rest`). When true, `prepareKwargs()` becomes a no-op pass-through.
params()  : array<int, string>
Names of the declared (non-variadic) parameters in source order. The variadic tail, if any, is reported separately via `isVariadic()`.
prepareKwargs()  : array<string, mixed>
Filter `$kwargs` down to the keys the closure actually declares. When the closure has a variadic tail, every kwarg passes through untouched.

Properties

Methods

__construct()

public __construct(Closure $callback) : mixed
Parameters
$callback : Closure

call()

Invoke the underlying closure. Positional `$args` are forwarded as-is; `$kwargs` is filtered via `prepareKwargs()` so a closure declaring only `$a` won't choke on an extra `bot:` kwarg the dispatcher injected.

public call([array<int, mixed> $args = [] ][, array<string, mixed> $kwargs = [] ]) : mixed

Relies on PHP 8.1+ named-argument unpacking: ($cb)(...$args, ...$kwargs) forwards the integer-keyed entries positionally and the string-keyed entries as named arguments.

Exceptions raised by the callback propagate unchanged — no try/catch, matching upstream.

Parameters
$args : array<int, mixed> = []
$kwargs : array<string, mixed> = []

isVariadic()

Whether the callback declares a variadic tail (`...$rest`). When true, `prepareKwargs()` becomes a no-op pass-through.

public isVariadic() : bool
Return values
bool

params()

Names of the declared (non-variadic) parameters in source order. The variadic tail, if any, is reported separately via `isVariadic()`.

public params() : array<int, string>
Return values
array<int, string>

prepareKwargs()

Filter `$kwargs` down to the keys the closure actually declares. When the closure has a variadic tail, every kwarg passes through untouched.

public prepareKwargs(array<string, mixed> $kwargs) : array<string, mixed>
Parameters
$kwargs : array<string, mixed>
Return values
array<string, mixed>
On this page

Search results