Download the PHP package gomachan46/state-machine without Composer
On this page you can find all versions of the php package gomachan46/state-machine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download gomachan46/state-machine
More information about gomachan46/state-machine
Files in gomachan46/state-machine
Package state-machine
Short Description simple state machine with annotations for PHP, inspired by AASM known as a Ruby state machine.
License MIT
Informations about the package state-machine
StateMachine
StateMachine is a simple state machine with annotations for PHP, inspired by AASM known as a Ruby state machine.
Description
StateMachine is ... ?
- using some features of Doctrine. doctrine/annotations and doctrine/inflector only.
- Doctrine is known as ORM, but StateMachine is not related to the database.
- StateMachine is anything available if the PHP class.
- composed of Doctrine's custom annotations and traits.
- very easily available. Describe the annotations and
use StateMachineTrait
to what you want to manage the state, only this. - provides
@StateMachine
,@State
,Event
, and@Transition
annotations.
Demo
As an example, you want to manage the states of Job class.
This case, you can use StateMachine, only this.
So simple! So easy!
VS.
StateMachine vs. Other state machine for PHP ...
- using annotations.
- using trait.
- no configuration files.
- no state object.
- no state machine class, only trait.
- no state machine factory.
- when state changed, is immediately reflected.
Requirement
StateMachine works with PHP 5.4.0 or later.
Installation (via composer)
Usage
Adding a state machine is as simple as:
and start defining states and events together with their transitions.
Basic Setting
Annotations description
@SM\StateMachine
property
target property name to manage the states (e.g. property="status")
this name is used to likesetStatus()
states
events
@SM\State
- name state name (e.g. name="sleeping")
@SM\Event
- name
event name (e.g. name="run")
this name is used to likerun() canRun()
- transitions
- name
event name (e.g. name="run")
@SM\Transition
- from
transition from ... (e.g. from="sleeping")
you can set array or string. - to transition to ... (e.g. to="running")
- from
transition from ... (e.g. from="sleeping")
Provides
Methods
StateMachine provides some methods.
Whiny transition
If you do not like exceptions and prefer a simple true
or false
as response, you can use whinyTransitions
option.
Direct assignment
StateMachine support direct assign.
No direct assignment option
If you do not want to forgive direct assign, you can use noDirectAssignment
option.
Only this!
Callbacks
You can set callback method when ...
- before event
- before exit old state
- exit old state
- after transition
- before enter new state
- enter new state
- update state
- after exit old state
- after enter new state
-
after event
In this case,
You can run methods with args, too.
For example,
In future
In future, I am going to implement like AASM provides services:
- Guards
- Inspection
- and more ...
Questions
- create an issue on GitHub
- send us a tweet @gomachan46
- send mail [email protected]
Feel free!
Contribution
- Please fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :)
I'm looking forward to your contributions!
Licence
Author
Acknowledgement
Thank you for the great product.