CallableObject
in package
Reflection-cached "kwarg binder" mirroring upstream `aiogram.dispatcher.event.handler.CallableObject`. The dispatcher injects a large bag of context arguments (`bot`, `event_context`, `event_from_user`, `state`, …) and each handler declares only the subset it actually needs.
call() filters the kwargs map down to the parameter names the underlying
\Closure exposes before forwarding it.
Departures from the Python original (intentional, all sync-runtime):
- No
awaitableflag — phpbotgram is synchronous from the caller's PoV; Fibers handle non-blocking I/O at the transport layer and are invisible here, so we always invoke the closure directly with noasyncio.to_threadequivalent. paramsis preserved as an ordered map (array<string,true>) instead of an unorderedset[str]; this keepsparams()deterministic for tests and gives us a free O(1) membership check viaarray_intersect_key.- The PHP variadic parameter (
...$args) maps onto Python's**kwargssemantics — when present we forward every kwarg without filtering. PHP 8.1+func(...$assoc)treats string keys as named arguments, so a variadic closure receives them as its variadic array.
Subclassed by FilterObject and HandlerObject to add filter-result
interpretation + per-handler metadata, mirroring aiogram's
event/handler.py inheritance shape. PHP convention usually marks leaf
classes final; this class is intentionally left open for that subclass
chain only — no other extensions are expected.
Table of Contents
Properties
- $callback : Closure
- $params : array<string, true>
- Parameter names the closure declares, in declaration order, mapped to `true` so `array_intersect_key` can filter the kwargs in one call.
- $varKw : bool
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
$callback read-only
public
Closure
$callback
$params
Parameter names the closure declares, in declaration order, mapped to `true` so `array_intersect_key` can filter the kwargs in one call.
private
array<string, true>
$params
$varKw
private
bool
$varKw
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
boolparams()
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>