Download the PHP package coff/state-machine-framework without Composer
On this page you can find all versions of the php package coff/state-machine-framework. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coff/state-machine-framework
More information about coff/state-machine-framework
Files in coff/state-machine-framework
Package state-machine-framework
Short Description State Machine Framework PHP component for designing state machines
License MIT
Informations about the package state-machine-framework
State Machine Framework for PHP
Maybe state machines are not what you usually do with PHP but when you do... just use this. This simple yet powerful framework will keep your state machines within their desired state transition cycles. You can also modify their behavior whilst running or just configure them dynamically and launch. You can define state transition conditions you want based upon anonymous functions or class methods. Fire events on each state transition with your favorite event dispatcher.
Installation
Easiest way is to use composer:
Alternatively just clone repository:
and then checkout specific tag:
Usage example
States' dictionary
For clarity each state machine should have its own state dictionary defined.
Machine class
Machine in-use
Transition object
Each transition object should have one or more assertion objects attached.
Remark: By default (when no assertion object is given as parameter) Machine::allowTransition()
method attaches DefaultCallbackAssertion
.
Assertion behaviors
AlwaysTrueAssertion
Results in automatic transition when machine is launched.
Be aware:
AlwaysFalseAssertion
Results in no transition when machine is launched. Use this kind of assertion when machine state is supposed to be
changed upon setMachineState()
method call only.
DefaultCallbackAssertion
Calls assertXToY
method on machine object (or other object if specified) and makes transition decision upon its return.
CommonCallbackAssertion
Calls assertTransition
method on machine object (or other object if specified) and makes transition decision upon its return.
CallbackAssertion
Calls user specified method to assert if state transition should proceed.