! UNDER DEVELOPMENT !
A finite state machine for php
- PHP 7.1+
$state = new NormalState('state');
$state
->event('publish', 'published')
->trigger('beforePublish', function() { /* exec before $state->publish() run */ })
->trigger('onExit', function() { return /* will be executed when leaving this state */; });
$state->publish(); // return 'published'
// file SimpleState.php
class SimpleState implements StateInterface {
// public method it is event
public function publish()
{
return 'published';
}
// before<*> or after<*> it is triggers
// runs before and after event execute
public function beforePublish()
{
return true;
}
// This is trigger like an 'onExit', 'onReset'
public function onExit()
{
return true;
}
}
$state = new SimpleState();
$state->publish(); // return 'published'
- workflux - Finite state machine for php.
- UnderStated - A PHP Finite State Machine
- S-Flow - A lightweight library for defining state machines that supports conditional transitions