feature #22416 [FrameworkBundle][Workflow] Deprecate the default type of a workflow (lyrixx)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[FrameworkBundle][Workflow] Deprecate the default type of a workflow

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

---

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".

Commits
-------

004751c [FrameworkBundle][Workflow] Deprecate the default type of a workflow
This commit is contained in:
Nicolas Grekas 2017-04-18 17:41:42 +02:00
commit 86dbbde66f
12 changed files with 86 additions and 11 deletions

View File

@ -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.

View File

@ -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
@ -415,7 +417,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

View File

@ -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

View File

@ -230,7 +230,6 @@ class Configuration implements ConfigurationInterface
->end()
->enumNode('type')
->values(array('workflow', 'state_machine'))
->defaultValue('workflow')
->end()
->arrayNode('marking_store')
->fixXmlConfig('argument')

View File

@ -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();

View File

@ -89,6 +89,7 @@ $container->loadFromExtension('framework', array(
),
),
'service_marking_store_workflow' => array(
'type' => 'workflow',
'marking_store' => array(
'service' => 'workflow_service',
),

View File

@ -0,0 +1,26 @@
<?php
use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest;
$container->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',
),
),
),
),
));

View File

@ -80,7 +80,7 @@
</framework:transition>
</framework:workflow>
<framework:workflow name="service_marking_store_workflow">
<framework:workflow name="service_marking_store_workflow" type="workflow">
<framework:marking-store service="workflow_service"/>
<framework:support>Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest</framework:support>
<framework:place>first</framework:place>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
<framework:config>
<framework:workflow name="missing_type">
<framework:marking-store service="workflow_service"/>
<framework:support>stdClass</framework:support>
<framework:place>first</framework:place>
<framework:place>last</framework:place>
<framework:transition name="go">
<framework:from>first</framework:from>
<framework:to>last</framework:to>
</framework:transition>
</framework:workflow>
</framework:config>
</container>

View File

@ -64,6 +64,7 @@ framework:
from: closed
to: review
service_marking_store_workflow:
type: workflow
marking_store:
service: workflow_service
supports:

View File

@ -0,0 +1,7 @@
framework:
workflows:
missing_type:
supports: stdClass
places: [ first, second ]
transitions:
go: {from: first, to: last }

View File

@ -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.