Skip to content
docsv0.1.0

ProcessInstance

A process instance handle: an opaque `instanceId` bound to the {@see ProcessDefinition} that governs it. Holds NO event data of its own — every state-reading method takes the {@see EventStoreInterface} explicitly and replays through the {@see Reducer}, so two `ProcessInstance` objects built from the same `instanceId` + `definition` against the same log always agree, and neither one ever caches a stale answer ("state is a projection", not a stored field). The constructor is the "attach to an existing instance" path — cheap, side-effect-free, usable any time a caller already knows an `instanceId` (e.g. a tool call carrying one). {@see self::start()} is the ONLY path that creates a brand-new instance (it is the one that writes to the store); calling it twice with the same `instanceId` would duplicate the bootstrap events, so callers resuming an existing instance must use `new self(...)` instead.

ProcessInstance::__construct()

public function __construct(string $instanceId, Milpa\Orchestrator\ProcessDefinition $definition):

Parameters

Parameters of __construct()
NameTypeDescription
$instanceIdstring
$definitionMilpa\Orchestrator\ProcessDefinition

ProcessInstance::start()

public static function start(Milpa\EventStore\EventStoreInterface $store, Milpa\Orchestrator\ProcessDefinition $definition, array $inputs, ?string $instanceId = null): self

Starts a brand-new process instance: appends `ProcessStarted` (payload = `$inputs`), then `StateEntered` (payload = `{state: $definition->initialState()}`), to `$store`, and returns the resulting handle. `$instanceId` defaults to a freshly generated UUID (via {@see UuidGenerator}) when omitted — pass one explicitly for deterministic tests or caller-assigned ids.

Parameters

Parameters of start()
NameTypeDescription
$storeMilpa\EventStore\EventStoreInterface
$definitionMilpa\Orchestrator\ProcessDefinition
$inputsarray<string, mixed>the new instance's starting context (e.g. domain ids)
$instanceId?string

ProcessInstance::state()

public function state(Milpa\EventStore\EventStoreInterface $store): Milpa\Orchestrator\ProcessState

The full projection — current state and accumulated context — replayed fresh from `$store` on every call.

Parameters

Parameters of state()
NameTypeDescription
$storeMilpa\EventStore\EventStoreInterface

ProcessInstance::currentState()

public function currentState(Milpa\EventStore\EventStoreInterface $store): string

Convenience accessor for {@see self::state()}'s `currentState`.

Parameters

Parameters of currentState()
NameTypeDescription
$storeMilpa\EventStore\EventStoreInterface

ProcessInstance::context()

public function context(Milpa\EventStore\EventStoreInterface $store): array

Convenience accessor for {@see self::state()}'s `context`.

Parameters

Parameters of context()
NameTypeDescription
$storeMilpa\EventStore\EventStoreInterface