phpbotgram

HistoryManager
in package
implements HistoryManagerInterface

FinalYes

Manages the scene history stack for back-navigation.

Stores a bounded list of {state, data} snapshots in a separate FSM destiny slot so that they do not interfere with the main conversation state. Scene lifecycle methods (leave, back, exit) interact with this class via the HistoryManagerInterface surface exposed through SceneWizard.

Mirrors HistoryManager (aiogram/fsm/scene.py:32-105).

Destiny isolation

The history records are written to a cloned StorageKey whose destiny tag is set to $destiny (default 'scenes_history'). All other key fields (bot, chat, user, thread, business connection) remain identical, so the history stack is per-conversation but separate from the primary FSM slot.

Size cap

After every push() the list is trimmed to the last $size entries (oldest entries are evicted). Python equivalent: history[-self._size:].

Table of Contents

Interfaces

HistoryManagerInterface
Manages the scene history stack for back-navigation.

Properties

$historyState  : FsmContext
FSM context that addresses the history-specific storage slot.
$size  : int
$state  : FsmContext

Methods

__construct()  : mixed
all()  : array<int, MemoryStorageRecord>
Return all history entries as a list of `MemoryStorageRecord` objects.
clear()  : void
Remove all entries from the history stack.
get()  : null|MemoryStorageRecord
Peek at the last history entry without removing it.
pop()  : null|MemoryStorageRecord
Remove and return the last history entry.
push()  : void
Append a `{state, data}` entry to the history stack.
rollback()  : null|string
Pop the last history entry and restore the main FSM to its values.
snapshot()  : void
Record the current main FSM state and data onto the top of the stack.
loadHistory()  : array<int, array{state: null|string, data: array}>
Load the raw history list from the history storage slot.
setState()  : void
Apply `$state` and `$data` to the main FSM context.

Properties

$historyState read-only

FSM context that addresses the history-specific storage slot.

private FsmContext $historyState

Methods

__construct()

public __construct(FsmContext $state[, string $destiny = 'scenes_history' ][, int $size = 10 ]) : mixed
Parameters
$state : FsmContext

Main FSM context (provides storage + key).

$destiny : string = 'scenes_history'

Destiny tag for the history storage slot.

$size : int = 10

Maximum number of history entries to retain.

clear()

Remove all entries from the history stack.

public clear() : void

Mirrors HistoryManager.clear (aiogram/fsm/scene.py:79-80).

get()

Peek at the last history entry without removing it.

public get() : null|MemoryStorageRecord

Mirrors HistoryManager.get (aiogram/fsm/scene.py:…).

Return values
null|MemoryStorageRecord

The last entry as a record, or null when the history stack is empty.

pop()

Remove and return the last history entry.

public pop() : null|MemoryStorageRecord

After the entry is removed, if the stack is now empty the history data is cleared (set to }). Otherwise the trimmed list is persisted.

Mirrors HistoryManager.pop (aiogram/fsm/scene.py:66-76).

Return values
null|MemoryStorageRecord

The popped entry as a record, or null when the history stack was empty.

push()

Append a `{state, data}` entry to the history stack.

public push(null|string $state, array<string, mixed> $data) : void

If the resulting list length exceeds $this->size, the oldest entries are dropped so that only the most recent $size entries are retained.

Mirrors HistoryManager.push (aiogram/fsm/scene.py:56-64).

Parameters
$state : null|string

Serialised state name (or null).

$data : array<string, mixed>

FSM data payload.

rollback()

Pop the last history entry and restore the main FSM to its values.

public rollback() : null|string

When the stack is empty after popping (or was already empty), the main FSM state is cleared to null with an empty data map.

Mirrors HistoryManager.rollback (aiogram/fsm/scene.py:87-96).

Return values
null|string

The state string from the popped entry, or null when the history was empty.

snapshot()

Record the current main FSM state and data onto the top of the stack.

public snapshot() : void

Mirrors HistoryManager.snapshot (aiogram/fsm/scene.py:82-85).

loadHistory()

Load the raw history list from the history storage slot.

private loadHistory() : array<int, array{state: null|string, data: array}>
Return values
array<int, array{state: null|string, data: array}>

setState()

Apply `$state` and `$data` to the main FSM context.

private setState(string|null $state, array<string, mixed> $data) : void
Parameters
$state : string|null
$data : array<string, mixed>
On this page

Search results