Download the PHP package tsmsogn/cakephp-state-machine without Composer
On this page you can find all versions of the php package tsmsogn/cakephp-state-machine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tsmsogn/cakephp-state-machine
More information about tsmsogn/cakephp-state-machine
Files in tsmsogn/cakephp-state-machine
Package cakephp-state-machine
Short Description StateMachineBehavior for CakePHP
License MIT
Homepage https://github.com/davidsteinsland/cakephp-state-machine
Informations about the package cakephp-state-machine
CakePHP State Machine
Documentation is not finished yet either. See the tests if you want to learn something, as all aspects of the state machine is tested there.
What is a State Machine?
http://en.wikipedia.org/wiki/State_machine
Installation
First you need to alter the tables of the models you want to use StateMachine:
Features
- Callbacks on states and transitions
- Custom methods may be added to your model
is($state)
,can($transition)
,on($transition, 'before|after', callback)
andwhen($state, callback)
methods allows you to control the whole flow.transition($transition)
is used to move between two states.- Roles and rules
- Graphviz
Callbacks
You can add callbacks that will fire before/after a transition, and before/after a state change. This can either be done manually with $this->on('mytransition', 'before', funtion() {})
, or you can add a method to your model:
The state callbacks are a little different:
Naming conventions
-
Transitions and states in
$transitions
should be lowercased and underscored. The method names are in turn camelized.Example:
How to Use
With the model above, we have the following methods:
Graphviz
Here's how to state machine of the Vehicle would look like if you saved:
into fsm.gv
and ran:
History
- Support PHP 5.3
- Add param $id to
is($state)
,can($transition)
andtransition($transition)
methods. It specifies record to be read