dev-master
9999999-dev http://esampaio.github.io/state-machineState Machine library for PHP projects
MIT
The Requires
- php >=5.3.2
- doctrine/common >=2.3.0
by Eduardo Sampaio
annotations statemachine state machine state-machine
Wallogit.com
2017 © Pedro Peláez
State Machine library for PHP projects
A dead simple State Machine PHP package., (*1)
To install, just add this to your composer.json:, (*2)
"require": {
"esampaio/state-machine":"master"
}
If you are running PHP 5.3 you need to inherit the StateMachine class:, (*3)
<?php
use Esampaio\StateMachine\StateMachine;
class MyClass extends StateMachine
{
If you are running PHP version 5.4, just use the Trait:, (*4)
use Esampaio\StateMachine\Traits\StateMachine;
class MyClass
{
use StateMachine;
To add your possible states and transitions, use the following annotations:, (*5)
use Esampaio\StateMachine\Traits\StateMachine;
use Esampaio\StateMachine\States;
use Esampaio\StateMachine\Transition;
/**
* @States(states = {"requested", "approved", "rejected"})
* @Transition(state = "requested", transitions = {"approved", "rejected"})
*/
class MyClass
{
use StateMachine;
The following methods will be created for each state:, (*6)
$foo->isRequested(); // Check if foo's current state equals "requested" $foo->canApproved(); // Check if foo's current state allows transition to "approved" $foo->transitionRejected(); // Transitions current foo's state to "rejected"
Two methods are triggered when a transition happens, you may implement them if you want:, (*7)
$foo->beforeRejected(); // Triggered before foo's state is changed into "rejected" $foo->afterRejected(); // Triggered after foo's state is changed into "rejected"
Check the source code and/or tests to understand it better., (*8)
git checkout -b my-new-feature)git commit -am 'Added some feature')git push origin my-new-feature)State Machine library for PHP projects
MIT
annotations statemachine state machine state-machine