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
feature #60204 [FrameworkBundle] Add support for configuring workflow places with glob patterns matching consts/backed enums (lyrixx)
This PR was merged into the 7.4 branch.
Discussion
----------
[FrameworkBundle] Add support for configuring workflow places with glob patterns matching consts/backed enums
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Issues |
| License | MIT
This PR improves the DX on two aspects:
- allowing to use FWCN::glob patterns to list places - works with enums and consts
- allowing to use backed enums to list places and reference them in transitions
---
#### Example with consts:
```yaml
framework:
workflows:
my_workflow_name:
places: 'App\Workflow\MyWorkflow::PLACE_*'
transitions:
one:
from: !php/const App\Workflow\MyWorkflow::PLACE_A
to: !php/const App\Workflow\MyWorkflow::PLACE_B
```
and
```php
<?php
namespace App\Workflow;
class MyWorkflow
{
const PLACE_A = 'a';
const PLACE_B = 'b';
const PLACE_C = 'c';
// [...]
}
```
---
#### Example with enums:
```yaml
framework:
workflows:
my_workflow_name:
places: !php/enum App\Workflow\Places
transitions:
one:
from: !php/enum App\Workflow\Places::A
to: !php/enum App\Workflow\Places::B
```
and
```php
<?php
namespace App\Workflow;
enum Places: string
{
case A = 'a';
case B = 'b';
case C = 'c';
}
```
Commits
-------
72dd914 [FrameworkBundle] Add support for configuring workflow places with glob patterns matching consts/backed enums
@@ -364,7 +365,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
364
365
->arrayNode('workflows', 'workflow')
365
366
->canBeEnabled()
366
367
->beforeNormalization()
367
-
->always(function ($v) {
368
+
->always(staticfunction ($v) {
368
369
if (\is_array($v) && true === $v['enabled']) {
369
370
$workflows = $v;
370
371
unset($workflows['enabled']);
@@ -478,15 +479,36 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
478
479
->end()
479
480
->arrayNode('places', 'place')
480
481
->beforeNormalization()
481
-
->always()
482
-
->then(staticfunction ($places) {
483
-
if (!\is_array($places)) {
484
-
thrownewInvalidConfigurationException('The "places" option must be an array in workflow configuration.');
482
+
->always(staticfunction ($places) {
483
+
if (\is_string($places)) {
484
+
if (2 !== \count($places = explode('::', $places, 2))) {
485
+
thrownewInvalidConfigurationException('The "places" option must be a "FQCN::glob" pattern in workflow configuration.');
486
+
}
487
+
[$class, $pattern] = $places;
488
+
if (!class_exists($class) && !interface_exists($class, false)) {
489
+
thrownewInvalidConfigurationException(\sprintf('The "places" option must be a "FQCN::glob" pattern in workflow configuration, but class "%s" is not found.', $class));
0 commit comments