ScenesManager
in package
implements
SceneManagerInterface
Per-update scene transition front-end.
ScenesManager is the entry point for wizard-style navigation. It resolves
the current active scene (by looking up the FSM state in the registry),
instantiates scene objects, and delegates lifecycle calls (enter, exit)
through SceneWizard.
Mirrors ScenesManager (aiogram/fsm/scene.py:659-743).
Responsibilities
enter($scene)— exits the currently active scene (if any) and enters the requested one. When$checkActiveisfalsethe exit step is skipped (used bySceneWizardfor chained transitions that have already handled leaving the old scene).close()— exits the currently active scene without transitioning to a new one.history()— accessor for the boundHistoryManagerinstance.
Registry contract
The injected SceneRegistryInterface::get() resolves a class-string, State
instance, or bare state string to a concrete class-string<Scene>. It
throws SceneException when the identifier is unknown (including null).
ScenesManager relies on this exception to detect the "clear FSM state"
path: when $scene is null and get() throws, FSM state is cleared
instead of entering a new scene.
Table of Contents
Interfaces
- SceneManagerInterface
- Controls scene transitions on behalf of `SceneWizard`.
Properties
- $data : array<string, mixed>
- $event : object
- $historyManager : HistoryManager
- History manager for this update session.
- $registry : SceneRegistryInterface
- $state : FsmContext
- $updateType : string
Methods
- __construct() : mixed
- close() : void
- Exit the currently active scene without entering a new one.
- enter() : void
- Transition to the given scene (or clear FSM state when `null`).
- history() : HistoryManagerInterface
- Access the history manager for this scene session.
- mergeData() : void
- Merge additional data into this manager's data bag.
- updateType() : string
- Return the update-type key this manager was created for.
- getActiveScene() : Scene|null
- Return the currently active `Scene` instance, or `null` if none.
- getScene() : Scene
- Instantiate the scene identified by `$sceneType`.
Properties
$data
private
array<string, mixed>
$data
$event read-only
private
object
$event
$historyManager read-only
History manager for this update session.
private
HistoryManager
$historyManager
$registry read-only
private
SceneRegistryInterface
$registry
$state read-only
private
FsmContext
$state
$updateType read-only
private
string
$updateType
Methods
__construct()
public
__construct(SceneRegistryInterface $registry, string $updateType, object $event, FsmContext $state, array<string, mixed> $data) : mixed
Parameters
- $registry : SceneRegistryInterface
-
Scene-class resolver.
- $updateType : string
-
Telegram update-type key (e.g.
'message'). - $event : object
-
The raw Telegram event object.
- $state : FsmContext
-
FSM context for state + data operations.
- $data : array<string, mixed>
-
Dispatcher kwargs bag.
close()
Exit the currently active scene without entering a new one.
public
close(mixed ...$kwargs) : void
When no scene is currently active this method is a no-op (matches upstream
Python behaviour where close() silently returns when _get_active_scene
yields None).
Mirrors ScenesManager.close (aiogram/fsm/scene.py:708-712).
Parameters
- $kwargs : mixed
-
Additional context forwarded to the exit handler.
enter()
Transition to the given scene (or clear FSM state when `null`).
public
enter(null|Scene>|State|string $scene[, bool $checkActive = true ], mixed ...$kwargs) : void
When $checkActive is true (the default) and a scene is currently
active, its SceneWizard::exit() is invoked before entering the new scene.
Passing null for $scene combined with an unknown registry entry causes
the FSM state to be cleared via FsmContext::setState(null). Any extra
$kwargs are merged into the data bag and forwarded to lifecycle methods.
Mirrors ScenesManager.enter (aiogram/fsm/scene.py:687-706).
Parameters
- $scene : null|Scene>|State|string
-
Target scene.
- $checkActive : bool = true
-
Skip the "exit active scene" guard when
false. - $kwargs : mixed
-
Additional context merged into the data bag.
history()
Access the history manager for this scene session.
public
history() : HistoryManagerInterface
Mirrors ScenesManager.history (implicit property, aiogram/fsm/scene.py:665).
Return values
HistoryManagerInterfacemergeData()
Merge additional data into this manager's data bag.
public
mergeData(array<string, mixed> $extra) : void
Used by SceneHandlerWrapper to inject the full dispatcher kwargs bag
so the scene wizard and lifecycle actions have access to bot,
event_context, etc.
Mirrors scenes.data = {**scenes.data, **kwargs} in
SceneHandlerWrapper.__call__ (aiogram/fsm/scene.py:262).
Parameters
- $extra : array<string, mixed>
updateType()
Return the update-type key this manager was created for.
public
updateType() : string
Used by SceneHandlerWrapper to populate the SceneWizard's
$updateType field without requiring access to the private property.
Mirrors the update_type field on ScenesManager
(aiogram/fsm/scene.py:659).
Return values
stringgetActiveScene()
Return the currently active `Scene` instance, or `null` if none.
private
getActiveScene() : Scene|null
Reads the current FSM state and attempts to resolve it via the registry.
When the state is null or the registry does not know it, null is
returned rather than propagating a SceneException.
Mirrors ScenesManager._get_active_scene (aiogram/fsm/scene.py:681-685).
Return values
Scene|nullgetScene()
Instantiate the scene identified by `$sceneType`.
private
getScene(null|Scene>|State|string $sceneType) : Scene
Resolves $sceneType through the registry and constructs a SceneWizard
Scenepair with a circular back-reference.
Mirrors ScenesManager._get_scene (aiogram/fsm/scene.py:669-679).
Parameters
- $sceneType : null|Scene>|State|string