php-utils / laravel-workflow
Simple workflow for laravel 5.6, 5.7
This package's canonical repository appears to be gone and the package has been frozen as a result.
v2.1.1
2018-12-18 09:04 UTC
Requires
- php: ^7.1.3
- illuminate/bus: 5.6.* | 5.7.*
- illuminate/support: 5.6.* | 5.7.*
- php-utils/workflow: ^2.0
README
Supports 5.6 , 5.7
Installation
composer require php-utils/laravel-workflow
Add following to config/app.php
'providers' => [
...
Workflow\Providers\WorkflowServiceProvider::class,
],
'aliases' => [
...
'Workflow' => Workflow\Facades\Workflow::class,
]
Run
php artisan vendor:publish
Select: Provider: Workflow\Providers\WorkflowServiceProvider
Usage
- Create config for your Subject as shown in example
- Your Subject should implement
Workflow\Contracts\Subject
- Create commands for each transition, it should implement
Workflow\Contracts\Command
or extendWorkflow\Commands\Command
. If you want to defer the processing of a time consuming command, you should extend it fromWorkflow\Commands\QueuedCommand
. - If you have no need in separation transitions by roles you can skip implementing
Workflow\Contracts\Who
- If you have no need in passing context to command you can skip imlementing
Workflow\Contracts\Context
Example
You can see example in config/workflow.php after installation.
Full example: https://github.com/vadim-ostapenko/workflow/blob/master/README.md
Config example:
'lesson' => [
'states' => [
'started',
'paused',
'finished'
],
'transitions' => [
[
'name' => 'pause',
'routes' => [
[
'from' => 'started',
'to' => 'paused',
'who' => ['student']
]
]
],
[
'name' => 'finish',
'routes' => [
[
'from' => 'started',
'to' => 'finished',
'who' => ['teacher']
],
[
'from' => 'paused',
'to' => 'finished',
'who' => []
]
]
]
]
]
$lesson = new \WorkflowExample\Subject\Lesson();
$student = new \WorkflowExample\Who\Student();
$teacher = new \WorkflowExample\Who\Teacher();
$workflow = new \Workflow\BusWorkflow($lesson, \Workflow\Facades\Workflow::get('lesson'));
$workflow->can('answer', $teacher); //false
$workflow->make('pause', $student); //pause
$workflow->make('finish', $student); //finish