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

State Machine Bundle Laravel Package

winzou/state-machine-bundle

Lightweight PHP/Symfony bundle for defining state machines on your domain objects. Configure graphs with states, transitions, and optional guard/before/after callbacks via YAML/XML/PHP, then apply and test transitions without hard-coded state logic.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • State Management: The package excels in modeling finite state machines (FSMs) for domain entities (e.g., Article, Order, User), aligning with Domain-Driven Design (DDD) principles. It enforces business rules (e.g., "an Article can only be published if accepted") via explicit transitions, reducing ad-hoc state checks in business logic.
  • Decoupling: Separates state logic from domain entities, improving testability and maintainability. State transitions are declaratively defined in YAML, not hardcoded in PHP.
  • Symfony Integration: Leverages Symfony’s dependency injection (DI) for callbacks (e.g., services, arguments), enabling reusable business logic (e.g., sending emails, validating transitions).
  • Extensibility: Supports multiple graphs per entity (e.g., an Order could have payment and shipping state machines), though this adds complexity.

Integration Feasibility

  • Laravel Compatibility:
    • The bundle is Symfony-centric (uses AppKernel, Symfony DI, and YAML config). Laravel’s service container and configuration system (.env, config/) differ significantly, requiring adapters or workarounds.
    • Key Challenges:
      • Symfony’s Bundle system is not native to Laravel. Would need to be rewritten as a Laravel package (e.g., using Illuminate\Support\ServiceProvider).
      • YAML config is not idiomatic in Laravel (PHP arrays or .env are preferred). Would require migration to Laravel’s config format.
      • Symfony’s event system (for callbacks) would need replacement with Laravel’s events/listeners or service bindings.
  • Alternative Approaches:
    • Use the underlying state-machine PHP library (this bundle wraps it) directly in Laravel, avoiding Symfony dependencies.
    • Build a Laravel-specific wrapper around the bundle’s core logic (e.g., abstracting config loading, DI).

Technical Risk

  • High Integration Risk:
    • Symfony Lock-in: The bundle assumes Symfony’s ecosystem (e.g., AppKernel, ServiceContainer). Porting to Laravel would require significant refactoring.
    • Configuration Overhead: YAML-based state definitions may clutter Laravel’s config system. A PHP-based DSL (e.g., fluent builder) might be cleaner.
    • Callback System: Symfony’s service-based callbacks (@service.method) would need replacement with Laravel’s service resolution (app()->make() or resolve()).
  • Performance Risk:
    • Minimal runtime overhead (lightweight design), but validation-heavy workflows (e.g., complex guards) could introduce latency if callbacks are I/O-bound (e.g., database checks).
  • Maintenance Risk:
    • Bundle Abandonment: Last release was 2026-03-24, but no active maintenance signs (e.g., issues, PRs). Risk of breaking changes in future Symfony versions.
    • Laravel Ecosystem Drift: Laravel’s DI and config systems evolve faster than Symfony’s. Long-term compatibility is uncertain.

Key Questions

  1. Is Symfony Dependency Acceptable?
    • Can the team tolerate Symfony dependencies in a Laravel project, or is a pure Laravel solution required?
  2. Configuration Preference
    • Is YAML config acceptable, or should state definitions be PHP classes/arrays (more Laravel-native)?
  3. Callback Complexity
    • Are callbacks simple (e.g., method calls) or complex (e.g., async tasks, external APIs)? This affects how much of the bundle’s callback system can be reused.
  4. State Machine Scope
    • Will the FSM be used for critical workflows (e.g., payments) where auditability is key, or for non-critical features?
  5. Alternatives Evaluation
    • Have other Laravel FSM packages (e.g., spatie/laravel-state-machines, verot/flow) been considered? Why was this bundle chosen?
  6. Long-Term Viability
    • Is the team willing to maintain a fork or build a Laravel adapter if the bundle stagnates?

Integration Approach

Stack Fit

  • Core Fit: The state machine logic (transitions, guards, callbacks) is highly reusable in Laravel, assuming Symfony-specific components are abstracted.
  • Mismatched Components:
    Symfony Feature Laravel Equivalent Integration Strategy
    AppKernel ServiceProvider Replace with Laravel’s register()/boot() methods.
    YAML Config PHP arrays/.env Convert YAML to Laravel’s config/state_machines.php.
    Symfony DI (@service) Laravel DI (app()->make()) Replace service IDs with Laravel’s container calls.
    Event Dispatcher Laravel Events Use Laravel’s Event::dispatch() or listeners.
    Bundle System Composer Packages Package as a Laravel-specific Composer package.

Migration Path

  1. Phase 1: Dependency Extraction

    • Fork the bundle and remove Symfony-specific code (e.g., AppKernel, ContainerAware traits).
    • Replace Symfony’s config loader with Laravel’s config() helper.
    • Replace Symfony services with Laravel’s container resolution (e.g., app()->make()).
  2. Phase 2: Configuration Adaptation

    • Convert YAML state definitions to PHP arrays in config/state_machines.php:
      'my_bundle_article' => [
          'class' => MyBundle\Entity\Article::class,
          'property_path' => 'state',
          'graph' => 'simple',
          'states' => ['new', 'pending_review', ...],
          'transitions' => [
              'create' => ['from' => ['new'], 'to' => 'pending_review'],
              // ...
          ],
          'callbacks' => [
              'guard' => [
                  'guard_on_submitting' => [
                      'on' => 'submit_changes',
                      'do' => ['MyAwesomeService', 'isSubmittable'],
                      'args' => ['object'],
                  ],
              ],
          ],
      ],
      
    • Replace Symfony’s service callbacks (e.g., @service.method) with Laravel’s closure-based callbacks or service bindings.
  3. Phase 3: DI and Service Integration

    • Register the state machine factory as a Laravel service provider:
      public function register() {
          $this->app->singleton('state_machine.factory', function () {
              return new StateMachineFactory($this->app['config']['state_machines']);
          });
      }
      
    • Bind callback services to Laravel’s container:
      $this->app->bind(MyAwesomeService::class, function () {
          return new MyAwesomeService();
      });
      
  4. Phase 4: Testing and Validation

    • Test state transitions, guard callbacks, and edge cases (e.g., invalid transitions).
    • Verify performance under load (e.g., high-throughput workflows).

Compatibility

  • Laravel Versions: The bundle supports Symfony 7/8, which aligns with Laravel’s PHP 8.1+ requirements. No major conflicts expected.
  • PHP Extensions: No special extensions required (uses core PHP features).
  • Database/ORM: Works with Doctrine ORM (Symfony default) or Eloquent (Laravel default) if state is stored in a database column.

Sequencing

  1. Prototype: Implement a single state machine (e.g., for Article) to validate the approach.
  2. Refactor: Abstract Symfony dependencies into a Laravel-compatible layer.
  3. Expand: Add more state machines incrementally, reusing the adapted pattern.
  4. Optimize: Profile performance and adjust callback handling (e.g., caching guards).

Operational Impact

Maintenance

  • Pros:
    • Centralized State Logic: All transitions and guards are defined in one place (config), reducing scattered if-else checks.
    • Auditability: State changes are explicit and traceable, aiding debugging.
    • Low Boilerplate: No need to manually implement state validation in business logic.
  • Cons:
    • Configuration Complexity: YAML/PHP state definitions can become hard to maintain for large graphs.
    • Dependency on Bundle: If the bundle is abandoned, forking/maintaining becomes necessary.
    • Callback Debugging: Symfony/Laravel service callbacks may require deep inspection of the container to debug.

Support

  • Developer Onboarding:
    • Steep Learning Curve: Developers must understand **
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui