Original file: src/Fsm/Events/TransitionAttempted.php
The TransitionAttempted class is part of the Fsm\Events namespace in the Laravel Finite State Machine (FSM) implementation. This class represents an event that occurs during a transition of an FSM in the application. It encapsulates the details of a model's state transition, including the originating and destination states, along with relevant contextual information.
This event can be useful for logging, auditing state transitions, or triggering additional processes when state changes occur.
The constructor initializes an instance of the TransitionAttempted event, capturing key information about the state transition of a specified model.
| Parameter | Type | Description |
|---|---|---|
$model |
Model |
The model instance that is undergoing a state transition. |
$columnName |
string |
The name of the column in the database that stores the FSM state. |
$fromState |
`FsmStateEnum | string |
$toState |
`FsmStateEnum | string` |
$context |
`ArgonautDTOContract | null` |
public function __construct(
public readonly Model $model,
public readonly string $columnName,
public readonly FsmStateEnum|string|null $fromState,
public readonly FsmStateEnum|string $toState,
public readonly ?ArgonautDTOContract $context
) {}
The constructor takes in five parameters, assigning them to public readonly properties that provide access to the event's data after instantiation.
Model parameter serves to bind the event to a specific entity within the application, allowing developers to reference the exact instance being manipulated.string parameter $columnName specifies which database column is used to hold the FSM state information, facilitating scalability by enabling developers to adapt this to various model configurations.$fromState and $toState offer transparency into the transition's origin and destination, vital for debugging and system auditing.$context allows the inclusion of additional information about the transition event, which can be beneficial in complex systems where multiple pieces of data affect a state change.This class does not return a value from its constructor; it simply initializes an instance of TransitionAttempted that can be used elsewhere in the application for event handling or logging of state changes.
The TransitionAttempted class acts as a structured event object that encapsulates essential information regarding a model's FSM state transition. By leveraging this class, developers can ensure that their applications maintain a clear understanding of state changes, making it easier to implement complex FSM logic and respond to transitions as needed.
How can I help you explore Laravel packages today?