Original file: src/Fsm/TransitionBuilder.php
The TransitionBuilder class is a core component of the finite state machine (FSM) framework implemented in this PHP codebase. It is designed to build the states and transitions for a specific FSM associated with a model and a specified column. This class collects all definitions of states and transitions, which can then be compiled into an FsmRuntimeDefinition object, typically via the FsmRegistry. The class enables developers to easily define states, transitions, actions, and guards in a fluent and readable manner.
The class properties include:
states, transitions, and transition-building state variables like fluentFrom, fluentTo, etc.public function __construct(string $modelClass, string $columnName)
modelClass (string): The fully qualified class name of the Eloquent model.columnName (string): The name of the column that will store the state.private static function normalizeStateValue(FsmStateEnum|string $state): string
state (FsmStateEnum|string): The state to normalize.public function initial(FsmStateEnum|string $state): self
state (FsmStateEnum|string): The state to set as the initial state.public function state(FsmStateEnum|string $state, ?callable $configurator = null): self
state (FsmStateEnum|string): The name of the state to define.configurator (callable|null): A callback function to configure the state further.public function onEntry(string|Closure|array $callable, array $parameters = [], bool $runAfterTransition = false, bool $queued = false): self
callable (string|Closure|array): A callable action to execute on entry.parameters (array): Arguments to pass to the callable.runAfterTransition (bool): Whether to run the action after the transition.queued (bool): If true, queues the action for later execution.public function onExit(string|Closure|array $callable, array $parameters = [], bool $runAfterTransition = false, bool $queued = false): self
onEntry.public function transition(FsmStateEnum|string|null $fromOrDescription = null, FsmStateEnum|string|null $to = null): self
fromOrDescription (FsmStateEnum|string|null): Indicates the source state or a description if it's the finalizing call.to (FsmStateEnum|string|null): The destination state (only when starting a new transition).public function description(string $description): self
description (string): The description text.public function type(string $type): self
type (string): The type of the state (e.g., 'initial', 'final').public function category(?string $category): self
category (string|null): The category name.How can I help you explore Laravel packages today?