State
is a state machine implementation in PHP.
Pull State
in from Composer:
Creating a state machine with State
is a cinch. Just pass a machine spec
, which
is a specially formatted string description, to the machine into the constructor,
like the following:
The machine spec
starts with one line enumerating all states, namely placed
,
payed
, shipped
and completed
. The first state (placed
) will be treated
as the initial state.
Following the states line, subsequent lines each describes one possible transition. E.g.:
The above line defines a transition named pay
that changes the state of the machine
from placed
to payed
.
You can provide an optional second argument to the constructor to indicate the current state of the machine.
A teleport()
method is at your disposal if you would like to set the machine
to a specific state after instantiation.
Note that the teleport()
method does nothing but setting the machine state. None
of the transition listeners will be called since no transition is performed.
What happened here is a teleport! :P