phpbotgram

FsmContext
in package

FinalYes

Per-context FSM handle that delegates all operations to the backing storage.

Mirrors aiogram.fsm.context.FSMContext (aiogram/fsm/context.py).

Each instance is bound to a specific StorageKey (bot + chat + user + optional thread/destiny) so callers can read/write FSM state and data without managing the key themselves.

Async note: phpbotgram exposes a sync-style public surface. Implementations of BaseStorage may suspend internally via Amp (Revolt event loop) but must not leak async primitives through this interface.

State type note: upstream Python uses str | State | None. PHP tightens object to State once Gruven\PhpBotGram\Fsm\State is available (Task 5.5 has landed). The current signature uses string|State|null which maps cleanly to BaseStorage::setState.

Table of Contents

Properties

$key  : StorageKey
$storage  : BaseStorage

Methods

__construct()  : mixed
clear()  : void
Reset both state and data to their empty defaults.
getData()  : array<string, mixed>
Retrieve the current FSM data payload for this context.
getState()  : string|null
Get the current FSM state for this context.
getValue()  : mixed
Read a single value from the FSM data payload for this context.
setData()  : void
Replace the FSM data payload for this context entirely.
setState()  : void
Set the FSM state for this context.
updateData()  : array<string, mixed>
Merge data into the existing FSM data payload for this context.

Properties

Methods

clear()

Reset both state and data to their empty defaults.

public clear() : void

Equivalent to calling setState(null) followed by setData([]).

Mirrors FSMContext.clear (aiogram/fsm/context.py).

getData()

Retrieve the current FSM data payload for this context.

public getData() : array<string, mixed>

Delegates to BaseStorage::getData($this->key).

Return values
array<string, mixed>

Current data map (may be empty).

Mirrors FSMContext.get_data (aiogram/fsm/context.py).

getState()

Get the current FSM state for this context.

public getState() : string|null

Delegates to BaseStorage::getState($this->key).

Return values
string|null

Serialised state name, or null if no state is set.

Mirrors FSMContext.get_state (aiogram/fsm/context.py).

getValue()

Read a single value from the FSM data payload for this context.

public getValue(string $key[, mixed $default = null ]) : mixed

Delegates to BaseStorage::getValue($this->key, $key, $default).

Parameters
$key : string

Dict key within the data payload.

$default : mixed = null

Value returned when $key is absent.

Return values
mixed

The stored value, or $default.

Mirrors FSMContext.get_value (aiogram/fsm/context.py).

setData()

Replace the FSM data payload for this context entirely.

public setData(array<string, mixed> $data) : void

Delegates to BaseStorage::setData($this->key, $data).

Parameters
$data : array<string, mixed>

Data map to store.

Mirrors FSMContext.set_data (aiogram/fsm/context.py).

setState()

Set the FSM state for this context.

public setState([null|State|string $state = null ]) : void

When $state is a State instance, its qualified name (from state()) is extracted before being forwarded to the storage backend. This ensures that BaseStorage::setState always receives a string|null regardless of whether the caller passed a State object or a raw string.

Delegates to BaseStorage::setState($this->key, ...).

Parameters
$state : null|State|string = null

New state. null clears the state.

Mirrors FSMContext.set_state (aiogram/fsm/context.py).

updateData()

Merge data into the existing FSM data payload for this context.

public updateData([array<string, mixed>|null $data = null ], mixed ...$kwargs) : array<string, mixed>

Upstream merge semantics (aiogram/fsm/context.py):

kwargs.update(data or })   # data wins over kwargs on overlap
return await self.storage.update_data(key=self.key, data=kwargs)

PHP equivalent: array_merge($kwargs, $data ?? []) so $data entries overwrite same-keyed $kwargs entries.

Delegates to BaseStorage::updateData($this->key, $merged).

Parameters
$data : array<string, mixed>|null = null

Optional explicit data to merge.

$kwargs : mixed

Additional named key/value pairs to include.

Return values
array<string, mixed>

The merged data map as persisted.

Mirrors FSMContext.update_data (aiogram/fsm/context.py).

On this page

Search results