8000 [Workflow] Changed initial_places to initial_marking, added property … · symfony/symfony@0737d3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0737d3e

Browse files
committed
[Workflow] Changed initial_places to initial_marking, added property instead of type
1 parent 468bca8 commit 0737d3e

File tree

38 files changed

+214
-98
lines changed

38 files changed

+214
-98
lines changed

UPGRADE-4.3.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ Workflow
147147
initial_places: [draft]
148148
```
149149
150-
Yaml
151-
----
152-
153-
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.
154-
155150
Workflow
156151
--------
157152
@@ -183,19 +178,22 @@ Workflow
183178
```yaml
184179
framework:
185180
workflows:
181+
type: workflow
186182
article:
187183
marking_store:
188184
type: multiple
185+
arguments: states
189186
```
190187

191188
After:
192189
```yaml
193190
framework:
194191
workflows:
192+
type: workflow
195193
article:
196194
marking_store:
197195
type: method
198-
196+
property: states
199197
```
200198

201199
* `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead.
@@ -206,16 +204,21 @@ Workflow
206204
workflows:
207205
article:
208206
marking_store:
209-
type: single
207+
arguments: state
210208
```
211209

212210
After:
213211
```yaml
214212
framework:
215213
workflows:
214+
type: state_machine
216215
article:
217216
marking_store:
218217
type: method
219-
arguments:
220-
- true
218+
property: state
221219
```
220+
221+
Yaml
222+
----
223+
224+
* Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0.

UPGRADE-5.0.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,47 @@ Workflow
369369
* `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead.
370370
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
371371
* Removed support of `initial_place`. Use `initial_places` instead.
372-
* `MultipleStateMarkingStore` has been removed.
373-
* `SingleStateMarkingStore` has been removed.
372+
* `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.
373+
374+
Before:
375+
```yaml
376+
framework:
377+
workflows:
378+
type: workflow
379+
article:
380+
marking_store:
381+
type: multiple
382+
arguments: states
383+
```
384+
385+
After:
386+
```yaml
387+
framework:
388+
workflows:
389+
type: workflow
390+
article:
391+
marking_store:
392+
property: states
393+
```
394+
* `SingleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.
395+
396+
Before:
397+
```yaml
398+
framework:
399+
workflows:
400+
article:
401+
marking_store:
402+
arguments: state
403+
```
404+
405+
After:
406+
```yaml
407+
framework:
408+
workflows:
409+
article:
410+
marking_store:
411+
property: state
412+
```
374413

375414
Yaml
376415
----

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

Lines changed: 21 additions & 4 deletions
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_places', '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_marking', 'places', 'transitions']))) {
235235
$workflows = $workflows['workflows'];
236236
}
237237

@@ -256,9 +256,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
256256
->arrayNode('workflows')
257257
->useAttributeAsKey('name')
258258
->prototype('array')
259+
->beforeNormalization()
260+
->always(function ($v) {
261+
if (isset($v['initial_place'])) {
262+
$v['initial_marking'] = [$v['initial_place']];
263+
}
264+
265+
return $v;
266+
})
267+
->end()
259268
->fixXmlConfig('support')
260269
->fixXmlConfig('place')
261-
->fixXmlConfig('initial_place')
262270
->fixXmlConfig('transition')
263271
->children()
264272
->arrayNode('audit_trail')
@@ -272,9 +280,11 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
272280
->fixXmlConfig('argument')
273281
->children()
274282
->enumNode('type')
283+
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "method" instead as it will be the only option in Symfony 5.0.')
275284
->values(['multiple_state', 'single_state', 'method'])
276285
->end()
277286
->arrayNode('arguments')
287+
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.')
278288
->beforeNormalization()
279289
->ifString()
280290
->then(function ($v) { return [$v]; })
@@ -283,6 +293,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
283293
->prototype('scalar')
284294
->end()
285295
->end()
296+
->scalarNode('property')
297+
->defaultNull()
298+
->end()
286299
->scalarNode('service')
287300
->cannotBeEmpty()
288301
->end()
@@ -295,6 +308,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
295308
->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); })
296309
->thenInvalid('"arguments" and "service" cannot be used together.')
297310
->end()
311+
->validate()
312+
->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); })
313+
->thenInvalid('"property" and "service" cannot be used together.')
314+
->end()
298315
->end()
299316
->arrayNode('supports')
300317
->beforeNormalization()
@@ -313,10 +330,10 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
313330
->cannotBeEmpty()
314331
->end()
315332
->scalarNode('initial_place')
316-
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_places" configuration key instead.')
333+
->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_marking" configuration key instead.')
317334
->defaultNull()
318335
->end()
319-
->arrayNode('initial_places')
336+
->arrayNode('initial_marking')
320337
->beforeNormalization()
321338
->ifTrue(function ($v) { return !\is_array($v); })
322339
->then(function ($v) { return [$v]; })

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

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

622622
// Create places
623623
$places = array_column($workflow['places'], 'name');
624-
$initialPlaces = $workflow['initial_places'] ?? $workflow['initial_place'] ?? [];
624+
$initialMarking = $workflow['initial_marking'] ?? $workflow['initial_place'] ?? [];
625625

626626
// Create a Definition
627627
$definitionDefinition = new Definition(Workflow\Definition::class);
628628
$definitionDefinition->setPublic(false);
629629
$definitionDefinition->addArgument($places);
630630
$definitionDefinition->addArgument($transitions);
631-
$definitionDefinition->addArgument($initialPlaces);
631+
$definitionDefinition->addArgument($initialMarking);
632632
$definitionDefinition->addArgument($metadataStoreDefinition);
633633

634634
// Create MarkingStore
@@ -637,6 +637,12 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
637637
foreach ($workflow['marking_store']['arguments'] as $argument) {
638638
$markingStoreDefinition->addArgument($argument);
639639
}
640+
if ('method' === $workflow['marking_store']['type']) {
641+
$markingStoreDefinition->setArguments([
642+
'state_machine' === $type, //single state
643+
$workflow['marking_store']['property'] ?? 'marking',
644+
]);
645+
}
640646
} elseif (isset($workflow['marking_store']['service'])) {
641647
$markingStoreDefinition = new Reference($workflow['marking_store']['service']);
642648
}
@@ -676,7 +682,7 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
676682
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {
677683
return $container->get((string) $ref);
678684
}, $transitions))
679-
->setInitialPlace($initialPlaces)
685+
->setInitialPlace($initialMarking)
680686
->build()
681687
;
682688
$validator->validate($realDefinition, $name);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270

271271
<xsd:complexType name="workflow">
272272
<xsd:sequence>
273-
<xsd:element name="initial-place" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
273+
<xsd:element name="initial-marking" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
274274
<xsd:element name="marking-store" type="marking_store" minOccurs="0" maxOccurs="1" />
275275
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
276276
<xsd:element name="place" type="place" minOccurs="0" maxOccurs="unbounded" />
@@ -280,6 +280,7 @@
280280
<xsd:attribute name="name" type="xsd:string" />
281281
<xsd:attribute name="type" type="workflow_type" />
282282
<xsd:attribute name="initial-place" type="xsd:string" />
283+
<xsd:attribute name="initial-marking" type="xsd:string" />
283284
<xsd:attribute name="support-strategy" type="xsd:string" />
284285
<xsd:attribute name="enabled" type="xsd:boolean" />
285286
</xsd:complexType>
@@ -295,12 +296,14 @@
295296
</xsd:sequence>
296297
<xsd:attribute name="type" type="marking_store_type" />
297298
<xsd:attribute name="service" type="xsd:string" />
299+
<xsd:attribute name="property" type="xsd:string" />
298300
</xsd:complexType>
299301

300302
<xsd:simpleType name="marking_store_type">
301303
<xsd:restriction base="xsd:string">
302304
<xsd:enumeration value="multiple_state" />
303305
<xsd:enumeration value="single_state" />
306+
<xsd:enumeration value="method" />
304307
</xsd:restriction>
305308
</xsd:simpleType>
306309

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4-
53
$container->loadFromExtension('framework', [
64
'workflows' => [
75
'legacy' => [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'workflows' => [
77
'my_workflow' => [
88
'marking_store' => [
9-
'type' => 'multiple_state',
9+
'type' => 'method',
1010
'service' => 'workflow_service',
1111
],
1212
'supports' => [

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
'workflows' => [
77
'article' => [
88
'type' => 'workflow',
9-
'marking_store' => [
10-
'type' => 'multiple_state',
11-
],
129
'supports' => [
1310
FrameworkExtensionTest::class,
1411
],
15-
'initial_places' => ['draft'],
12+
< 741A span class="pl-s">'initial_marking' => ['draft'],
1613
'places' => [
1714
'draft',
1815
'wait_for_journalist',

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
'workflows' => [
77
'article' => [
88
'type' => 'workflow',
9-
'marking_store' => [
10-
'type' => 'multiple_state',
11-
],
129
'supports' => [
1310
FrameworkExtensionTest::class,
1411
],
15-
'initial_places' => ['draft'],
12+
'initial_marking' => ['draft'],
1613
'places' => [
1714
'draft',
1815
'wait_for_journalist',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', [
6+
'workflows' => [
7+
'my_workflow' => [
8+
'type' => 'workflow',
9+
'marking_store' => [
10+
'property' => 'states',
11+
'service' => 'workflow_service',
12+
],
13+
'supports' => [
14+
FrameworkExtensionTest::class,
15+
],
16+
'places' => [
17+
'first',
18+
'last',
19+
],
20+
'transitions' => [
21+
'go' => [
22+
'from' => [
23+
'first',
24+
],
25+
'to' => [
26+
'last',
27+
],
28+
],
29+
],
30+
],
31+
],
32+
]);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
$container->loadFromExtension('framework', [
66
'workflows' => [
77
'my_workflow' => [
8-
'marking_store' => [
9-
'type' => 'multiple_state',
10-
],
8+
'type' => 'workflow',
119
'supports' => [
1210
FrameworkExtensionTest::class,
1311
],

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
<?php
22

3-
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4-
53
$container->loadFromExtension('framework', [
64
'workflows' => [
75
'my_workflow' => [
8-
'marking_store' => [
9-
'type' => 'multiple_state',
10-
],
6+
'type' => 'workflow',
117
'places' => [
128
'first',
139
'last',

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
'workflows' => [
77
'article' => [
88
'type' => 'workflow',
9-
'marking_store' => [
10-
'type' => 'multiple_state',
11-
],
129
'supports' => [
1310
FrameworkExtensionTest::class,
1411
],
15-
'initial_places' => ['draft'],
12+
'initial_marking' => ['draft'],
1613
'places' => [
1714
'draft',
1815
'wait_for_journalist',
@@ -41,13 +38,10 @@
4138
],
4239
],
4340
'pull_request' => [
44-
'marking_store' => [
45-
'type' => 'single_state',
46-
],
4741
'supports' => [
4842
FrameworkExtensionTest::class,
4943
],
50-
'initial_places' => ['start'],
44+
'initial_marking' => 'start',
5145
'metadata' => [
5246
'title' => 'workflow title',
5347
],

0 commit comments

Comments
 (0)
0