8000 Added support for many inital places · symfony/symfony@1af1bf2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1af1bf2

Browse files
committed
Added support for many inital places
1 parent fc826aa commit 1af1bf2

37 files changed

+250
-45
lines changed

UPGRADE-4.3.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ Security
127127
}
128128
```
129129

130+
Workflow
131+
--------
132+
133+
* `initial_place` is deprecated in favour of `initial_places`.
134+
135+
Before:
136+
```yaml
137+
framework:
138+
workflows:
139+
article:
140+
initial_place: draft
141+
```
142+
143+
After:
144+
```yaml
145+
framework:
146+
workflows:
147+
article:
148+
initial_places: [draft]
149+
```
150+
130151
Yaml
131152
----
132153

UPGRADE-5.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ Workflow
368368
* `SupportStrategyInterface` has been removed, use `WorkflowSupportStrategyInterface` instead.
369369
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
370370
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
371+
* Removed support of `initial_place`. Use `initial_places` instead.
371372

372373
Yaml
373374
----

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
231231
$workflows = [];
232232
}
233233

234-
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']))) {
234+
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']))) {
235235
$workflows = $workflows['workflows'];
236236
}
237237

@@ -258,6 +258,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
258258
->prototype('array')
259259
->fixXmlConfig('support')
260260
->fixXmlConfig('place')
261+
->fixXmlConfig('initial_place')
261262
->fixXmlConfig('transition')
262263
->children()
263264
->arrayNode('audit_trail')
@@ -312,8 +313,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
312313
->cannotBeEmpty()
313314
->end()
314315
->scalarNode('initial_place')
316+
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_places" configuration key instead.')
315317
->defaultNull()
316318
->end()
319+
->arrayNode('initial_places')
320+
->beforeNormalization()
321+
->ifTrue(function ($v) { return !\is_array($v); })
322+
->then(function ($v) { return [$v]; })
323+
->end()
324+
->defaultValue([])
325+
->prototype('scalar')->end()
326+
->end()
317327
->arrayNode('places')
318328
->beforeNormalization()
319329
->always()

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,14 +615,14 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
615615

616616
// Create places
617617
$places = array_column($workflow['places'], 'name');
618-
$initialPlace = $workflow['initial_place'] ?? null;
618+
$initialPlaces = $workflow['initial_places'] ?? $workflow['initial_place'] ?? [];
619619

620620
// Create a Definition
621621
$definitionDefinition = new Definition(Workflow\Definition::class);
622622
$definitionDefinition->setPublic(false);
623623
$definitionDefinition->addArgument($places);
624624
$definitionDefinition->addArgument($transitions);
625-
$definitionDefinition->addArgument($initialPlace);
625+
$definitionDefinition->addArgument($initialPlaces);
626626
$definitionDefinition->addArgument($metadataStoreDefinition);
627627

628628
// Create MarkingStore
@@ -670,7 +670,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
670670
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {
671671
return $container->get((string) $ref);
672672
}, $transitions))
673-
->setInitialPlace($initialPlace)
673+
->setInitialPlace($initialPlaces)
674674
->build()
675675
;
676676
$validator->validate($realDefinition, $name);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@
270270

271271
<xsd:complexType name="workflow">
272272
<xsd:sequence>
273+
<xsd:element name="initial-place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
273274
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
274275
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
275276
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
Lines changed: 25 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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' => [
Lines changed: 20 additions & 0 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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>
Lines changed: 14 additions & 0 deletions
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

-1Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function testWorkflows()
217217
'Places are passed to the workflow definition'
218218
);
219219
$this->assertCount(4, $workflowDefinition->getArgument(1));
220-
$this->assertSame('draft', $workflowDefinition->getArgument(2));
220+
$this->assertSame(['draft'], $workflowDefinition->getArgument(2));
221221

222222
$this->assertTrue($container->hasDefinition('state_machine.pull_request'), 'State machine is registered as a service');
223223
$this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.pull_request')->getParent());
@@ -238,7 +238,7 @@ public function testWorkflows()
238238
'Places are passed to the state machine definition'
239239
);
240240
$this->assertCount(9, $stateMachineDefinition->getArgument(1));
241-
$this->assertSame('start', $stateMachineDefinition->getArgument(2));
241+
$this->assertSame(['start'], $stateMachineDefinition->getArgument(2));
242242

243243
$metadataStoreDefinition = $stateMachineDefinition->getArgument(3);
244244
$this->assertInstanceOf(Definition::class, $metadataStoreDefinition);
@@ -271,6 +271,28 @@ public function testWorkflows()
271271
$this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls()));
272272
}
273273

274+
public function testWorkflowLegacy()
275+
{
276+
$container = $this->createContainerFromFile('workflow-legacy');
277+
278+
$this->assertTrue($container->hasDefinition('workflow.legacy'), 'Workflow is registered as a service');
279+
$this->assertSame('workflow.abstract', $container->getDefinition('workflow.legacy')->getParent());
280+
$this->assertTrue($container->hasDefinition('workflow.legacy.definition'), 'Workflow definition is registered as a service');
281+
282+
$workflowDefinition = $container->getDefinition('workflow.legacy.definition');
283+
284+
$this->assertSame(['draft'], $workflowDefinition->getArgument(2));
285+
286+
$this->assertSame(
287+
[
288+
'draft',
289+
'published',
290+
],
291+
$workflowDefinition->getArgument(0),
292+
'Places are passed to the workflow definition'
293+
);
294+
}
295+
274296
/**
275297
* @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException
276298
* @expectedExceptionMessage A transition from a place/state must have an unique name. Multiple transitions named "go" from place/state "first" where found on StateMachine "my_workflow".

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"symfony/twig-bundle": "~2.8|~3.2|~4.0",
5555
"symfony/validator": "^4.1",
5656
"symfony/var-dumper": "~3.4|~4.0",
57-
"symfony/workflow": "^4.1",
57+
"symfony/workflow": "^4.3",
5858
"symfony/yaml": "~3.4|~4.0",
5959
"symfony/property-info": "~3.4|~4.0",
6060
"symfony/lock": "~3.4|~4.0",
@@ -79,7 +79,7 @@
7979
"symfony/translation": "<4.3",
8080
"symfony/twig-bridge": "<4.1.1",
8181
"symfony/validator": "<4.1",
82-
"symfony/workflow": "<4.1"
82+
"symfony/workflow": "<4.3"
8383
},
8484
"suggest": {
8585
"ext-apcu": "For best performance of the system caches",

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ CHANGELOG
2626
* Dispatch `EnteredEvent` on `workflow.entered`
2727
* Dispatch `CompletedEvent` on `workflow.completed`
2828
* Dispatch `AnnounceEvent` on `workflow.announce`
29+
* Added support for many `initialPlaces`
2930

3031
4.1.0
3132
-----

0 commit comments

Comments
 (0)
0