Skip to content
docsv0.17.0

StateMachineComponent

A CLOSED, declarative state machine over the live wire — the portable-interaction/v1 machine (greenhouse decisions/0087) made executable in the runtime: the states, the initial state, the transition table AND each transition's EFFECTS are DATA, and {@see handle()} is a pure application of that data — the reducer IS the table, with no per-transition code. An event no transition declares does not advance the state (a closed union, not an open handler); an action the contract does not declare never reaches here (the endpoint's authorizer refuses it first); and an EFFECT of a type outside the allow-list is refused, never applied. The owner rides every transition: `meta.principal` is preserved across each advance, so a machine advances only for the actor it was mounted for (greenhouse decisions/0093, effects: decisions/0094).

StateMachineComponent::__construct()

public function __construct(?Milpa\Interfaces\Event\MilpaEventDispatcherInterface $dispatcher = null, Milpa\Interfaces\Clock $clock = new SystemClock()):

Parameters

Parameters of __construct()
NameTypeDescription
$dispatcher?Milpa\Interfaces\Event\MilpaEventDispatcherInterface
$clockClocktime as an INPUT: a `stamp` effect reads it from here, never from `date()`, so the same inputs and the same clock replay to the same state (greenhouse decisions/0102).

StateMachineComponent::contract()

public static function contract(): Milpa\Live\ValueObjects\ComponentContract

The machine's contract: a single `state` field and the declared events; the authorizer allow-lists these.

StateMachineComponent::handle()

public function handle(Milpa\Live\ValueObjects\InteractionRequest $request): Milpa\Live\ValueObjects\InteractionResult

One event: advance along the declared transition and fire its allow-listed effects, or refuse — without advancing — when no transition is declared or an effect is outside the allow-list.

Parameters

Parameters of handle()
NameTypeDescription
$requestMilpa\Live\ValueObjects\InteractionRequest