ajthenewguy / php7-machines
Implementation of a finite state machine in PHP7
v0.0.2
2020-06-06 02:14 UTC
Requires
- php: ^7.2.5
- php-ds/php-ds: dev-master
Requires (Dev)
- phpbench/phpbench: @dev
- phpstan/phpstan: ^0.12.0@dev
- phpunit/phpunit: ^8.5
README
Implementation of a finite state machine in PHP7.
Usage
A turnstile abstraction:
use Machines\State;
use Machines\StateMachine;
use Machines\Transition;
$Locked = new State('Locked');
$Unlocked = new State('Unlocked');
$Locked->setTransitions([
new Transition(new MatchAcceptor('coin'), $Unlocked)
]);
$Unlocked->setTransitions([
new Transition(new MatchAcceptor('push'), $Locked)
]);
$machine = new StateMachine([$Locked, $Unlocked]);
$machine->input('coin');
$machine->input('push');