Download the PHP package cosma/simple-state-machine without Composer
On this page you can find all versions of the php package cosma/simple-state-machine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cosma/simple-state-machine
More information about cosma/simple-state-machine
Files in cosma/simple-state-machine
Informations about the package simple-state-machine
SimpleStateMachine - A very simple State Machine
- A Simple State Machine without timeouts.
- States can modify a Data object which will be injected in the initial State.
- The State Machine graph can be visualised in a UML diagram generated in different formats.
Table of Contents
- Installation
- Usage
- Reference
- Defining Data Object
- Defining States
- Define Conditions
- Graph Diagram
- Export Formats
- DOT Language
- Tests
- License
Installation
Simple State Machine is installable via Composer as cosma/simple-state-machine.
Usage
Let's follow the example of a simple price calculator state machine.
Reference
Defining Data Object
The Data object can be modify by the State Machines transitions and State.
The Data class must implement the interface \Cosma\SimpleStateMachine\InterfaceData.
InterfaceData is a empty interface but is used to force Type hinting.
Defining States
All states must extend the class \Cosma\SimpleStateMachine\AbstractState
Defining Conditions
A Transition between states is possible directly when there is no condition or, if there is a condition, only when that condition is true.
All Conditions must extend \Cosma\SimpleStateMachine\AbstractCondition class
Graph Diagram
You can easily visualise the State Machine Diagram
Export Formats
The output is delivered in various formats.
The most used export formats are:
All supported formats are the DOT output formats: bmp, canon, cgimage, cmap, cmapx, cmapx_np, dot, eps, exr, fig, gif, gv, icns, ico, imap, imap_np, ismap, jp2, jpe, jpeg, jpg, pct, pdf, pic, pict, plain, plain-ext, png, pov, ps, ps2, psd, sgi, svg, svgz, tga, tif, tiff, tk, vml, vmlz, x11, xdot, xdot1.2, xdot1.4, xlib
DOT Language
Stands for graph description language and you can read more here
To take fully advantage of style attributes you need to know DOT language.
When defining a Condition or a State, you can easily modify the protected $styleAttributes property and overwrite the default style for a State or a Condition.
By this you can manipulate the color, font and shape of States and Conditions
DOT Useful Links:
-
Drawing graphs with DOT - download a pdf
- Node Shapes - shapes of a node
Tests
License
Released under the MIT License, see LICENSE.