Skip to content

Commit 35880b2

Browse files
committed
Added support for many inital places
1 parent 5b38e17 commit 35880b2

31 files changed

+190
-41
lines changed

UPGRADE-4.3.md

+21
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ Security
106106
}
107107
```
108108

109+
Workflow
110+
--------
111+
112+
* `initial_place` is deprecated in favour of `initial_places`.
113+
114+
Before:
115+
```yaml
116+
framework:
117+
workflows:
118+
legacy:
119+
initial_place: draft
120+
```
121+
122+
Before:
123+
```yaml
124+
framework:
125+
workflows:
126+
legacy:
127+
initial_places: [draft]
128+
```
129+
109130
Yaml
110131
----
111132

UPGRADE-5.0.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Finder
8383

8484
Form
8585
----
86-
86+
8787
* Removed support for using the `format` option of `DateType` and `DateTimeType` when the `html5` option is enabled.
8888
* Using names for buttons that do not start with a letter, a digit, or an underscore leads to an exception.
8989
* Using names for buttons that do not contain only letters, digits, underscores, hyphens, and colons leads to an
@@ -350,6 +350,7 @@ Workflow
350350
* `add` method has been removed use `addWorkflow` method in `Workflow\Registry` instead.
351351
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
352352
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
353+
* Removed support of `initial_place`. Use `initial_places` instead.
353354

354355
Yaml
355356
----

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
228228
$workflows = [];
229229
}
230230

231-
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_place', 'places', 'transitions']))) {
231+
if (1 === \count($workflows) && isset($workflows['workflows']) && array_keys($workflows['workflows']) !== range(0, \count($workflows) - 1) && !empty(array_diff(array_keys($workflows['workflows']), ['audit_trail', 'type', 'marking_store', 'supports', 'support_strategy', 'initial_places', 'places', 'transitions']))) {
232232
$workflows = $workflows['workflows'];
233233
}
234234

@@ -255,6 +255,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
255255
->prototype('array')
256256
->fixXmlConfig('support')
257257
->fixXmlConfig('place')
258+
->fixXmlConfig('initial_place')
258259
->fixXmlConfig('transition')
259260
->children()
260261
->arrayNode('audit_trail')
@@ -309,8 +310,24 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
309310
->cannotBeEmpty()
310311
->end()
311312
->scalarNode('initial_place')
313+
->beforeNormalization()
314+
->ifTrue(function ($v) { return null !== $v;})
315+
->then(function ($v) {
316+
@trigger_error('The "initial_place" configuration key has been deprecated in Symfony 4.3. Use the "initial_places" configuration key instead.', E_USER_DEPRECATED);
317+
318+
return $v;
319+
})
320+
->end()
312321
->defaultNull()
313322
->end()
323+
->arrayNode('initial_places')
324+
->beforeNormalization()
325+
->ifTrue(function ($v) { return !\is_array($v); })
326+
->then(function ($v) { return [$v]; })
327+
->end()
328+
->defaultValue([])
329+
->prototype('scalar')->end()
330+
->end()
314331
->arrayNode('places')
315332
->beforeNormalization()
316333
->always()

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
609609
$definitionDefinition->setPublic(false);
610610
$definitionDefinition->addArgument($places);
611611
$definitionDefinition->addArgument($transitions);
612-
$definitionDefinition->addArgument($workflow['initial_place'] ?? null);
612+
$definitionDefinition->addArgument($workflow['initial_places'] ?? $workflow['initial_place'] ?? []);
613613
$definitionDefinition->addArgument($metadataStoreDefinition);
614614
$definitionDefinition->addTag('workflow.definition', [
615615
'name' => $name,

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@
269269

270270
<xsd:complexType name="workflow">
271271
<xsd:sequence>
272+
<xsd:element name="initial-place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
272273
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
273274
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
274275
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', [
6+
'workflows' => [
7+
'legacy' => [
8+
'type' => 'workflow',
9+
'supports' => [
10+
stdClass::class,
11+
],
12+
'initial_place' => 'draft',
13+
'places' => [
14+
'draft',
15+
'published',
16+
],
17+
'transitions' => [
18+
'publish' => [
19+
'from' => 'draft',
20+
'to' => 'published',
21+
],
22+
],
23+
],
24+
],
25+
]);

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_guard_expression.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'supports' => [
1313
FrameworkExtensionTest::class,
1414
],
15-
'initial_place' => 'draft',
15+
'initial_places' => ['draft'],
1616
'places' => [
1717
'draft',
1818
'wait_for_journalist',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_multiple_transitions_with_same_name.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'supports' => [
1313
FrameworkExtensionTest::class,
1414
],
15-
'initial_place' => 'draft',
15+
'initial_places' => ['draft'],
1616
'places' => [
1717
'draft',
1818
'wait_for_journalist',

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'supports' => [
1313
FrameworkExtensionTest::class,
1414
],
15-
'initial_place' => 'draft',
15+
'initial_places' => ['draft'],
1616
'places' => [
1717
'draft',
1818
'wait_for_journalist',
@@ -47,7 +47,7 @@
4747
'supports' => [
4848
FrameworkExtensionTest::class,
4949
],
50-
'initial_place' => 'start',
50+
'initial_places' => ['start'],
5151
'metadata' => [
5252
'title' => 'workflow title',
5353
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'foo' => [
77
'type' => 'workflow',
88
'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'],
9-
'initial_place' => 'bar',
9+
'initial_places' => ['bar'],
1010
'places' => ['bar', 'baz'],
1111
'transitions' => [
1212
'bar_baz' => [

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'workflows' => [
77
'type' => 'workflow',
88
'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'],
9-
'initial_place' => 'bar',
9+
'initial_places' => ['bar'],
1010
'places' => ['bar', 'baz'],
1111
'transitions' => [
1212
'bar_baz' => [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflow name="legacy" type="workflow" initial-place="draft">
11+
<framework:support>stdClass</framework:support>
12+
<framework:place name="draft"></framework:place>
13+
<framework:place name="published"></framework:place>
14+
<framework:transition name="publish">
15+
<framework:from>draft</framework:from>
16+
<framework:to>published</framework:to>
17+
</framework:transition>
18+
</framework:workflow>
19+
</framework:config>
20+
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config>
10-
<framework:workflow name="article" type="workflow" initial-place="draft">
10+
<framework:workflow name="article" type="workflow">
11+
<framework:initial-place>draft</framework:initial-place>
1112
<framework:marking-store type="multiple_state">
1213
<framework:argument>a</framework:argument>
1314
<framework:argument>a</framework:argument>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config>
10-
<framework:workflow name="article" type="workflow" initial-place="draft">
10+
<framework:workflow name="article" type="workflow">
11+
<framework:initial-place>draft</framework:initial-place>
1112
<framework:marking-store type="multiple_state">
1213
<framework:argument>a</framework:argument>
1314
<framework:argument>a</framework:argument>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
88

99
<framework:config>
10-
<framework:workflow name="article" type="workflow" initial-place="draft">
10+
<framework:workflow name="article" type="workflow">
11+
<framework:initial-place>draft</framework:initial-place>
1112
<framework:marking-store type="multiple_state">
1213
<framework:argument>a</framework:argument>
1314
<framework:argument>a</framework:argument>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
77

88
<framework:config>
9-
<framework:workflow enabled="true" name="foo" type="workflow" initial-place="bar">
9+
<framework:workflow enabled="true" name="foo" type="workflow">
10+
<framework:initial-place>bar</framework:initial-place>
1011
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
1112
<framework:place>bar</framework:place>
1213
<framework:place>baz</framework:place>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
77

88
<framework:config>
9-
<framework:workflow enabled="true" name="workflows" type="workflow" initial-place="bar">
9+
<framework:workflow enabled="true" name="workflows" type="workflow">
10+
<framework:initial-place>bar</framework:initial-place>
1011
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
1112
<framework:place>bar</framework:place>
1213
<framework:place>baz</framework:place>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
framework:
2+
workflows:
3+
legacy:
4+
type: workflow
5+
initial_place: draft
6+
supports:
7+
- stdClass
8+
places:
9+
- draft
10+
- published
11+
transitions:
12+
publish:
13+
from: draft
14+
to: published

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_guard_expression.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ framework:
66
type: multiple_state
77
supports:
88
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9-
initial_place: draft
9+
initial_places: [draft]
1010
places:
1111
- draft
1212
- wait_for_journalist

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_multiple_transitions_with_same_name.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ framework:
66
type: multiple_state
77
supports:
88
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9-
initial_place: draft
9+
initial_places: [draft]
1010
places:
1111
- draft
1212
- wait_for_journalist

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ framework:
66
type: multiple_state
77
supports:
88
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9-
initial_place: draft
9+
initial_places: [draft]
1010
places:
1111
# simple format
1212
- draft
@@ -33,7 +33,7 @@ framework:
3333
type: single_state
3434
supports:
3535
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
36-
initial_place: start
36+
initial_places: [start]
3737
metadata:
3838
title: workflow title
3939
places:

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ framework:
66
type: workflow
77
supports:
88
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
9-
initial_place: bar
9+
initial_places: [bar]
1010
places:
1111
- bar
1212
- baz

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ framework:
55
type: workflow
66
supports:
77
- Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest
8-
initial_place: bar
8+
initial_places: [bar]
99
places:
1010
- bar
1111
- baz

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

+25-2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public function testWorkflows()
201201
$this->assertSame('workflow.abstract', $container->getDefinition('workflow.article')->getParent());
202202
$this->assertTrue($container->hasDefinition('workflow.article.definition'), 'Workflow definition is registered as a service');
203203

204+
204205
$workflowDefinition = $container->getDefinition('workflow.article.definition');
205206

206207
$this->assertSame(
@@ -217,7 +218,7 @@ public function testWorkflows()
217218
);
218219
$this->assertSame(['workflow.definition' => [['name' => 'article', 'type' => 'workflow', 'marking_store' => 'multiple_state', 'single_state' => false]]], $workflowDefinition->getTags());
219220
$this->assertCount(4, $workflowDefinition->getArgument(1));
220-
$this->assertSame('draft', $workflowDefinition->getArgument(2));
221+
$this->assertSame(['draft'], $workflowDefinition->getArgument(2));
221222

222223
$this->assertTrue($container->hasDefinition('state_machine.pull_request'), 'State machine is registered as a service');
223224
$this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.pull_request')->getParent());
@@ -239,7 +240,7 @@ public function testWorkflows()
239240
);
240241
$this->assertSame(['workflow.definition' => [['name' => 'pull_request', 'type' => 'state_machine', 'marking_store' => 'single_state', 'single_state' => false]]], $stateMachineDefinition->getTags());
241242
$this->assertCount(9, $stateMachineDefinition->getArgument(1));
242-
$this->assertSame('start', $stateMachineDefinition->getArgument(2));
243+
$this->assertSame(['start'], $stateMachineDefinition->getArgument(2));
243244

244245
$metadataStoreDefinition = $stateMachineDefinition->getArgument(3);
245246
$this->assertInstanceOf(Definition::class, $metadataStoreDefinition);
@@ -272,6 +273,28 @@ public function testWorkflows()
272273
$this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls()));
273274
}
274275

276+
public function testWorkflowLegacy()
277+
{
278+
$container = $this->createContainerFromFile('workflow-legacy');
279+
280+
$this->assertTrue($container->hasDefinition('workflow.legacy'), 'Workflow is registered as a service');
281+
$this->assertSame('workflow.abstract', $container->getDefinition('workflow.legacy')->getParent());
282+
$this->assertTrue($container->hasDefinition('workflow.legacy.definition'), 'Workflow definition is registered as a service');
283+
284+
$workflowDefinition = $container->getDefinition('workflow.legacy.definition');
285+
286+
$this->assertSame(['draft'], $workflowDefinition->getArgument(2));
287+
288+
$this->assertSame(
289+
[
290+
'draft',
291+
'published',
292+
],
293+
$workflowDefinition->getArgument(0),
294+
'Places are passed to the workflow definition'
295+
);
296+
}
297+
275298
/**
276299
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
277300
* @expectedExceptionMessage "type" and "service" cannot be used together.

src/Symfony/Component/Workflow/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Trigger `entered` event for subject entering in the Workflow for the first time
88
* Added a context to `Workflow::apply()`. The `MethodMarkingStore` could be used to leverage this feature.
9+
* Added support for many `initialPlaces`
910

1011
4.1.0
1112
-----

0 commit comments

Comments
 (0)