ajthenewguy/php7-machines

Implementation of a finite state machine in PHP7

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

This package is auto-updated.

Last update: 2024-03-29 04:05:52 UTC


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