Download the PHP package yohang/finite without Composer
On this page you can find all versions of the php package yohang/finite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download yohang/finite
More information about yohang/finite
Files in yohang/finite
Package finite
Short Description A simple PHP Finite State Machine
License MIT
Homepage https://github.com/yohang/Finite
Informations about the package finite
Finite, A Simple PHP Finite State Machine
Finite is a Simple State Machine, written in PHP. It can manage any Stateful object by defining states and transitions between these states.
As of version 2, Finite is a low-deps and lightweight state machine library, thanks to the use of PHP Enums.
Disclaimer
I don't have the time anymore to maintain this lib. Here is the documentation for the brand new Finite V2, based on PHP >= 8.1 Enums, but don't expect it to be updated on a regular basis.
Features
- Manage State/Transition graph for an object
- Attach business logic to states
- Listen to transitions between state to trigger your domain code
- Symfony integration
- Twig Extension
Getting started
Installation (via composer)
Define your state enum
Define your Stateful Object
Your stateful object just need to have a state property
Initializing a simple StateMachine
Add business logic to states
Finite < 2.0 had properties on states. A metadata mechanism that allowed to add business properties on states to define the behavior of on object, depending on its state.
The idea behind this was to avoid to test the state in your domain code (A controller must not throw a 404 if the state is draft. But it can throw a 404 if the current state does not have a "visible" property. That was the idea).
Finite 2 does not needs this. PHP Enums can have methods. So, replace your properties with simple methods on your state.
After that, you can use theses methods on your object, even without instantiating the state machine.
All versions of finite with dependencies
symfony/options-resolver Version ^4.0|^5.0|^6.0|^7.0
symfony/event-dispatcher Version ^4.0|^5.0|^6.0|^7.0
symfony/property-access Version ^4.0|^5.0|^6.0|^7.0