Download the PHP package ironbound/state without Composer
On this page you can find all versions of the php package ironbound/state. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package state
IronBound State
IronBound State is a State Machine library heavily influenced by yohang/finite
.
Usage
Core Components
Subject
The subject is the object that maintains state and has transitions applied to it. The only requirement is that it is a PHP object; there is no interface
defined for subjects.
State
The State
object represents the current state the subject is in. For instance, a post could be in the "Pending" state or "Published" state. A delivery state could be "Processing", "Waiting at Carrier", "In Transit", and "Delivered".
Transition
The Transition
object defines how a subject moves from one state to another. For instance, when you "Publish" a post it moves from the "Pending" state to the "Published" state. When you "Deliver to Carrier" a package, it transitions from "Processing" to "Waiting at Carrier".
Graph
The Graph
object is responsible for holding the set of available states a subject can be in and the list of transitions between those states.
A subject can have more than one Graph. For instance, an ecommerce order might have a payment status and a delivery status. Each status is a separate graph.
State Machine
The StateMachine
is how you interact with a subject's state and transition between states. It can tell you what transitions are available from the current state and apply a transition to change the subject's state.
State Mediator
There are many different ways that a subject can store and change it's state. For instance, it could be an instance property, behind a method, or perhaps tracked somewhere completely separate from the subject's data. The StateMediator
is used to abstract these details away from the StateMachine
.
Factories
The most direct way to use IronBound State is to instantiate a ConcreteStateMachine
directly.
However, you may prefer an alternate construction style where you use a Factory that is preconfigured.
The recommended way to do this is to use the StateMachineFactoryConfigurator
class to do the heavy lifting based on a configuration array.
Events
IronBound-State integrates with the PSR-14 Event Dispatcher spec to customize behavior and listen for actions.
You can provide the ConcreteStateMachine
with an EventDispatcherInterface
instance by calling ConcreteStateMachine::setEventDispatcher
. The following events are currently supported.
TestTransitionEvent
Called during the evaluation process after determining that the transition is available, and it's guard returned a valid evaluation. Call TestTransitionEvent::reject($reason)
to dynamically prevent a transition from being applied.
BeforeTransitionEvent
Called before updating a subject's state in response to a transition being applied.
AfterTransitionEvent
Called after updating a subject's state in response to a transition being applied.