Skip to content

Commit fc5b188

Browse files
authored
Merge pull request #18 from zerodahero/3.x
3.x is now primary branch
2 parents ce10ab1 + 5b25ce9 commit fc5b188

15 files changed

+487
-204
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ language: php
33
php:
44
- 7.2
55
- 7.3
6+
- 7.4
67
before_install:
78
- sudo apt-get update -q
89
- sudo apt-get autoremove graphviz -y

README.md

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ This is a fork from [brexis/laravel-workflow](https://github.com/brexis/laravel-
44

55
Use the Symfony Workflow component in Laravel
66

7-
### Installation
7+
## Installation
88

99
composer require zerodahero/laravel-workflow
1010

11-
#### Right now, I've bumped the dependencies up to active PHP version (>=7.2), so in Laravel >= 5.5, use the package auto-discovery
12-
#### For laravel <= 5.4 (Deprecated)
11+
## Upgrade from v2 to v3
12+
13+
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.
14+
15+
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).
16+
17+
Also, the "initial_place" key has been changed to "initial_places" to align with the Symfony component as well.
18+
19+
### Non-package Discovery
20+
21+
If you aren't using package discovery:
1322

1423
Add a ServiceProvider to your providers array in `config/app.php`:
1524

@@ -31,7 +40,7 @@ Add the `Workflow` facade to your facades array:
3140
'Workflow' => ZeroDaHero\LaravelWorkflow\Facades\WorkflowFacade::class,
3241
```
3342

34-
### Configuration
43+
## Configuration
3544

3645
Publish the config file
3746

@@ -45,26 +54,27 @@ Configure your workflow in `config/workflow.php`
4554
<?php
4655

4756
return [
48-
'straight' => [
49-
'type' => 'workflow', // or 'state_machine'
57+
'straight' => [
58+
'type' => 'workflow', // or 'state_machine'
5059
'marking_store' => [
51-
'type' => 'multiple_state',
52-
'arguments' => ['currentPlace']
60+
'type' => 'multiple_state', // or 'single_state'
61+
'property' => 'currentPlace', // this is the property on the model
62+
'class' => MethodMarkingStore::class, // you may omit for default, or set to override marking store class
5363
],
54-
'supports' => ['App\BlogPost'],
55-
'places' => ['draft', 'review', 'rejected', 'published'],
56-
'transitions' => [
64+
'supports' => ['App\BlogPost'],
65+
'places' => ['draft', 'review', 'rejected', 'published'],
66+
'transitions' => [
5767
'to_review' => [
5868
'from' => 'draft',
59-
'to' => 'review'
69+
'to' => 'review'
6070
],
6171
'publish' => [
6272
'from' => 'review',
63-
'to' => 'published'
73+
'to' => 'published'
6474
],
6575
'reject' => [
6676
'from' => 'review',
67-
'to' => 'rejected'
77+
'to' => 'rejected'
6878
]
6979
],
7080
]
@@ -80,18 +90,18 @@ You may also add in metadata, similar to the Symfony implementation (note: it is
8090
<?php
8191

8292
return [
83-
'straight' => [
84-
'type' => 'workflow', // or 'state_machine'
85-
'metadata' => [
93+
'straight' => [
94+
'type' => 'workflow', // or 'state_machine'
95+
'metadata' => [
8696
'title' => 'Blog Publishing Workflow',
8797
],
8898
'marking_store' => [
89-
'type' => 'multiple_state',
90-
'arguments' => ['currentPlace']
99+
'type' => 'multiple_state', // or 'single_state'
100+
'property' => 'currentPlace' // this is the property on the model
91101
],
92-
'supports' => ['App\BlogPost'],
93-
'places' => [
94-
'draft', => [
102+
'supports' => ['App\BlogPost'],
103+
'places' => [
104+
'draft' => [
95105
'metadata' => [
96106
'max_num_of_words' => 500,
97107
]
@@ -100,21 +110,21 @@ return [
100110
'rejected',
101111
'published'
102112
],
103-
'transitions' => [
113+
'transitions' => [
104114
'to_review' => [
105115
'from' => 'draft',
106-
'to' => 'review',
116+
'to' => 'review',
107117
'metadata' => [
108118
'priority' => 0.5,
109119
]
110120
],
111121
'publish' => [
112122
'from' => 'review',
113-
'to' => 'published'
123+
'to' => 'published'
114124
],
115125
'reject' => [
116126
'from' => 'review',
117-
'to' => 'rejected'
127+
'to' => 'rejected'
118128
]
119129
],
120130
]
@@ -137,7 +147,7 @@ class BlogPost extends Model
137147

138148
}
139149
```
140-
### Usage
150+
## Usage
141151

142152
```php
143153
<?php
@@ -178,8 +188,8 @@ $post->workflow_apply('publish');
178188
$post->save();
179189
```
180190

181-
### Symfony Workflow Usage
182-
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](https://symfony.com/doc/current/workflow.html) to better understand what's going on here.
191+
## Symfony Workflow Usage
192+
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](https://symfony.com/doc/current/workflow.html) to better understand what's going on here.
183193

184194
```php
185195
<?php
@@ -328,7 +338,7 @@ class BlogPostWorkflowSubscriber
328338
$events->listen(
329339
'workflow.straight.guard',
330340
'App\Listeners\BlogPostWorkflowSubscriber@onGuard'
331-
);
341+
);
332342

333343
// workflow.leave
334344
// workflow.[workflow name].leave
@@ -381,7 +391,7 @@ class BlogPostWorkflowSubscriber
381391
}
382392
```
383393

384-
### Dump Workflows
394+
## Dump Workflows
385395
Symfony workflow uses GraphvizDumper to create the workflow image. You may need to install the `dot` command of [Graphviz](http://www.graphviz.org/)
386396

387397
php artisan workflow:dump workflow_name --class App\\BlogPost
@@ -390,7 +400,7 @@ You can change the image format with the `--format` option. By default the forma
390400

391401
php artisan workflow:dump workflow_name --format=jpg
392402

393-
### Use in tracking mode
403+
## Use in tracking mode
394404

395405
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.
396406

@@ -410,7 +420,7 @@ return [
410420

411421
/**
412422
* Only used when track_loaded = true
413-
*
423+
*
414424
* When set to true, a registering a duplicate workflow will be ignored (will not load the new definition)
415425
* When set to false, a duplicate workflow will throw a DuplicateWorkflowException
416426
*/
@@ -443,27 +453,27 @@ You can dynamically load a workflow by using the `addFromArray` method on the wo
443453
try {
444454
$registry->addFromArray($workflowName, $workflowDefinition);
445455
} catch (DuplicateWorkflowException $e) {
446-
// already loaded
456+
// already loaded
447457
}
448458
}
449459
```
450460

451-
You may also specify an `initial_place` in your workflow definition, if it is not the first place in the "places" list.
461+
You may also specify an `initial_places` in your workflow definition, if it is not the first place in the "places" list.
452462

453463
```php
454464
<?php
455465

456466
return [
457-
'type' => 'workflow', // or 'state_machine'
458-
'metadata' => [
467+
'type' => 'workflow', // or 'state_machine'
468+
'metadata' => [
459469
'title' => 'Blog Publishing Workflow',
460470
],
461471
'marking_store' => [
462-
'type' => 'multiple_state',
463-
'arguments' => ['currentPlace']
472+
'type' => 'multiple_state',
473+
'property' => 'currentPlace'
464474
],
465-
'supports' => ['App\BlogPost'],
466-
'places' => [
475+
'supports' => ['App\BlogPost'],
476+
'places' => [
467477
'review',
468478
'rejected',
469479
'published',
@@ -473,22 +483,22 @@ return [
473483
]
474484
]
475485
],
476-
'initial_place' => 'draft',
477-
'transitions' => [
486+
'initial_places' => 'draft', // or set to an array if multiple initial places
487+
'transitions' => [
478488
'to_review' => [
479489
'from' => 'draft',
480-
'to' => 'review',
490+
'to' => 'review',
481491
'metadata' => [
482492
'priority' => 0.5,
483493
]
484494
],
485495
'publish' => [
486496
'from' => 'review',
487-
'to' => 'published'
497+
'to' => 'published'
488498
],
489499
'reject' => [
490500
'from' => 'review',
491-
'to' => 'rejected'
501+
'to' => 'rejected'
492502
]
493503
],
494504
];

composer.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "zerodahero/laravel-workflow",
33
"description": "Integerate Symfony Workflow component into Laravel.",
4-
"keywords": ["workflow", "symfony", "laravel", "laravel5"],
4+
"keywords": ["workflow", "symfony", "laravel", "laravel7"],
55
"license": "MIT",
66
"require": {
77
"php": ">=7.2",
8-
"symfony/workflow": "^4.2.9",
9-
"symfony/process": "^4.2",
10-
"symfony/event-dispatcher": "^4.2",
11-
"illuminate/console": "5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0",
12-
"illuminate/support": "5.5.* || 5.6.* || 5.7.* || 5.8.* || ^6.0"
8+
"symfony/workflow": "^5.0",
9+
"symfony/process": "^5.0",
10+
"symfony/event-dispatcher": "^5.0",
11+
"illuminate/console": "^7.0",
12+
"illuminate/support": "^7.0",
13+
"illuminate/contracts": "^7.0"
1314
},
1415
"autoload": {
1516
"psr-4": {
@@ -23,7 +24,7 @@
2324
},
2425
"extra": {
2526
"branch-alias": {
26-
"dev-master": "1.0-dev"
27+
"dev-master": "3.x-dev"
2728
},
2829
"laravel": {
2930
"providers": [
@@ -36,6 +37,8 @@
3637
},
3738
"require-dev": {
3839
"mockery/mockery": "^1.2",
39-
"phpunit/phpunit": "^8.0"
40+
"phpunit/phpunit": "^8.0",
41+
"symfony/var-dumper": "^5.0",
42+
"fzaninotto/faker": "^1.9"
4043
}
4144
}

phpcs.xml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0"?>
22
<ruleset name="custom">
3-
<description>PSR2</description>
3+
<description>PSR12</description>
44

5-
<rule ref="PSR2" />
5+
<rule ref="PSR12" />
66

77
<file>src/</file>
88

@@ -14,27 +14,6 @@
1414
<exclude name="Generic.Commenting.DocComment.NonParamGroup" />
1515
<exclude name="Generic.Commenting.DocComment.MissingShort" />
1616
</rule>
17-
18-
<rule ref="Squiz.Commenting.BlockComment">
19-
<exclude name="Squiz.Commenting.BlockComment.NoEmptyLineAfter" />
20-
</rule>
21-
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
22-
<!-- <rule ref="Squiz.Commenting.EmptyCatchComment"/> -->
23-
<!-- <rule ref="Squiz.Commenting.InlineComment"/> -->
24-
<!-- <rule ref="Squiz.Commenting.LongConditionClosingComment"/> -->
25-
<rule ref="Squiz.Commenting.FunctionComment">
26-
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment" />
27-
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing" />
28-
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital" />
29-
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop" />
30-
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing" />
31-
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows" />
32-
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName" />
33-
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType" />
34-
</rule>
35-
<rule ref="Squiz.Commenting.PostStatementComment"/>
36-
<rule ref="Squiz.Commenting.VariableComment">
37-
<exclude name="Squiz.Commenting.VariableComment.Missing" />
38-
</rule>
17+
<exclude name="Squiz.Commenting" />
3918

4019
</ruleset>

src/Commands/WorkflowDumpCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,27 @@ class WorkflowDumpCommand extends Command
4040
*/
4141
public function handle()
4242
{
43-
$workflowName = $this->argument('workflow');
44-
$format = $this->option('format');
45-
$class = $this->option('class');
46-
$config = Config::get('workflow');
43+
$workflowName = $this->argument('workflow');
44+
$format = $this->option('format');
45+
$class = $this->option('class');
46+
$config = Config::get('workflow');
4747

4848
if (!isset($config[$workflowName])) {
4949
throw new Exception("Workflow $workflowName is not configured.");
5050
}
5151

5252
if (false === array_search($class, $config[$workflowName]['supports'])) {
53-
throw new Exception("Workflow $workflowName has no support for class $class.".
54-
' Please specify a valid support class with the --class option.');
53+
throw new Exception("Workflow $workflowName has no support for class $class." .
54+
' Please specify a valid support class with the --class option.');
5555
}
5656

57-
$subject = new $class;
58-
$workflow = Workflow::get($subject, $workflowName);
57+
$subject = new $class();
58+
$workflow = Workflow::get($subject, $workflowName);
5959
$definition = $workflow->getDefinition();
6060

6161
$dumper = new GraphvizDumper();
6262

63-
$dotCommand = "dot -T$format -o $workflowName.$format";
63+
$dotCommand = ['dot', "-T$format", '-o', "$workflowName.$format"];
6464

6565
$process = new Process($dotCommand);
6666
$process->setInput($dumper->dump($definition));

0 commit comments

Comments
 (0)