This package helps you to create State Machine data model-based services.
You can install the package via composer:
composer require caner/state-machine
In config/app.php
;
\Caner\StateMachine\StateMachineServiceProvider::class,
and publish config file;
php artisan vendor:publish --tag=caner-state-machine-config
A state machine is a mathematical abstraction used to design algorithms. A state machine reads a set of inputs and changes to a different state based on those inputs.
A state is a description of the status of a system waiting to execute a transition. A transition is a set of actions to execute when a condition is fulfilled or an event received. In a state diagram, circles represent each possible state and arrows represent transitions between states.
Basically, we are building a state
for each status
and running related transition
when changing the status
.
Each Transition
should consist of 3 parts. These are the guards
, action
and afterActions
methods.
I prefer to use package in complex status changes.
Preferred Directory Tree;
- app
-
- Services
-
-
- YourStateMachine
-
-
-
-
- AfterActions
-
-
-
-
-
- Guards
-
-
-
-
-
- States
-
-
-
-
-
- Transitions
-
-
-
-
-
- YourStateMachine.php
-
-
-
-
- AnotherStateMachine
-
-
-
-
- AfterActions
-
-
-
-
-
- Guards
-
-
-
-
-
- States
-
-
-
-
-
- Transitions
-
-
-
-
-
- AnotherStateMachine.php
-
-
In future versions, we will be added, create state machine parts in artisan commands. This time commands run like this directory tree.
1-) Create First State Machine
2-) Create First State
3-) Create First Transition
4-) Create First Guard
5-) Create First AfterAction
6-) Example Transition in Created State Machine
7-) Create Another State Machine
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please create an issue on github issues section.
Special thanks for Tarfin Labs
- Caner Ergez
- Will be update soon.
The MIT License (MIT). Please see License File for more information.