sonsofphp / state-machine
Basic, yet powerful, state machine
Fund package maintenance!
JoshuaEstes
Tidelift
Requires
- php: >=8.2
- sonsofphp/event-dispatcher: 0.3.x-dev
- sonsofphp/state-machine-contract: 0.3.x-dev
Provides
- sonsofphp/state-machine-implementation: 0.3.x-dev
This package is auto-updated.
Last update: 2024-10-30 16:45:03 UTC
README
<?php use SonsOfPHP\Component\StateMachine\StateMachine; $sm = new StateMachine([ 'graph' => 'order', 'supports' => [ OrderInterface::class, ], 'transitions' => [ 'create' => [ 'from' => 'draft', 'to' => 'new', ], 'fulfill' => [ 'from' => 'new', 'to' => 'fulfilled', ], 'cancel' => [ 'from' => ['draft', 'new', 'fulfilled'], 'to' => 'fulfilled', ], ], ]); // Check if state can change $sm->can($order, 'create'); // Apply transition $sm->apply($order, 'fulfil'); // Get Current State $sm->getState($order);
Learn More
- Documentation
- Contributing
- Report Issues and Submit Pull Requests in the Mother Repository
- Get Help & Support using Discussions