Download the PHP package ringierimu/state-workflow without Composer
On this page you can find all versions of the php package ringierimu/state-workflow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ringierimu/state-workflow
More information about ringierimu/state-workflow
Files in ringierimu/state-workflow
Package state-workflow
Short Description State Management workflow for Laravel
License MIT
Homepage https://github.com/RingierIMU/state-workflow
Informations about the package state-workflow
Laravel State workflow
Laravel State workflow provide tools for defining and managing workflows and activities with ease. It offers an object oriented way to define a process or a life cycle that your object goes through. Each step or stage in the process is called a state. You do also define transitions that describe the action to get from one state to another.
A workflow consist of state and actions to get from one state to another. These actions are called transitions which describes how to get from one state to another.
Installation
Publish config/workflow.php
file
Run migrations
Configuration
-
Open
config/workflow.php
and configure it - Add
HasWorkflowTrait
to your model class to support workflow
Usage
Manage State/Workflow
Authenticated User Resolver
Ability to audit and track who action a specific state change for your object. The package leverage the default Laravel auth provider to resolve the authenticated user when applying the state changes.
For a custom authentication mechanism, you should override authenticatedUserId
in your object class with your own implementation.
Fired Event
Each step has three events that are fired in order:
- An event for every workflow
- An event for the workflow concerned
- An event for the workflow concerned with the specific transition or state name
During state/workflow transition, the following events are fired in the following order:
-
Validate whether the transition is allowed at all. Their event listeners are invoked every time a call to
workflow()->can()
,workflow()->apply()
orworkflow()->getEnabledTransitions()
is executed.Guard Event
-
The subject is about to leave a state.
Leave Event
-
The subject is going through this transition.
Transition Event
-
The subject is about to enter a new state. This event is triggered just before the subject states are updated.
Enter Event
-
The subject has entered in the states and is updated.
Entered Event
- The subject has completed this transition.
Completed Event
Subscriber
Create subscriber class to listen to those events and the class should extends WorkflowSubscriberHandler
.
To register method to listen to specific even within subscriber use the following format for method name:
- on[Event] -
onGuard()
- on[Event][Transition/State name] -
onGuardActivate()
NB:
- Method name must start with
on
key word otherwise it will be ignored. Subscriber
class must be register insideworkflow.php
config file with the appropriate workflow configuration.Subscriber
class must extendsWorkflowSubscriberHandler
.Guard
,Transition
andCompleted
Event uses of transition name.Leave
,Enter
andEntered
Event uses state name.
Event Methods
Each workflow event has an instance of Event
. This means that each event has access to the following information:
getOriginalEvent()
: Returns the Parent Event that dispatched the event which has the following children methods:getSubject()
: Returns the object that dispatches the event.getTransition()
: Returns the Transition that dispatches the event.getWorkflowName()
: Returns a string with the name of the workflow that triggered the event.isBlocked()
: Returns true/false if transition is blocked.setBlocked()
: Sets the blocked value.
Artisan Command
Symfony workflow uses GraphvizDumper to create the workflow image by using the dot
command.
The dot
command is part of Graphviz.
You will be required to download dot
command to make use of this command.
https://graphviz.gitlab.io/download/
Usage
Run Unit Test
Credits
All versions of state-workflow with dependencies
illuminate/events Version ^7|^8|^9|^10.0
illuminate/support Version ^7|^8|^9|^10.0
symfony/event-dispatcher Version ^5.1
symfony/workflow Version ^5.1
symfony/property-access Version ^5.1