phpbotgram

ScenesManager
in package
implements SceneManagerInterface

FinalYes

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 $checkActive is false the exit step is skipped (used by SceneWizard for 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 bound HistoryManager instance.

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

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.

mergeData()

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
string

getActiveScene()

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|null

getScene()

Instantiate the scene identified by `$sceneType`.

private getScene(null|Scene>|State|string $sceneType) : Scene

Resolves $sceneType through the registry and constructs a SceneWizard

  • Scene pair with a circular back-reference.

Mirrors ScenesManager._get_scene (aiogram/fsm/scene.py:669-679).

Parameters
$sceneType : null|Scene>|State|string
Tags
throws
SceneException

When $sceneType cannot be resolved.

Return values
Scene
On this page

Search results