Original file: src/Fsm/Models/FsmLog.php
The FsmLog class is an Eloquent model responsible for logging state transitions in a Finite State Machine (FSM) context. It is part of the Fsm\Models namespace and facilitates the tracking of events related to FSM changes, ensuring that important data regarding state transitions is captured and stored in the fsm_logs database table. This class utilizes UUIDs for record identification and supports the ability to relate logs to specific subject and model instances.
The FsmLog class contains several important attributes that correspond to columns in the fsm_logs database table:
| Attribute | Type | Description |
|---|---|---|
id |
string |
Unique identifier for the log entry (UUID). |
subject_id |
`string | null` |
subject_type |
`string | null` |
model_id |
string |
ID of the model that this log entry is associated with. |
model_type |
string |
Type of the model that this log entry is associated with. |
fsm_column |
string |
Name of the FSM column involved in the transition. |
from_state |
string |
The state prior to the transition. |
to_state |
string |
The state after the transition. |
transition_event |
`string | null` |
context_snapshot |
`array<string, mixed> | null` |
exception_details |
`string | null` |
duration_ms |
`int | null` |
happened_at |
\Illuminate\Support\Carbon |
Timestamp when the transition occurred. |
private static function extractUserId($state): ?string
object|null $state: The state object from which to extract the user ID. If the state is not an object, it returns null.null if not.user_id is a public property of the state object.getUserId() method on the state object and invokes it.user_id property and accesses it if available.null.public function subject(): MorphTo
MorphTo, which is an Eloquent relationship type for handling polymorphic relations.subject_id and subject_type attributes, allowing the FsmLog to dynamically connect to different types of subjects.public function model(): MorphTo
MorphTo, enabling dynamic relationship resolution with various models.subject method, this allows the FsmLog to relate to different model types based on the model_id and model_type attributes.protected static function booted(): void
creating event. During the creation of a FsmLog instance:
happened_at is empty, it sets it to the current timestamp.subject_id and subject_type based on the current Verbs state if configured.The FsmLog class provides integral functionality for tracking FSM transitions in a Laravel application. Its design allows for extensible logging capabilities by utilizing polymorphic relations, ensuring that developers can maintain comprehensive logs related to state changes, exceptions, and associated context. This documentation aims to clarify the inner workings of the FsmLog class, aiding developers in leveraging its capabilities effectively.
How can I help you explore Laravel packages today?