Skip to content

[Workflow] Choose which Workflow events should be dispatched #37815

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

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Workflow] Choose which Workflow events should be dispatched
  • Loading branch information
stewartmalik authored and lyrixx committed Aug 13, 2020
commit d70074753cd9c13c33d85f2e6c1a6b30d4eed904
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->fixXmlConfig('support')
->fixXmlConfig('place')
->fixXmlConfig('transition')
->fixXmlConfig('dispatched_event')
->children()
->arrayNode('audit_trail')
->canBeEnabled()
Expand Down Expand Up @@ -381,6 +382,22 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
->defaultValue([])
->prototype('scalar')->end()
->end()
->arrayNode('dispatched_events')
->beforeNormalization()
->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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,25 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
$places = array_column($workflow['places'], 'name');
$initialMarking = $workflow['initial_marking'] ?? [];

// Record which events should be dispatched
if ($workflow['dispatched_events'] === ['all']) {
$dispatchedEvents = null;
} elseif ($workflow['dispatched_events'] === ['none']) {
$dispatchedEvents = [];
} else {
$dispatchedEvents = array_map(function (string $event) {
return 'workflow.'.$event;
}, $workflow['dispatched_events']);
}

// Create a Definition
$definitionDefinition = new Definition(Workflow\Definition::class);
$definitionDefinition->setPublic(false);
$definitionDefinition->addArgument($places);
$definitionDefinition->addArgument($transitions);
$definitionDefinition->addArgument($initialMarking);
$definitionDefinition->addArgument($metadataStoreDefinition);
$definitionDefinition->addArgument($dispatchedEvents);
$definitionDefinition->addTag('workflow.definition', [
'name' => $name,
'type' => $type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
<xsd:element name="initial-marking" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="dispatched-event" type="dispatched_event" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="transition" type="transition" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="metadata" type="metadata" minOccurs="0" maxOccurs="unbounded" />
Expand Down Expand Up @@ -345,6 +346,19 @@
</xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="dispatched_event">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="all" />
<xsd:enumeration value="none" />
<xsd:enumeration value="leave" />
<xsd:enumeration value="transition" />
<xsd:enumeration value="enter" />
<xsd:enumeration value="entered" />
<xsd:enumeration value="completed" />
<xsd:enumeration value="announce" />
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="default_middleware">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="true" />
Expand Down
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'
]
]
],
],
],
]);
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'
]
]
],
],
],
]);
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'
]
]
],
],
],
]);
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>
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>
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>
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
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
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
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy