caner / state-machine
Laravel Simple State Machine System
Requires
- php: ^8.0
- illuminate/support: ^8.0|^9.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-19 22:28:07 UTC
README
This package helps you to create State Machine data model-based services.
Installation
You can install the package via composer:
composer require caner/state-machine
Usage
In config/app.php
;
\Caner\StateMachine\StateMachineServiceProvider::class,
and publish config file;
php artisan vendor:publish --tag=caner-state-machine-config
Step by step documentation
Introducing Concept
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
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please create an issue on github issues section.
Credits
Special thanks for Tarfin Labs
- Caner Ergez
- Will be update soon.
License
The MIT License (MIT). Please see License File for more information.