OnAttribute
in package
Abstract base for all `#[On*]` scene event-marker attributes.
Each concrete subclass (e.g. OnMessage, OnCallbackQuery) corresponds to
one Telegram event observer and injects the observer name constant at
construction time.
Design note — Option B (14 attributes with ?SceneAction $action):
Upstream uses 14 ObserverMarker instances on a single OnMarker namespace
class, with per-marker .enter(), .leave(), .exit(), .back() chainable
factories (aiogram/fsm/scene.py:975-980). The plan mentions "25 total"
attributes, but the cleanest PHP equivalent is 14 attribute classes that
carry the lifecycle action as an optional constructor arg:
// run on any message while in scene #[OnMessage]
// run when entering the scene via a message #[OnMessage(action: SceneAction::Enter)]
// run on callback_query and then go back #[OnCallbackQuery(after: After::back())]
This yields 14 classes instead of 25 or 70, while covering all the same behavioural combinations. Task 5.9+ will read these attributes via reflection to wire scene handlers into the dispatcher.
Attributes flags:
Attribute::TARGET_METHOD— valid on methods only.Attribute::IS_REPEATABLE— a method may carry multiple#[On*]decorators (e.g., the same handler fires on bothEnterand a default message event).
Table of Contents
Properties
- $action : SceneAction|null
- Optional lifecycle action filter.
- $after : After|null
- Optional post-handler action.
- $event : string
- The Telegram observer name this attribute targets (e.g. `'message'`, `'callback_query'`). Set by subclass constructors.
- $filters : array<int, Filter>
- Optional dispatcher filters that must pass before this handler fires.
Methods
- __construct() : mixed
Properties
$action
Optional lifecycle action filter.
public
SceneAction|null
$action
null— the handler runs for any event of this type while in scene.SceneAction::Enter— runs when entering the scene via this event.SceneAction::Leave— runs when leaving the scene via this event.SceneAction::Exit— runs when exiting FSM via this event.SceneAction::Back— runs when rolling back via this event.
$after
Optional post-handler action.
public
After|null
$after
When non-null, the framework will execute this action (exit / back /
goto) automatically after the handler method returns, saving the user
from having to call $this->wizard->exit() etc. manually.
Mirrors the after= parameter on ObserverDecorator
(aiogram/fsm/scene.py:113).
$event
The Telegram observer name this attribute targets (e.g. `'message'`, `'callback_query'`). Set by subclass constructors.
public
string
$event
$filters
Optional dispatcher filters that must pass before this handler fires.
public
array<int, Filter>
$filters
Mirrors the *filters positional args on ObserverMarker.__call__
(aiogram/fsm/scene.py:939-944).
Methods
__construct()
public
__construct(string $event[, null|SceneAction $action = null ][, null|After $after = null ], Filter ...$filters) : mixed
Parameters
- $event : string
-
Observer name injected by each concrete subclass.
- $action : null|SceneAction = null
-
Lifecycle action filter.
- $after : null|After = null
-
Post-handler action.
- $filters : Filter
-
Additional dispatcher filters.