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
The recommended way to install php-workflow is through [Composer](http://getcomposer.org):
35
+
32
36
```
33
37
$ composer require wol-soft/php-workflow
34
38
```
@@ -155,6 +159,8 @@ class AcceptOpenSuggestionForSong implements \PHPWorkflow\Step\WorkflowStep {
155
159
}
156
160
```
157
161
162
+
## Workflow container
163
+
158
164
Now let's have a more detailed look at the **WorkflowContainer** which helps us, to share data and objects between our workflow steps.
159
165
The relevant objects for our example workflow is the **User** who wants to add the song, the **Song** object of the song to add and the **Playlist** object.
160
166
Before we execute our workflow we can set up a **WorkflowContainer** which contains all relevant objects:
@@ -166,6 +172,22 @@ $workflowContainer = (new \PHPWorkflow\State\WorkflowContainer())
166
172
->set('playlist', (new PlaylistRepository())->getPlaylistById($request->get('playlistId')));
167
173
```
168
174
175
+
The workflow container provides the following interface:
176
+
177
+
```php
178
+
// returns an item or null if the key doesn't exist
179
+
public function get(string $key)
180
+
// set or update a value
181
+
public function set(string $key, $value): self
182
+
// remove an entry
183
+
public function unset(string $key): self
184
+
// check if a key exists
185
+
public function has(string $key): bool
186
+
```
187
+
188
+
Each workflow step may define requirements, which entries must be present in the workflow container before the step is executed.
189
+
For more details have a look at [Required container values](#Required-container-values).
190
+
169
191
Alternatively to set and get the values from the **WorkflowContainer** via string keys you can extend the **WorkflowContainer** and add typed properties/functions to handle values in a type-safe manner:
170
192
171
193
```php
@@ -192,7 +214,7 @@ $workflowResult = (new \PHPWorkflow\Workflow('AddSongToPlaylist'))
192
214
->executeWorkflow($workflowContainer);
193
215
```
194
216
195
-
Another possibility would be to define a step in the **Prepare** stage (e.g. **PopulateAddSongToPlaylistContainer**) which populates the injected **WorkflowContainer** object.
217
+
Another possibility would be to define a step in the **Prepare** stage (e.g. **PopulateAddSongToPlaylistContainer**) which populates the automatically injected empty**WorkflowContainer** object.
196
218
197
219
## Stages
198
220
@@ -425,6 +447,40 @@ If you enable this option a failed step will not result in a failed workflow.
425
447
Instead, a warning will be added to the process log.
426
448
Calls to `failWorkflow` and `skipWorkflow` will always cancel the loop (and consequently the workflow) independent of the option.
427
449
450
+
## Step dependencies
451
+
452
+
Each step implementation may apply dependencies to the step.
453
+
By defining dependencies you can set up validation rules which are checked before your step is executed (for example: which data nust be provided in the workflow container).
454
+
If any of the dependencies is not fulfilled the step will not be executed and is handled as a failed step.
455
+
456
+
Note: as this feature uses [Attributes](https://www.php.net/manual/de/language.attributes.overview.php), it is only available if you use PHP >= 8.0.
457
+
458
+
### Required container values
459
+
460
+
With the `\PHPWorkflow\Step\Dependency\Required` attribute you can define keys which must be present in the provided workflow container.
461
+
The keys consequently must be provided in the initial workflow or be populated by a previous step.
462
+
Additionally to the key you can also provide the type of the value (eg. `string`).
463
+
464
+
To define the dependency you simply annotate the provided workflow container parameter:
// Implementation which can rely on the defined keys to be present in the container.
479
+
}
480
+
```
481
+
482
+
The following types are supported: `string`, `bool`, `int`, `float`, `object`, `array`, `iterable`, `scalar` as well as object type hints by providing the corresponding FQCN
483
+
428
484
## Error handling, logging and debugging
429
485
430
486
The **executeWorkflow** method returns an **WorkflowResult** object which provides the following methods to determine the result of the workflow:
0 commit comments