Skip to content

Commit 134a58b

Browse files
committed
[Workflow] Fixed code and tests
1 parent 1843012 commit 134a58b

18 files changed

+206
-25
lines changed

UPGRADE-3.3.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,9 @@ TwigBridge
5959

6060
* The `TwigRendererEngine::setEnvironment()` method has been deprecated and will be removed
6161
in 4.0. Pass the Twig Environment as second argument of the constructor instead.
62+
63+
Workflow
64+
--------
65+
66+
* Deprecated class name support in `WorkflowRegistry::add()` as second parameter.
67+
Wrap the class name in an instance of ClassInstanceSupportStrategy instead.

UPGRADE-4.0.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ FrameworkBundle
154154
* The `framework.serializer.cache` option and the services
155155
`serializer.mapping.cache.apc` and `serializer.mapping.cache.doctrine.apc`
156156
have been removed. APCu should now be automatically used when available.
157-
157+
158158
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been removed. Use `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass` instead.
159159

160160
SecurityBundle
@@ -216,7 +216,7 @@ Serializer
216216
* The ability to pass a Doctrine `Cache` instance to the `ClassMetadataFactory`
217217
class has been removed. You should use the `CacheClassMetadataFactory` class
218218
instead.
219-
219+
220220
* Not defining the 6th argument `$format = null` of the
221221
`AbstractNormalizer::instantiateObject()` method when overriding it is not
222222
supported anymore.
@@ -294,9 +294,9 @@ Validator
294294
// ...
295295
}
296296
```
297-
297+
298298
* The default value of the strict option of the `Choice` Constraint has been
299-
changed to `true` as of 4.0. If you need the previous behaviour ensure to
299+
changed to `true` as of 4.0. If you need the previous behaviour ensure to
300300
set the option to `false`.
301301

302302
Yaml
@@ -393,5 +393,10 @@ Yaml
393393

394394
Ldap
395395
----
396-
397-
* The `RenameEntryInterface` has been deprecated, and merged with `EntryManagerInterface`
396+
397+
* The `RenameEntryInterface` has been deprecated, and merged with `EntryManagerInterface`
398+
399+
Workflow
400+
--------
401+
402+
* Removed class name support in `WorkflowRegistry::add()` as second parameter.

src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Workflow\Definition;
1616
use Symfony\Component\Workflow\Marking;
1717
use Symfony\Component\Workflow\Registry;
18+
use Symfony\Component\Workflow\SupportStrategy\ClassInstanceSupportStrategy;
1819
use Symfony\Component\Workflow\Transition;
1920
use Symfony\Component\Workflow\Workflow;
2021

@@ -37,7 +38,7 @@ protected function setUp()
3738
$workflow = new Workflow($definition);
3839

3940
$registry = new Registry();
40-
$registry->add($workflow, \stdClass::class);
41+
$registry->add($workflow, new ClassInstanceSupportStrategy(\stdClass::class));
4142

4243
$this->extension = new WorkflowExtension($registry);
4344
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
295295
->scalarNode('support_strategy')
296296
->cannotBeEmpty()
297297
->end()
298-
->scalarNode('initial_place')->defaultNull()->end()
298+
->scalarNode('initial_place')
299+
->defaultNull()
300+
->end()
299301
->arrayNode('places')
300302
->isRequired()
301303
->requiresAtLeastOneElement()
@@ -356,9 +358,17 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
356358
->end()
357359
->end()
358360
->validate()
359-
->ifTrue(function ($v) { return isset($v['supports']) && isset($v['support_strategy']); })
361+
->ifTrue(function ($v) {
362+
return $v['supports'] && isset($v['support_strategy']);
363+
})
360364
->thenInvalid('"supports" and "support_strategy" cannot be used together.')
361365
->end()
366+
->validate()
367+
->ifTrue(function ($v) {
368+
return !$v['supports'] && !isset($v['support_strategy']);
369+
})
370+
->thenInvalid('"supports" or "support_strategy" should be configured.')
371+
->end()
362372
->end()
363373
->end()
364374
->end()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
476476
$container->setDefinition(sprintf('%s.definition', $workflowId), $definitionDefinition);
477477

478478
// Add workflow to Registry
479-
if (isset($workflow['supports'])) {
479+
if ($workflow['supports']) {
480480
foreach ($workflow['supports'] as $supportedClassName) {
481481
$strategyDefinition = new Definition(ClassInstanceSupportStrategy::class, array($supportedClassName));
482482
$strategyDefinition->setPublic(false);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,14 @@
232232
<xsd:complexType name="workflow">
233233
<xsd:sequence>
234234
<xsd:element name="marking-store" type="marking_store" />
235-
<xsd:element name="support" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
235+
<xsd:element name="support" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
236236
<xsd:element name="place" type="xsd:string" minOccurs="1" maxOccurs="unbounded" />
237237
<xsd:element name="transition" type="transition" minOccurs="1" maxOccurs="unbounded" />
238238
</xsd:sequence>
239239
<xsd:attribute name="name" type="xsd:string" use="required" />
240240
<xsd:attribute name="type" type="workflow_type" />
241241
<xsd:attribute name="initial-place" type="xsd:string" />
242+
<xsd:attribute name="support-strategy" type="xsd:string" />
242243
</xsd:complexType>
243244

244245
<xsd:complexType name="marking_store">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'my_workflow' => array(
8+
'marking_store' => array(
9+
'type' => 'multiple_state',
10+
),
11+
'supports' => array(
12+
FrameworkExtensionTest::class,
13+
),
14+
'support_strategy' => 'foobar',
15+
'places' => array(
16+
'first',
17+
'last',
18+
),
19+
'transitions' => array(
20+
'go' => array(
21+
'from' => array(
22+
'first',
23+
),
24+
'to' => array(
25+
'last',
26+
),
27+
),
28+
),
29+
),
30+
),
31+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'my_workflow' => array(
8+
'marking_store' => array(
9+
'type' => 'multiple_state',
10+
),
11+
'places' => array(
12+
'first',
13+
'last',
14+
),
15+
'transitions' => array(
16+
'go' => array(
17+
'from' => array(
18+
'first',
19+
),
20+
'to' => array(
21+
'last',
22+
),
23+
),
24+
),
25+
),
26+
),
27+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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 http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflow name="my_workflow" support-strategy="foobar">
11+
<framework:marking-store type="multiple_state"/>
12+
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
13+
<framework:place>first</framework:place>
14+
<framework:place>last</framework:place>
15+
<framework:transition name="foobar">
16+
<framework:from>a</framework:from>
17+
<framework:to>a</framework:to>
18+
</framework:transition>
19+
</framework:workflow>
20+
</framework:config>
21+
</container>
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 http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config>
10+
<framework:workflow name="my_workflow">
11+
<framework:marking-store type="multiple_state"/>
12+
<framework:place>first</framework:place>
13+
<framework:place>last</framework:place>
14+
<framework:transition name="foobar">
15+
<framework:from>a</framework:from>
16+
<framework:to>a</framework:to>
17+
</framework:transition>
18+
</framework:workflow>
19+
</framework:config>
20+
</container>

0 commit comments

Comments
 (0)