mini\Hooks\StateMachine::__construct() Method

public constructor

Signature

public function __construct(array $transitions, ?string $description = NULL)

Parameters

Name Type Default Description
$transitions array required Documentation missing
$description ?string NULL Documentation missing

Documentation

Configure the states and valid transitions

Transitions are defined as an array of arrays, where each sub-array represents a state and its valid target states. The first element is the source state, subsequent elements are states it can transition to. If there are no subsequent elements, the state is terminal (no valid transitions).

Examples:

// Simple two-state lifecycle
$machine = new StateMachine([
    [Phase::Bootstrap, Phase::Request],  // Bootstrap → Request
    [Phase::Request],                    // Request is terminal
]);

// More complex state machine
$machine = new StateMachine([
    ['idle', 'running', 'stopped'],    // idle → running OR stopped
    ['running', 'idle', 'stopped'],    // running → idle OR stopped
    ['stopped', 'idle'],               // stopped → idle (can restart)
]);

Note: Enums cannot be used as array keys in PHP, hence the nested array format.

Source

src/Hooks/StateMachine.php:129-143