You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+94Lines changed: 94 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,9 @@ Bonus: you will get an execution log for each executed workflow - if you want to
21
21
*[Stages](#Stages)
22
22
*[Workflow control](#Workflow-control)
23
23
*[Nested workflows](#Nested-workflows)
24
+
*[Loops](#Loops)
24
25
*[Error handling, logging and debugging](#Error-handling-logging-and-debugging)
26
+
*[Tests](#Tests)
25
27
26
28
## Installation
27
29
@@ -284,6 +286,14 @@ public function failWorkflow(string $reason): void;
284
286
// it's handled like a skipped step.
285
287
public function skipWorkflow(string $reason): void;
286
288
289
+
// Useful when using loops to cancel the current iteration (all upcoming steps).
290
+
// If used outside a loop, it behaves like skipStep.
291
+
public function continue(string $reason): void;
292
+
293
+
// Useful when using loops to break the loop (all upcoming steps and iterations).
294
+
// If used outside a loop, it behaves like skipStep.
295
+
public function break(string $reason): void;
296
+
287
297
// Attach any additional debug info to your current step.
288
298
// The infos will be shown in the workflow debug log.
289
299
public function attachStepInfo(string $info): void
@@ -327,6 +337,82 @@ The nested workflow will gain access to a merged **WorkflowContainer** which pro
327
337
If you add additional data to the merged container the data will be present in your main workflow container after the nested workflow execution has been completed.
328
338
For example your implementations of the steps used in the nested workflow will have access to the keys `nested-data` and `parent-data`.
329
339
340
+
## Loops
341
+
342
+
If you handle multiple entities in your workflows at once you may need loops.
343
+
An approach would be to set up a single step which contains the loop and all logic which is required to be executed in a loop.
344
+
But if there are multiple steps required to be executed in the loop you may want to split the step into various steps.
345
+
By using the `Loop` class you can execute multiple steps in a loop.
346
+
For example let's assume our `AddSongToPlaylist` becomes a `AddSongsToPlaylist` workflow which can add multiple songs at once:
347
+
348
+
```php
349
+
$workflowResult = (new \PHPWorkflow\Workflow('AddSongToPlaylist'))
// update the songs entry to handle the songs step by step
399
+
$container->set('songs', $songs);
400
+
401
+
return true;
402
+
}
403
+
}
404
+
```
405
+
406
+
A loop step may contain a nested workflow if you need more complex steps.
407
+
408
+
To control the flow of the loop from the steps you can use the `continue` and `break` methods on the `WorkflowControl` object.
409
+
410
+
By default, a loop is stopped if a step fails.
411
+
You can set the second parameter of the `Loop` class (`$continueOnError`) to true to continue the execution with the next iteration.
412
+
If you enable this option a failed step will not result in a failed workflow.
413
+
Instead, a warning will be added to the process log.
414
+
Calls to `failWorkflow` and `skipWorkflow` will always cancel the loop (and consequently the workflow) independent of the option.
415
+
330
416
## Error handling, logging and debugging
331
417
332
418
The **executeWorkflow** method returns an **WorkflowResult** object which provides the following methods to determine the result of the workflow:
@@ -412,3 +498,11 @@ Summary:
412
498
413
499
In this example the **AcceptOpenSuggestionForSong** step found a matching open suggestion and successfully accepted the suggestion.
414
500
Consequently, the further workflow execution is skipped.
501
+
502
+
503
+
## Tests ##
504
+
505
+
The library is tested via [PHPUnit](https://phpunit.de/).
506
+
507
+
After installing the dependencies of the library via `composer update` you can execute the tests with `./vendor/bin/phpunit` (Linux) or `vendor\bin\phpunit.bat` (Windows).
508
+
The test names are optimized for the usage of the `--testdox` output.
0 commit comments