Wallogit.com
2017 © Pedro Peláez
中文介绍, (*2)
A state machine implemetation in PHP. This implementation is mostly inspired from "Domain Specifi Languages" of Martin Flower., (*3)
State Machine in essential is a collection of State, Event and Transistion., (*4)
+---------+ +---------+ | | | | | +---------------+ | +---------+ +---------+ State1 Event target
In this implementation the description of a state machine could be written in yml., (*5)
An example state machine could be like:, (*6)
Name: door Start: "dc" Event: - ["close door", "CD"] - ["open door", "OD"] - ["open window", "OW"] - ["close window", "CW"] State: - "dc" - "do" - "wo" - "wc" Transition: - ["dc", "OD", "do"] - ["do", "OW", "wo"] - ["wo", "CW", "wc"] - ["do", "CD", "dc"]
In '''Event''' block all events are listed in the format [name, code]. Code must be unique. This code is also used to drive the machine., (*7)
In '''State''' block all states are listed in the format "name"., (*8)
In '''Transition''' block all transitions are listed in the format [startState, event, targetState]., (*9)
The sample use of state machine and controller could be see in the test directory., (*10)
{
"require": {
"tiddr/state_machine": "dev-master"
}
}
Then just add, (*11)
require_once __DIR__.'/vendor/autoload.php';
Take a look at the files under directory tests, (*12)