Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Fsm Laravel Package

christhompsontldr/laravel-fsm

View on GitHub
Deep Wiki
Context7

Documentation: StateTimelineEntryData.php

Original file: src/Fsm/Data/StateTimelineEntryData.php

StateTimelineEntryData Documentation

Table of Contents

  1. Introduction
  2. Class Overview
  3. Constructor
  4. Properties
  5. Usage Examples

Introduction

StateTimelineEntryData.php defines the StateTimelineEntryData class, which represents a Data Transfer Object (DTO) for individual state transitions within a finite state machine (FSM) context. The class encapsulates details pertinent to a state transition event—such as transition timestamps, state details, and additional context—that can be useful for logging, debugging, or analysis purposes.

This class is designed to be versatile, acting as both a structure for direct instantiation with named parameters or associative arrays, making it easier to construct instances with varying requirements.

Class Overview

Namespace

namespace Fsm\Data;

The StateTimelineEntryData class is part of the Fsm\Data namespace, organizing it within the broader finite state machine module.

Extends

class StateTimelineEntryData extends Dto

This class extends the base Dto class, inheriting its properties and functionalities, while providing additional specific properties and behaviors suited for handling state transition data.

Constructor

public function __construct(
    string|array $id,
    ?string $model_id = null,
    ?string $model_type = null,
    ?string $fsm_column = null,
    ?string $from_state = null,
    ?string $to_state = null,
    ?string $transition_event = null,
    ?array $context_snapshot = null,
    ?string $exception_details = null,
    ?int $duration_ms = null,
    ?CarbonImmutable $happened_at = null,
    ?string $subject_id = null,
    ?string $subject_type = null,
)

Purpose

The constructor initializes a new instance of StateTimelineEntryData, accepting a variety of parameters for the different aspects of the state transition event. It allows for flexibility in constructing instances either via individual arguments or an associative array.

Parameters

Parameter Type Description
$id `string array`
$model_id ?string The ID of the model associated with the transition. Default is null.
$model_type ?string The type of the model associated with the transition. Default is null.
$fsm_column ?string The FSM column used for the state transition. Default is null.
$from_state ?string The state prior to the transition. Default is null.
$to_state ?string The state after the transition. Default is null.
$transition_event ?string The event triggering the transition. Default is null.
$context_snapshot ?array<string, mixed> Optional context data at the time of the transition. Default is null.
$exception_details ?string Details about any exceptions that occurred during the transition. Default is null.
$duration_ms ?int The duration of the transition in milliseconds. Default is null.
$happened_at ?CarbonImmutable The timestamp when the transition occurred. Default is null.
$subject_id ?string The ID of the subject associated with the transition. Default is null.
$subject_type ?string The type of the subject associated with the transition. Default is null.

Functionality

The constructor contains logic that distinguishes between array-based construction and named parameter initialization. If an array is passed as the first argument:

  • The method checks if it is associative and prepares attributes using a private method prepareAttributes().
  • It validates the presence of required keys (only id is mandatory) and prepares the properties for the object.
  • If an SDK-compliant associative array is not passed, an exception will be thrown to ensure clarity about expected input.

For named parameter initialization, it directly prepares and assigns attributes using prepareAttributes().

Properties

The class defines several public properties that store the details of the state transition. All properties are initialized to null by default except for $id, which is mandatory (type string).

Property Table

Property Type Description
public string $id string Unique identifier for the transition entry.
public ?string $modelId string ID of the associated model, or null.
public ?string $modelType string Type of the associated model, or null.
public ?string $fsmColumn string FSM column involved in the transition, or null.
public ?string $fromState string Previous state before the transition, or null.
public ?string $toState string Next state after the transition, or null.
public ?string $transitionEvent string Event triggering the transition, or null.
public ?array $contextSnapshot array Contextual data at transition time, or null.
public ?string $exceptionDetails string Any exception details during the process, or null.
public ?int $durationMs int Duration of the transition in milliseconds, or null.
public ?CarbonImmutable $happenedAt CarbonImmutable Timestamp of when the transition occurred, or null.
public ?string $subjectId string ID of the subject for this transition, or null.
public ?string $subjectType string Type of subject associated with the transition, or null.

Usage Examples

To create a new instance of StateTimelineEntryData, you can do so either through named parameters or by passing an associative array:

Named Parameter Initialization

$entry = new StateTimelineEntryData(
    id: 'transition_1',
    model_id: 'model_1',
    from_state: 'initial',
    to_state: 'completed',
    transition_event: 'start_process',
    duration_ms: 200,
    happened_at: Carbon\CarbonImmutable::now()
);

Associative Array Initialization

$entry = new StateTimelineEntryData([
    'id' => 'transition_1',
    'model_id' => 'model_1',
    'from_state' => 'initial
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport