Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 004751c

Browse files
committed
[FrameworkBundle][Workflow] Deprecate the default type of a workflow
Before this patch, the default type is "workflow". Most of the time a "state_machine" is better because it's simpler and it involves less knowledge to be able to use it. So this patch deprecate a missing type in Symfony 3.3. And In Symfony 4.0 the default value will become "state_machine".
1 parent 46fc0b9 commit 004751c

File tree

12 files changed

+86
-11
lines changed

12 files changed

+86
-11
lines changed

UPGRADE-3.3.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ Form
138138
* Using the "choices" option in ``CountryType``, ``CurrencyType``, ``LanguageType``,
139139
``LocaleType``, and ``TimezoneType`` without overriding the ``choice_loader``
140140
option has been deprecated and will be ignored in 4.0.
141-
141+
142142
Before:
143143
```php
144144
$builder->add('custom_locales', LocaleType::class, array(
145145
'choices' => $availableLocales,
146146
));
147147
```
148-
148+
149149
After:
150150
```php
151151
$builder->add('custom_locales', LocaleType::class, array(
@@ -168,6 +168,9 @@ FrameworkBundle
168168

169169
* The "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter have been deprecated and will be removed in 4.0. Use the Request::setTrustedProxies() method in your front controller instead.
170170

171+
* Not defining the `type` option of the `framework.workflows.*` configuration entries is deprecated.
172+
The default value will be `state_machine` in Symfony 4.0.
173+
171174
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass` has been deprecated.
172175

173176
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated.

UPGRADE-4.0.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ Form
198198
* Using the "choices" option in ``CountryType``, ``CurrencyType``, ``LanguageType``,
199199
``LocaleType``, and ``TimezoneType`` without overriding the ``choice_loader``
200200
option is now ignored.
201-
201+
202202
Before:
203203
```php
204204
$builder->add('custom_locales', LocaleType::class, array(
205205
'choices' => $availableLocales,
206206
));
207207
```
208-
208+
209209
After:
210210
```php
211211
$builder->add('custom_locales', LocaleType::class, array(
@@ -228,6 +228,8 @@ FrameworkBundle
228228

229229
* The "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter have been removed. Use the `Request::setTrustedProxies()` method in your front controller instead.
230230

231+
* The default value of the `framework.workflows.[name].type` configuration options is now `state_machine`.
232+
231233
* Support for absolute template paths has been removed.
232234

233235
* The following form types registered as services have been removed; use their
@@ -411,7 +413,7 @@ Security
411413

412414
* The `RoleInterface` has been removed. Extend the `Symfony\Component\Security\Core\Role\Role`
413415
class instead.
414-
416+
415417
* The `LogoutUrlGenerator::registerListener()` method expects a 6th `$context = null` argument.
416418

417419
* The `AccessDecisionManager::setVoters()` method has been removed. Pass the

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ CHANGELOG
44
3.3.0
55
-----
66

7+
* Not defining the `type` option of the `framework.workflows.*` configuration entries is deprecated.
8+
The default value will be `state_machine` in Symfony 4.0.
79
* Deprecated the `CompilerDebugDumpPass` class
810
* [BC BREAK] Removed the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter
911
* Added a new new version strategy option called json_manifest_path
@@ -33,13 +35,13 @@ CHANGELOG
3335
* Deprecated `ControllerArgumentValueResolverPass`. Use
3436
`Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` instead
3537
* Deprecated `RoutingResolverPass`, use `Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` instead
36-
* [BC BREAK] The `server:run`, `server:start`, `server:stop` and
37-
`server:status` console commands have been moved to a dedicated bundle.
38-
Require `symfony/web-server-bundle` in your composer.json and register
38+
* [BC BREAK] The `server:run`, `server:start`, `server:stop` and
39+
`server:status` console commands have been moved to a dedicated bundle.
40+
Require `symfony/web-server-bundle` in your composer.json and register
3941
`Symfony\Bundle\WebServerBundle\WebServerBundle` in your AppKernel to use them.
4042
* Added `$defaultLocale` as 3rd argument of `Translator::__construct()`
4143
making `Translator` works with any PSR-11 container
42-
* Added `framework.serializer.mapping` config option allowing to define custom
44+
* Added `framework.serializer.mapping` config option allowing to define custom
4345
serialization mapping files and directories
4446
* Deprecated `AddValidatorInitializersPass`, use
4547
`Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode)
230230
->end()
231231
->enumNode('type')
232232
->values(array('workflow', 'state_machine'))
233-
->defaultValue('workflow')
234233
->end()
235234
->arrayNode('marking_store')
236235
->fixXmlConfig('argument')

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ private function registerWorkflowConfiguration(array $workflows, ContainerBuilde
440440
$registryDefinition = $container->getDefinition('workflow.registry');
441441

442442
foreach ($workflows as $name => $workflow) {
443+
if (!array_key_exists('type', $workflow)) {
444+
$workflow['type'] = 'workflow';
445+
@trigger_error(sprintf('The "type" option of the "framework.workflows.%s" configuration entry must be defined since Symfony 3.3. The default value will be "state_machine" in Symfony 4.0.', $name), E_USER_DEPRECATED);
446+
}
443447
$type = $workflow['type'];
444448

445449
$transitions = array();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
),
9090
),
9191
'service_marking_store_workflow' => array(
92+
'type' => 'workflow',
9293
'marking_store' => array(
9394
'service' => 'workflow_service',
9495
),
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
4+
5+
$container->loadFromExtension('framework', array(
6+
'workflows' => array(
7+
'missing_type' => array(
8+
'marking_store' => array(
9+
'service' => 'workflow_service',
10+
),
11+
'supports' => array(
12+
\stdClass::class,
13+
),
14+
'places' => array(
15+
'first',
16+
'last',
17+
),
18+
'transitions' => array(
19+
'go' => array(
20+
'from' => 'first',
21+
'to' => 'last',
22+
),
23+
),
24+
),
25+
),
26+
));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
</framework:transition>
8181
</framework:workflow>
8282

83-
<framework:workflow name="service_marking_store_workflow">
83+
<framework:workflow name="service_marking_store_workflow" type="workflow">
8484
<framework:marking-store service="workflow_service"/>
8585
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
8686
<framework:place>first</framework:place>
Lines changed: 21 additions & 0 deletions
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="missing_type">
11+
<framework:marking-store service="workflow_service"/>
12+
<framework:support>stdClass</framework:support>
13+
<framework:place>first</framework:place>
14+
<framework:place>last</framework:place>
15+
<framework:transition name="go">
16+
<framework:from>first</framework:from>
17+
<framework:to>last</framework:to>
18+
</framework:transition>
19+
</framework:workflow>
20+
</framework:config>
21+
</container>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ framework:
6464
from: closed
6565
to: review
6666
service_marking_store_workflow:
67+
type: workflow
6768
marking_store:
6869
service: workflow_service
6970
supports:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
framework:
2+
workflows:
3+
missing_type:
4+
supports: stdClass
5+
places: [ first, second ]
6+
transitions:
7+
go: {from: first, to: last }

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ public function testWorkflows()
207207
$this->assertGreaterThan(0, count($registryDefinition->getMethodCalls()));
208208
}
209209

210+
/**
211+
* @group legacy
212+
* @expectedDeprecation The "type" option of the "framework.workflows.missing_type" configuration entry must be defined since Symfony 3.3. The default value will be "state_machine" in Symfony 4.0.
213+
*/
214+
public function testDeprecatedWorkflowMissingType()
215+
{
216+
$container = $this->createContainerFromFile('workflows_without_type');
217+
}
218+
210219
/**
211220
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
212221
* @expectedExceptionMessage "type" and "service" cannot be used together.

0 commit comments

Comments
 (0)