-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[WIP] [Workflow] Choose which Workflow events should be dispatched #36633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
stewartmalik
wants to merge
7
commits into
symfony:master
from
stewartmalik:feature/choose-workflow-events
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
388069d
[Workflow] Choose which Workflow events should be dispatched
stewartmalik 808e789
[Workflow] Removed previous change regarding not firing the `announce…
stewartmalik dc38230
[Workflow] Add feedback from Code Review. Add configuration support.
stewartmalik 661bfb9
Update `Workflow` to `transition`
stewartmalik b93e33a
[Workflow] Style fixes suggested by CI
stewartmalik dfe0969
[Workflow] Fix merge conflict
stewartmalik 6dde6db
[Workflow] Another code style fix after the first one broke on patch …
stewartmalik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,6 +282,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) | |
->fixXmlConfig('support') | ||
->fixXmlConfig('place') | ||
->fixXmlConfig('transition') | ||
->fixXmlConfig('dispatched_event') | ||
->children() | ||
->arrayNode('audit_trail') | ||
->canBeEnabled() | ||
|
@@ -324,6 +325,22 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode) | |
->defaultValue([]) | ||
->prototype('scalar')->end() | ||
->end() | ||
->arrayNode('dispatched_events') | ||
->beforeNormalization() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should handle many way to configure the same thing.
So I would remove the case for string. And it would allow to remove special cases for |
||
->ifString() | ||
->then(function ($v) { | ||
return [$v]; | ||
}) | ||
->end() | ||
// We have to specify a default here as when this config option | ||
// isn't set the default behaviour of `arrayNode()` is to return an empty | ||
// array which conflicts with our Definition, and we cannot set a default | ||
// of `null` for arrayNode()'s | ||
->defaultValue(['all']) | ||
->prototype('scalar')->end() | ||
->info('Select which Transition events should be dispatched for this Workflow') | ||
->example(['leave', 'completed']) | ||
->end() | ||
->arrayNode('places') | ||
->beforeNormalization() | ||
->always() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...workBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_all_dispatched_events.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest; | ||
|
||
$container->loadFromExtension('framework', [ | ||
'workflows' => [ | ||
'my_workflow' => [ | ||
'type' => 'state_machine', | ||
'marking_store' => [ | ||
'type' => 'method', | ||
'property' => 'state' | ||
], | ||
'supports' => [ | ||
FrameworkExtensionTest::class, | ||
], | ||
'places' => [ | ||
'one', | ||
'two', | ||
'three', | ||
], | ||
'transitions' => [ | ||
'count_to_two' => [ | ||
'from' => [ | ||
'one', | ||
], | ||
'to' => [ | ||
'two', | ||
], | ||
], | ||
'count_to_three' => [ | ||
'from' => [ | ||
'two', | ||
], | ||
'to' => [ | ||
'three' | ||
] | ||
] | ||
], | ||
], | ||
], | ||
]); |
42 changes: 42 additions & 0 deletions
42
...eworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_no_dispatched_events.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest; | ||
|
||
$container->loadFromExtension('framework', [ | ||
'workflows' => [ | ||
'my_workflow' => [ | ||
'type' => 'state_machine', | ||
'marking_store' => [ | ||
'type' => 'method', | ||
'property' => 'state' | ||
], | ||
'supports' => [ | ||
FrameworkExtensionTest::class, | ||
], | ||
'dispatched_events' => [], | ||
'places' => [ | ||
'one', | ||
'two', | ||
'three', | ||
], | ||
'transitions' => [ | ||
'count_to_two' => [ | ||
'from' => [ | ||
'one', | ||
], | ||
'to' => [ | ||
'two', | ||
], | ||
], | ||
'count_to_three' => [ | ||
'from' => [ | ||
'two', | ||
], | ||
'to' => [ | ||
'three' | ||
] | ||
] | ||
], | ||
], | ||
], | ||
]); |
45 changes: 45 additions & 0 deletions
45
...ndle/Tests/DependencyInjection/Fixtures/php/workflow_with_specified_dispatched_events.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest; | ||
|
||
$container->loadFromExtension('framework', [ | ||
'workflows' => [ | ||
'my_workflow' => [ | ||
'type' => 'state_machine', | ||
'marking_store' => [ | ||
'type' => 'method', | ||
'property' => 'state' | ||
], | ||
'supports' => [ | ||
FrameworkExtensionTest::class, | ||
], | ||
'dispatched_events' => [ | ||
'leave', | ||
'completed' | ||
], | ||
'places' => [ | ||
'one', | ||
'two', | ||
'three', | ||
], | ||
'transitions' => [ | ||
'count_to_two' => [ | ||
'from' => [ | ||
'one', | ||
], | ||
'to' => [ | ||
'two', | ||
], | ||
], | ||
'count_to_three' => [ | ||
'from' => [ | ||
'two', | ||
], | ||
'to' => [ | ||
'three' | ||
] | ||
] | ||
], | ||
], | ||
], | ||
]); |
27 changes: 27 additions & 0 deletions
27
...workBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_all_dispatched_events.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:workflow name="my_workflow" type="state_machine"> | ||
<framework:initial-marking>one</framework:initial-marking> | ||
<framework:marking-store type="method" property="state" /> | ||
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support> | ||
<framework:place name="one" /> | ||
<framework:place name="two" /> | ||
<framework:place name="three" /> | ||
<framework:transition name="count_to_two"> | ||
<framework:from>one</framework:from> | ||
<framework:to>two</framework:to> | ||
</framework:transition> | ||
<framework:transition name="count_to_three"> | ||
<framework:from>two</framework:from> | ||
<framework:to>three</framework:to> | ||
</framework:transition> | ||
</framework:workflow> | ||
</framework:config> | ||
</container> |
28 changes: 28 additions & 0 deletions
28
...eworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_no_dispatched_events.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:workflow name="my_workflow" type="state_machine"> | ||
<framework:initial-marking>one</framework:initial-marking> | ||
<framework:marking-store type="method" property="state" /> | ||
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support> | ||
<framework:dispatched-event>none</framework:dispatched-event> | ||
<framework:place name="one" /> | ||
<framework:place name="two" /> | ||
<framework:place name="three" /> | ||
<framework:transition name="count_to_two"> | ||
<framework:from>one</framework:from> | ||
<framework:to>two</framework:to> | ||
</framework:transition> | ||
<framework:transition name="count_to_three"> | ||
<framework:from>two</framework:from> | ||
<framework:to>three</framework:to> | ||
</framework:transition> | ||
</framework:workflow> | ||
</framework:config> | ||
</container> |
29 changes: 29 additions & 0 deletions
29
...ndle/Tests/DependencyInjection/Fixtures/xml/workflow_with_specified_dispatched_events.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:framework="http://symfony.com/schema/dic/symfony" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd | ||
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> | ||
|
||
<framework:config> | ||
<framework:workflow name="my_workflow" type="state_machine"> | ||
<framework:initial-marking>one</framework:initial-marking> | ||
<framework:marking-store type="method" property="state" /> | ||
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support> | ||
<framework:dispatched-event>leave</framework:dispatched-event> | ||
<framework:dispatched-event>completed</framework:dispatched-event> | ||
<framework:place name="one" /> | ||
<framework:place name="two" /> | ||
<framework:place name="three" /> | ||
<framework:transition name="count_to_two"> | ||
<framework:from>one</framework:from> | ||
<framework:to>two</framework:to> | ||
</framework:transition> | ||
<framework:transition name="count_to_three"> | ||
<framework:from>two</framework:from> | ||
<framework:to>three</framework:to> | ||
</framework:transition> | ||
</framework:workflow> | ||
</framework:config> | ||
</container> |
21 changes: 21 additions & 0 deletions
21
...workBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_all_dispatched_events.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
framework: | ||
workflows: | ||
my_workflow: | ||
type: state_machine | ||
initial_marking: one | ||
marking_store: | ||
type: method | ||
property: state | ||
supports: | ||
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest | ||
places: | ||
- one | ||
- two | ||
- three | ||
transitions: | ||
count_to_two: | ||
from: one | ||
to: two | ||
count_to_three: | ||
from: two | ||
to: three |
22 changes: 22 additions & 0 deletions
22
...eworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_no_dispatched_events.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
framework: | ||
workflows: | ||
my_workflow: | ||
type: state_machine | ||
initial_marking: one | ||
dispatched_events: [] | ||
marking_store: | ||
type: method | ||
property: state | ||
supports: | ||
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest | ||
places: | ||
- one | ||
- two | ||
- three | ||
transitions: | ||
count_to_two: | ||
from: one | ||
to: two | ||
count_to_three: | ||
from: two | ||
to: three |
22 changes: 22 additions & 0 deletions
22
...ndle/Tests/DependencyInjection/Fixtures/yml/workflow_with_specified_dispatched_events.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
framework: | ||
workflows: | ||
my_workflow: | ||
type: state_machine | ||
initial_marking: one | ||
dispatched_events: ['leave', 'completed'] | ||
marking_store: | ||
type: method | ||
property: state | ||
supports: | ||
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest | ||
places: | ||
- one | ||
- two | ||
- three | ||
transitions: | ||
count_to_two: | ||
from: one | ||
to: two | ||
count_to_three: | ||
from: two | ||
to: three |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could definitely use input on configuration here, this is my first time working on the Symfony code base and this was somewhat confusing.
I ran into issues with a number of things such as expressing an empty array in the XML configuration format, as well as having a default null value for arrayNodes.
I have worked around this by specifying
all
andnone
as allowed values for this configuration option however these are mostly hidden from the end user. The only exception is with the XML configuration where you need to specifynone
to remove all events from being fired.