Original file: src/Fsm/FsmBuilder.php
The FsmBuilder class is a pivotal component of the finite state machine (FSM) implementation in the Laravel application. It serves the purpose of collecting and building FSM definitions for various models and their state columns. This class allows developers to define states and transitions in an organized manner, facilitating the management of the various possible states an entity can occupy throughout its lifecycle.
forCreates a new instance of the TransitionBuilder for a specified model and state column.
class-string $modelClass: The fully qualified class name of the model for which the FSM is being defined.string $columnName: The name of the state column on the model.TransitionBuilder: An instance of TransitionBuilder representing the FSM for the specified model and column.This method checks if a TransitionBuilder already exists for the given model class and column name. If it does, it returns the existing instance; if not, it creates a new TransitionBuilder and stores it in the $builders array.
registerFsmRegisters the details of a single transition for a given FSM.
class-string $modelClass: The fully qualified class name of the model associated with the FSM.string $columnName: The name of the state column on the model.array<string, mixed> $transitionDetails: An associative array holding the definition of a single transition (e.g., 'from', 'to', 'guards', 'callbacks').void: This method does not return any value.It stores the transition details in the $definitions array under the specific model class and column name, allowing for organized access to FSM definitions.
getFsmRetrieves all registered transition definitions for a specific FSM.
class-string $modelClass: The fully qualified class name of the model whose FSM is being queried.string $columnName: The state column of the model.array<int, array<string, mixed>>|null: This returns an array of transition definitions or null if no FSM is defined for the specified parameters.This method provides access to the registered FSM definitions for a given model class and state column, enabling the retrieval of transition data when needed.
getDefinitionRetrieves the TransitionBuilder for a specific FSM if it is defined.
class-string $modelClass: The fully qualified class name of the model for which the FSM is defined.string $columnName: The name of the state column on the model.TransitionBuilder|null: An instance of TransitionBuilder, or null if it is not defined.This method checks if a TransitionBuilder exists for the given model and column name and returns it for further modification or inspection.
getDefinitionsGet all stored TransitionBuilder instances.
array<class-string, array<string, TransitionBuilder>>: An array containing all the TransitionBuilder instances classified by model class name and state column.This method returns a comprehensive list of all defined FSMs, allowing for inspection or iteration over all FSM configurations available within the system.
resetClears all registered FSM definitions.
void: This method does not return any value.This method resets the state of the FsmBuilder class by clearing the $definitions and $builders arrays. It is particularly useful in testing scenarios where a fresh state is required.
extendExtend an existing FSM definition with additional states and transitions.
class-string $modelClass: The fully qualified class name of the model.string $columnName: The name of the state column on the model.callable $extension: A callback function that is intended to receive the existing TransitionBuilder instance for modification.void: This method does not return any value.The extend method allows developers to add new transitions and states to an existing FSM. The supplied callback receives the TransitionBuilder, which can be used to define further behavior within the FSM.
overrideStateOverride a specific state definition for an FSM.
class-string $modelClass: The fully qualified class name of the model.string $columnName: The name of the state column.string|Fsm\Contracts\FsmStateEnum $stateName: The name or enum value of the state to override.array<string, mixed> $stateConfig: Configuration for the state which includes methods to be called on the TransitionBuilder.void: This method does not return any value.Uses the TransitionBuilder for the given model and column to override an existing state with new configuration. It ensures that the state's methods are validated before being called, allowing for robust configuration management.
overrideTransitionOverride or add a transition definition for an FSM.
class-string $modelClass: The fully qualified class name of the model.string $columnName: The name of the state column on the model.string|Fsm\Contracts\FsmStateEnum|null $fromState: The state from which to transition, or null.string|Fsm\Contracts\FsmStateEnum $toState: The state to transition to.string $event: The event that triggers the transition.array<string, mixed> $transitionConfig: Configuration for the transition with methods to be called.void: This method does not return any value.It handles transitions by first removing any existing transitions that match the parameters, then it creates a new transition and applies the configuration settings to it. This process ensures that the FSM is flexible and up-to-date with the desired transition states.
applyExtensionsApply runtime extensions to an FSM definition.
class-string $modelClass: The fully qualified class name of the model.string $columnName: The name of the state column on the model.Fsm\FsmExtensionRegistry $extensionRegistry: The registry containing FSM extensions.void: This method does not return any value.This method retrieves and
How can I help you explore Laravel packages today?