ajthenewguy/php7-machines

PHP7中有限状态机的实现

v0.0.2 2020-06-06 02:14 UTC

This package is auto-updated.

Last update: 2024-09-29 05:48:50 UTC


README

PHP7中有限状态机的实现。

用法

转闸抽象

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');