sbooker / workflow
Simple workflow for FSM implementation
Installs: 5 885
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- php-ds/php-ds: ^1.2
Requires (Dev)
- ext-dom: *
- ext-xml: *
- ext-xmlwriter: *
- phpunit/phpunit: ^10.2
This package is auto-updated.
Last update: 2024-11-14 11:00:55 UTC
README
Installation
pecl install ds composer require sbooker/workflow
Usage
// Step 1. Create Status Enum use Sbooker\Workflow\Status; enum ConcreteStatus: string implements Status { use \Sbooker\Workflow\EnumTrait; case first = "first"; case second = "second"; } // Step 2. Define workflow use Sbooker\Workflow\Workflow; use Ds\Map; use Ds\Set; final class ConcreteWorkflow extends Workflow { public function __construct() { parent::__construct(ConcreteStatus::first); } protected function buildTransitionMap(): Map { $map = new Map(); $map->put(ConcreteStatus::first, new Set([ConcreteStatus::second])); return $map; } protected function getStatusClass(): string { return ConcreteStatus::class; } } // Step 3. Use workflow in your entity for state control class ConcreteEntity { // ... private ConcreteWorkflow $workflow; // ... public function __construct() { // ... $this->workflow = new ConcreteWorkflow(); // ... } public function doSecond(): void { // ... $this->workflow->transitTo(ConcreteStatus::second()); // ... } }
License
See LICENSE file.