From 004751c5e8f5228bc84ae9430b271f05c2699f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Thu, 13 Apr 2017 11:10:44 +0200 Subject: [PATCH] [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". --- UPGRADE-3.3.md | 7 +++-- UPGRADE-4.0.md | 8 +++--- .../Bundle/FrameworkBundle/CHANGELOG.md | 10 ++++--- .../DependencyInjection/Configuration.php | 1 - .../FrameworkExtension.php | 4 +++ .../Fixtures/php/workflows.php | 1 + .../Fixtures/php/workflows_without_type.php | 26 +++++++++++++++++++ .../Fixtures/xml/workflows.xml | 2 +- .../Fixtures/xml/workflows_without_type.xml | 21 +++++++++++++++ .../Fixtures/yml/workflows.yml | 1 + .../Fixtures/yml/workflows_without_type.yml | 7 +++++ .../FrameworkExtensionTest.php | 9 +++++++ 12 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml diff --git a/UPGRADE-3.3.md b/UPGRADE-3.3.md index 792fe3fc20..a0fd653289 100644 --- a/UPGRADE-3.3.md +++ b/UPGRADE-3.3.md @@ -138,14 +138,14 @@ Form * Using the "choices" option in ``CountryType``, ``CurrencyType``, ``LanguageType``, ``LocaleType``, and ``TimezoneType`` without overriding the ``choice_loader`` option has been deprecated and will be ignored in 4.0. - + Before: ```php $builder->add('custom_locales', LocaleType::class, array( 'choices' => $availableLocales, )); ``` - + After: ```php $builder->add('custom_locales', LocaleType::class, array( @@ -168,6 +168,9 @@ FrameworkBundle * 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. + * Not defining the `type` option of the `framework.workflows.*` configuration entries is deprecated. + The default value will be `state_machine` in Symfony 4.0. + * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CompilerDebugDumpPass` has been deprecated. * The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass` has been deprecated. diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md index 1375d6ffab..c992cd340a 100644 --- a/UPGRADE-4.0.md +++ b/UPGRADE-4.0.md @@ -198,14 +198,14 @@ Form * Using the "choices" option in ``CountryType``, ``CurrencyType``, ``LanguageType``, ``LocaleType``, and ``TimezoneType`` without overriding the ``choice_loader`` option is now ignored. - + Before: ```php $builder->add('custom_locales', LocaleType::class, array( 'choices' => $availableLocales, )); ``` - + After: ```php $builder->add('custom_locales', LocaleType::class, array( @@ -228,6 +228,8 @@ FrameworkBundle * 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. + * The default value of the `framework.workflows.[name].type` configuration options is now `state_machine`. + * Support for absolute template paths has been removed. * The following form types registered as services have been removed; use their @@ -411,7 +413,7 @@ Security * The `RoleInterface` has been removed. Extend the `Symfony\Component\Security\Core\Role\Role` class instead. - + * The `LogoutUrlGenerator::registerListener()` method expects a 6th `$context = null` argument. * The `AccessDecisionManager::setVoters()` method has been removed. Pass the diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index e733a6a0bf..01b3e0e414 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -4,6 +4,8 @@ CHANGELOG 3.3.0 ----- + * Not defining the `type` option of the `framework.workflows.*` configuration entries is deprecated. + The default value will be `state_machine` in Symfony 4.0. * Deprecated the `CompilerDebugDumpPass` class * [BC BREAK] Removed the "framework.trusted_proxies" configuration option and the corresponding "kernel.trusted_proxies" parameter * Added a new new version strategy option called json_manifest_path @@ -33,13 +35,13 @@ CHANGELOG * Deprecated `ControllerArgumentValueResolverPass`. Use `Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass` instead * Deprecated `RoutingResolverPass`, use `Symfony\Component\Routing\DependencyInjection\RoutingResolverPass` instead - * [BC BREAK] The `server:run`, `server:start`, `server:stop` and - `server:status` console commands have been moved to a dedicated bundle. - Require `symfony/web-server-bundle` in your composer.json and register + * [BC BREAK] The `server:run`, `server:start`, `server:stop` and + `server:status` console commands have been moved to a dedicated bundle. + Require `symfony/web-server-bundle` in your composer.json and register `Symfony\Bundle\WebServerBundle\WebServerBundle` in your AppKernel to use them. * Added `$defaultLocale` as 3rd argument of `Translator::__construct()` making `Translator` works with any PSR-11 container - * Added `framework.serializer.mapping` config option allowing to define custom + * Added `framework.serializer.mapping` config option allowing to define custom serialization mapping files and directories * Deprecated `AddValidatorInitializersPass`, use `Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass` instead diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 8b6b4da71f..87d722b91e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -230,7 +230,6 @@ class Configuration implements ConfigurationInterface ->end() ->enumNode('type') ->values(array('workflow', 'state_machine')) - ->defaultValue('workflow') ->end() ->arrayNode('marking_store') ->fixXmlConfig('argument') diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 9a757e8082..8912b2e60d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -440,6 +440,10 @@ class FrameworkExtension extends Extension $registryDefinition = $container->getDefinition('workflow.registry'); foreach ($workflows as $name => $workflow) { + if (!array_key_exists('type', $workflow)) { + $workflow['type'] = 'workflow'; + @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); + } $type = $workflow['type']; $transitions = array(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php index 5ebfeeeb76..c527606561 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php @@ -89,6 +89,7 @@ $container->loadFromExtension('framework', array( ), ), 'service_marking_store_workflow' => array( + 'type' => 'workflow', 'marking_store' => array( 'service' => 'workflow_service', ), diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php new file mode 100644 index 0000000000..63e83170fc --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_without_type.php @@ -0,0 +1,26 @@ +loadFromExtension('framework', array( + 'workflows' => array( + 'missing_type' => array( + 'marking_store' => array( + 'service' => 'workflow_service', + ), + 'supports' => array( + \stdClass::class, + ), + 'places' => array( + 'first', + 'last', + ), + 'transitions' => array( + 'go' => array( + 'from' => 'first', + 'to' => 'last', + ), + ), + ), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml index 509bdd38fc..be065c4558 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml @@ -80,7 +80,7 @@ - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest first diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml new file mode 100644 index 0000000000..2e6ebad552 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_without_type.xml @@ -0,0 +1,21 @@ + + + + + + + + stdClass + first + last + + first + last + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml index 00cd4b55a8..36b84f71e4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml @@ -64,6 +64,7 @@ framework: from: closed to: review service_marking_store_workflow: + type: workflow marking_store: service: workflow_service supports: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml new file mode 100644 index 0000000000..41b81683ba --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_without_type.yml @@ -0,0 +1,7 @@ +framework: + workflows: + missing_type: + supports: stdClass + places: [ first, second ] + transitions: + go: {from: first, to: last } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 8282f082ae..4f86c85d4f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -207,6 +207,15 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertGreaterThan(0, count($registryDefinition->getMethodCalls())); } + /** + * @group legacy + * @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. + */ + public function testDeprecatedWorkflowMissingType() + { + $container = $this->createContainerFromFile('workflows_without_type'); + } + /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "type" and "service" cannot be used together.