Download the PHP package adiletmaks/laravel-workflow without Composer
On this page you can find all versions of the php package adiletmaks/laravel-workflow. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-workflow
Laravel workflow
This is a fork from brexis/laravel-workflow. My current needs for this package are a bit more bleeding-edge than seem to be maintainable by the other packages. Massive kudos to brexis for the original work and adaptation on this.
Use the Symfony Workflow component in Laravel
Installation
composer require adlietmaks/laravel-workflow
Laravel Support
Package Version | Laravel Version Support |
---|---|
^2.0 | 5.x |
^3.0 | 7.x |
^3.2 | 8.x |
Upgrade from v2 to v3
The biggest changes from v2 to v3 are the dependencies. To match the Symfony v5 components, the Laravel version is raised to v7. If you're on Laravel v6 or earlier, you should continue to use the v2 releases of this package.
To match the changes in the Symfony v5 workflow component, the "arguments" config option has been changed to "property". This describes the property on the model the workflow ties to (in most circumstances, you can simply change the key name from "arguments" to "property", and set to a string instead of the previous array).
Also, the "initial_place" key has been changed to "initial_places" to align with the Symfony component as well.
Non-package Discovery
If you aren't using package discovery:
Add a ServiceProvider to your providers array in config/app.php
:
Add the Workflow
facade to your facades array:
Configuration
Publish the config file
Configure your workflow in config/workflow.php
If you are using a "multiple_state" type of marking_store (i.e. you will be in multiple places simultaneously in your workflow), you will need your supported class/Eloquent model to cast the marking to an array. Read more in the Laravel docs.
You may also add in metadata, similar to the Symfony implementation (note: it is not collected the same way as Symfony's implementation, but should work the same. Please open a pull request or issue if that's not the case.)
Use the WorkflowTrait
inside supported classes
Usage
Symfony Workflow Usage
Once you have the underlying Symfony workflow component, you can do anything you want, just like you would in Symfony. A couple examples are provided below, but be sure to take a look at the Symfony docs to better understand what's going on here.
Use the events
This package provides a list of events fired during a transition
You can subscribe to an event
You are also welcome to use Symfony's dot syntax style of event emission.
NOTE: these events receive the Symfony event prior to version 3.1.1, and will receive this package's events starting with version 3.1.1
Workflow vs State Machine
When using a multi-state workflow, it becomes necessary to distinguish between an array of multiple places that can transition to one place, or a situation where a subject in exactly multiple places transitions to one. Since the config is a PHP array, you must "nest" the latter situation into an array, so that it builds a transition using an array of places, rather that looping through single places.
Example 1. Exactly two places transition to one
In this example, a draft must be in both content_approved
and legal_approved
at the same time
Example 2. Either of two places transition to one
In this example, a draft can transition from EITHER content_approved
OR legal_approved
to published
Dump Workflows
Symfony workflow uses GraphvizDumper to create the workflow image. You may need to install the dot
command of Graphviz
php artisan workflow:dump workflow_name --class App\\BlogPost
You can change the image format with the --format
option. By default the format is png.
php artisan workflow:dump workflow_name --format=jpg
Use in tracking mode
If you are loading workflow definitions through some dynamic means (perhaps via DB), you'll most likely want to turn on registry tracking. This will enable you to see what has been loaded, to prevent or ignore duplicate workflow definitions.
Set track_loaded
to true
in the workflow_registry.php
config file.
You can dynamically load a workflow by using the addFromArray
method on the workflow registry
NOTE: There's no persistence for dynamic workflows, this package assumes you're storing those somehow (DB, etc). To use the dynamic workflows, you will need to load the workflow prior to using it. The loadWorkflow()
method above could be tied into a model boot()
or similar.
You may also specify an initial_places
in your workflow definition, if it is not the first place in the "places" list.
All versions of laravel-workflow with dependencies
symfony/workflow Version ^5.0
symfony/process Version ^5.0
symfony/event-dispatcher Version ^5.0
illuminate/console Version ^7.1|^8.0
illuminate/support Version ^7.1|^8.0
illuminate/contracts Version ^7.1|^8.0