CallbackPrefix
in package
Class-level metadata carrier for `CallbackData` subclasses. Declares the wire prefix and separator that the framework uses to pack/unpack a typed callback-data payload.
#[CallbackPrefix('order', sep: ':')] final class OrderCallback extends CallbackData { ... }
Mirrors upstream's class OrderCallback(CallbackData, prefix='order', sep=':') keyword-argument-on-subclass syntax (aiogram/filters/ callback_data.py:50-65). PHP has no equivalent of __init_subclass__
for capturing class-declaration keywords, so we substitute a class-level
attribute. CallbackData::reflectMeta reads it once per subclass and
caches nothing (PHP's reflection cache makes the per-call lookup cheap;
adding a memo map would add complexity for negligible win).
Constraints:
- Targets classes only (not methods/properties) — pinned by the
Attribute::TARGET_CLASSflag and verified inCallbackPrefixTest::testAttributeIsClassTargeted. - Not repeatable: each subclass declares exactly one
#[CallbackPrefix]. ThegetAttributes()lookup picks the first entry but PHP itself rejects stacking whenIS_REPEATABLEis omitted from the flag set, so the invariant is engine-enforced. - The base validates that
$sepis not contained in$prefixlazily, insideCallbackData::reflectMeta. Doing the check inside the attribute constructor would require throwing during attribute instantiation, which couples failure mode to reflection timing.
Attributes
- #[Attribute]
- \Attribute::TARGET_CLASS
Table of Contents
Properties
Methods
- __construct() : mixed
Properties
$prefix
public
string
$prefix
$sep
public
string
$sep
= ':'
Methods
__construct()
public
__construct(string $prefix[, non-empty-string $sep = ':' ]) : mixed
Parameters
- $prefix : string
- $sep : non-empty-string = ':'
-
Separator between encoded fields. Pinned as
non-empty-stringsoexplode($sep, $wire)inCallbackData:: unpackdoesn't trip PHPStan'sargument.typecheck at level 9. The runtime equivalent of this constraint is enforced insideCallbackData::reflectMeta, which raisesLogicExceptionwhen the separator is empty — but the type system carries the same guarantee statically.