From 73708a61b6af18f41b8a398645c31e7ca688205c Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sat, 23 Mar 2019 20:20:32 +0100 Subject: [PATCH 1/3] [Workflow] Changed initial_places to initial_marking, added property instead of type --- UPGRADE-4.3.md | 21 +++++---- UPGRADE-5.0.md | 43 ++++++++++++++++++- .../DependencyInjection/Configuration.php | 25 +++++++++-- .../FrameworkExtension.php | 12 ++++-- .../Resources/config/schema/symfony-1.0.xsd | 5 ++- .../Fixtures/php/workflow-legacy.php | 2 - ...low_legacy_with_arguments_and_service.php} | 0 ...workflow_legacy_with_type_and_service.php} | 2 +- .../php/workflow_with_guard_expression.php | 5 +-- ...th_multiple_transitions_with_same_name.php | 5 +-- .../workflow_with_property_and_service.php | 32 ++++++++++++++ ...flow_with_support_and_support_strategy.php | 4 +- ...w_without_support_and_support_strategy.php | 6 +-- .../Fixtures/php/workflows.php | 10 +---- .../php/workflows_explicitly_enabled.php | 2 +- ...ows_explicitly_enabled_named_workflows.php | 2 +- .../Fixtures/xml/workflow-legacy.xml | 4 +- ...low_legacy_with_arguments_and_service.xml} | 0 ...workflow_legacy_with_type_and_service.xml} | 2 +- .../xml/workflow_with_guard_expression.xml | 4 +- ...th_multiple_transitions_with_same_name.xml | 2 +- .../workflow_with_property_and_service.xml | 21 +++++++++ ...flow_with_support_and_support_strategy.xml | 3 +- ...w_without_support_and_support_strategy.xml | 3 +- .../Fixtures/xml/workflows.xml | 18 ++++---- .../xml/workflows_explicitly_enabled.xml | 3 +- ...ows_explicitly_enabled_named_workflows.xml | 2 +- ...low_legacy_with_arguments_and_service.yml} | 0 ...workflow_legacy_with_type_and_service.yml} | 2 +- .../yml/workflow_with_guard_expression.yml | 18 ++++---- ...th_multiple_transitions_with_same_name.yml | 4 +- .../workflow_with_property_and_service.yml | 17 ++++++++ ...flow_with_support_and_support_strategy.yml | 3 +- ...w_without_support_and_support_strategy.yml | 3 +- .../Fixtures/yml/workflows.yml | 8 +--- .../yml/workflows_explicitly_enabled.yml | 2 +- ...ows_explicitly_enabled_named_workflows.yml | 2 +- .../FrameworkExtensionTest.php | 15 ++++++- 38 files changed, 214 insertions(+), 98 deletions(-) rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/{workflow_with_arguments_and_service.php => workflow_legacy_with_arguments_and_service.php} (100%) rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/{workflow_with_type_and_service.php => workflow_legacy_with_type_and_service.php} (94%) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/{workflow_with_arguments_and_service.xml => workflow_legacy_with_arguments_and_service.xml} (100%) rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/{workflow_with_type_and_service.xml => workflow_legacy_with_type_and_service.xml} (91%) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/{workflow_with_arguments_and_service.yml => workflow_legacy_with_arguments_and_service.yml} (100%) rename src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/{workflow_with_type_and_service.yml => workflow_legacy_with_type_and_service.yml} (92%) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index 110e58ed65..aeb2b1181f 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -166,11 +166,6 @@ Workflow initial_places: [draft] ``` -Yaml ----- - - * Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0. - Workflow -------- @@ -202,19 +197,22 @@ Workflow ```yaml framework: workflows: + type: workflow article: marking_store: type: multiple + arguments: states ``` After: ```yaml framework: workflows: + type: workflow article: marking_store: type: method - + property: states ``` * `SingleStateMarkingStore` is deprecated. Use `MethodMarkingStore` instead. @@ -225,16 +223,21 @@ Workflow workflows: article: marking_store: - type: single + arguments: state ``` After: ```yaml framework: workflows: + type: state_machine article: marking_store: type: method - arguments: - - true + property: state ``` + +Yaml +---- + + * Using a mapping inside a multi-line string is deprecated and will throw a `ParseException` in 5.0. diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 7c4a38aba2..70bfdf3542 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -388,8 +388,47 @@ Workflow * `ClassInstanceSupportStrategy` has been removed, use `InstanceOfSupportStrategy` instead. * `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`. * Removed support of `initial_place`. Use `initial_places` instead. - * `MultipleStateMarkingStore` has been removed. - * `SingleStateMarkingStore` has been removed. + * `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead. + + Before: + ```yaml + framework: + workflows: + type: workflow + article: + marking_store: + type: multiple + arguments: states + ``` + + After: + ```yaml + framework: + workflows: + type: workflow + article: + marking_store: + property: states + ``` + * `SingleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead. + + Before: + ```yaml + framework: + workflows: + article: + marking_store: + arguments: state + ``` + + After: + ```yaml + framework: + workflows: + article: + marking_store: + property: state + ``` Yaml ---- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 698ef88e02..8a7062c4b6 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -233,7 +233,7 @@ class Configuration implements ConfigurationInterface $workflows = []; } - 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']))) { + 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']))) { $workflows = $workflows['workflows']; } @@ -258,9 +258,17 @@ class Configuration implements ConfigurationInterface ->arrayNode('workflows') ->useAttributeAsKey('name') ->prototype('array') + ->beforeNormalization() + ->always(function ($v) { + if (isset($v['initial_place'])) { + $v['initial_marking'] = [$v['initial_place']]; + } + + return $v; + }) + ->end() ->fixXmlConfig('support') ->fixXmlConfig('place') - ->fixXmlConfig('initial_place') ->fixXmlConfig('transition') ->children() ->arrayNode('audit_trail') @@ -274,9 +282,11 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('argument') ->children() ->enumNode('type') + ->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.') ->values(['multiple_state', 'single_state', 'method']) ->end() ->arrayNode('arguments') + ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.') ->beforeNormalization() ->ifString() ->then(function ($v) { return [$v]; }) @@ -285,6 +295,9 @@ class Configuration implements ConfigurationInterface ->prototype('scalar') ->end() ->end() + ->scalarNode('property') + ->defaultNull() + ->end() ->scalarNode('service') ->cannotBeEmpty() ->end() @@ -297,6 +310,10 @@ class Configuration implements ConfigurationInterface ->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); }) ->thenInvalid('"arguments" and "service" cannot be used together.') ->end() + ->validate() + ->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); }) + ->thenInvalid('"property" and "service" cannot be used together.') + ->end() ->end() ->arrayNode('supports') ->beforeNormalization() @@ -315,10 +332,10 @@ class Configuration implements ConfigurationInterface ->cannotBeEmpty() ->end() ->scalarNode('initial_place') - ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_places" configuration key instead.') + ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3, use the "initial_marking" configuration key instead.') ->defaultNull() ->end() - ->arrayNode('initial_places') + ->arrayNode('initial_marking') ->beforeNormalization() ->ifTrue(function ($v) { return !\is_array($v); }) ->then(function ($v) { return [$v]; }) diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index afca88af95..e10af2e178 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -631,14 +631,14 @@ class FrameworkExtension extends Extension // Create places $places = array_column($workflow['places'], 'name'); - $initialPlaces = $workflow['initial_places'] ?? $workflow['initial_place'] ?? []; + $initialMarking = $workflow['initial_marking'] ?? $workflow['initial_place'] ?? []; // Create a Definition $definitionDefinition = new Definition(Workflow\Definition::class); $definitionDefinition->setPublic(false); $definitionDefinition->addArgument($places); $definitionDefinition->addArgument($transitions); - $definitionDefinition->addArgument($initialPlaces); + $definitionDefinition->addArgument($initialMarking); $definitionDefinition->addArgument($metadataStoreDefinition); // Create MarkingStore @@ -647,6 +647,12 @@ class FrameworkExtension extends Extension foreach ($workflow['marking_store']['arguments'] as $argument) { $markingStoreDefinition->addArgument($argument); } + if ('method' === $workflow['marking_store']['type']) { + $markingStoreDefinition->setArguments([ + 'state_machine' === $type, //single state + $workflow['marking_store']['property'] ?? 'marking', + ]); + } } elseif (isset($workflow['marking_store']['service'])) { $markingStoreDefinition = new Reference($workflow['marking_store']['service']); } @@ -686,7 +692,7 @@ class FrameworkExtension extends Extension ->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition { return $container->get((string) $ref); }, $transitions)) - ->setInitialPlace($initialPlaces) + ->setInitialPlace($initialMarking) ->build() ; $validator->validate($realDefinition, $name); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd index 5a807403a0..9d71b403dd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd @@ -279,7 +279,7 @@ - + @@ -289,6 +289,7 @@ + @@ -304,12 +305,14 @@ + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php index e7d8919315..729fe03f33 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php @@ -1,7 +1,5 @@ loadFromExtension('framework', [ 'workflows' => [ 'legacy' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_arguments_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_arguments_and_service.php similarity index 100% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_arguments_and_service.php rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_arguments_and_service.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_type_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php similarity index 94% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_type_and_service.php rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php index eca1e29c45..15189349bd 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_type_and_service.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_legacy_with_type_and_service.php @@ -6,7 +6,7 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'my_workflow' => [ 'marking_store' => [ - 'type' => 'multiple_state', + 'type' => 'method', 'service' => 'workflow_service', ], 'supports' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_guard_expression.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_guard_expression.php index 03b6a0b79b..2037b5f904 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_guard_expression.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_guard_expression.php @@ -6,13 +6,10 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'article' => [ 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'multiple_state', - ], 'supports' => [ FrameworkExtensionTest::class, ], - 'initial_places' => ['draft'], + 'initial_marking' => ['draft'], 'places' => [ 'draft', 'wait_for_journalist', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_multiple_transitions_with_same_name.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_multiple_transitions_with_same_name.php index 613a38c6c0..35a9df3730 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_multiple_transitions_with_same_name.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_multiple_transitions_with_same_name.php @@ -6,13 +6,10 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'article' => [ 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'multiple_state', - ], 'supports' => [ FrameworkExtensionTest::class, ], - 'initial_places' => ['draft'], + 'initial_marking' => ['draft'], 'places' => [ 'draft', 'wait_for_journalist', diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php new file mode 100644 index 0000000000..4129332d00 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php @@ -0,0 +1,32 @@ +loadFromExtension('framework', [ + 'workflows' => [ + 'my_workflow' => [ + 'type' => 'workflow', + 'marking_store' => [ + 'property' => 'states', + 'service' => 'workflow_service', + ], + 'supports' => [ + FrameworkExtensionTest::class, + ], + 'places' => [ + 'first', + 'last', + ], + 'transitions' => [ + 'go' => [ + 'from' => [ + 'first', + ], + 'to' => [ + 'last', + ], + ], + ], + ], + ], +]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_support_and_support_strategy.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_support_and_support_strategy.php index 4b38093a3d..063755b130 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_support_and_support_strategy.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_support_and_support_strategy.php @@ -5,9 +5,7 @@ use Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionT $container->loadFromExtension('framework', [ 'workflows' => [ 'my_workflow' => [ - 'marking_store' => [ - 'type' => 'multiple_state', - ], + 'type' => 'workflow', 'supports' => [ FrameworkExtensionTest::class, ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_without_support_and_support_strategy.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_without_support_and_support_strategy.php index dd2a92dc26..5eef5cc4d0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_without_support_and_support_strategy.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_without_support_and_support_strategy.php @@ -1,13 +1,9 @@ loadFromExtension('framework', [ 'workflows' => [ 'my_workflow' => [ - 'marking_store' => [ - 'type' => 'multiple_state', - ], + 'type' => 'workflow', 'places' => [ 'first', 'last', 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 17a0e1fa4a..7c7f7ed0b4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows.php @@ -6,13 +6,10 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'article' => [ 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'multiple_state', - ], 'supports' => [ FrameworkExtensionTest::class, ], - 'initial_places' => ['draft'], + 'initial_marking' => ['draft'], 'places' => [ 'draft', 'wait_for_journalist', @@ -41,13 +38,10 @@ $container->loadFromExtension('framework', [ ], ], 'pull_request' => [ - 'marking_store' => [ - 'type' => 'single_state', - ], 'supports' => [ FrameworkExtensionTest::class, ], - 'initial_places' => ['start'], + 'initial_marking' => 'start', 'metadata' => [ 'title' => 'workflow title', ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php index 1c8190bd09..e6f261f8f2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled.php @@ -6,7 +6,7 @@ $container->loadFromExtension('framework', [ 'foo' => [ 'type' => 'workflow', 'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'], - 'initial_places' => ['bar'], + 'initial_marking' => ['bar'], 'places' => ['bar', 'baz'], 'transitions' => [ 'bar_baz' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php index 6faae44f45..e4bc05a66f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflows_explicitly_enabled_named_workflows.php @@ -6,7 +6,7 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'type' => 'workflow', 'supports' => ['Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest'], - 'initial_places' => ['bar'], + 'initial_marking' => ['bar'], 'places' => ['bar', 'baz'], 'transitions' => [ 'bar_baz' => [ diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml index d1339d5f65..b59bd6c29f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml @@ -9,8 +9,8 @@ stdClass - - + + draft published diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_arguments_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_arguments_and_service.xml similarity index 100% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_arguments_and_service.xml rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_arguments_and_service.xml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_type_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml similarity index 91% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_type_and_service.xml rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml index 8b4bf305a8..e137f9b4b0 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_type_and_service.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_legacy_with_type_and_service.xml @@ -8,7 +8,7 @@ - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml index 32c33db5b8..e310c0d11d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml @@ -8,8 +8,8 @@ - draft - + draft + a a diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml index ffc316c99e..5cb7d75e88 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml @@ -8,7 +8,7 @@ - draft + draft a a diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml new file mode 100644 index 0000000000..2b2de8c368 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml @@ -0,0 +1,21 @@ + + + + + + + + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + + + + a + a + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_support_and_support_strategy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_support_and_support_strategy.xml index f3ff577b80..54a346ebda 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_support_and_support_strategy.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_support_and_support_strategy.xml @@ -7,8 +7,7 @@ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_without_support_and_support_strategy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_without_support_and_support_strategy.xml index 3529c50cee..c6ee7d77b5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_without_support_and_support_strategy.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_without_support_and_support_strategy.xml @@ -7,8 +7,7 @@ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - - + 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 da5cd4c758..e0340d5418 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml @@ -8,18 +8,18 @@ - draft + draft a a Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - - - - - - + + + + + + draft wait_for_journalist @@ -40,8 +40,8 @@ - - + + start Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml index b564c6ff76..bb544d8979 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled.xml @@ -6,8 +6,7 @@ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - - bar + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest bar baz diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml index b218480fe6..41fd29a1f2 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows_explicitly_enabled_named_workflows.xml @@ -7,7 +7,7 @@ - bar + bar Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest bar baz diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_arguments_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_arguments_and_service.yml similarity index 100% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_arguments_and_service.yml rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_arguments_and_service.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_type_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml similarity index 92% rename from src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_type_and_service.yml rename to src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml index 000ba10dfb..33ee68b1bc 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_type_and_service.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_legacy_with_type_and_service.yml @@ -2,7 +2,7 @@ framework: workflows: my_workflow: marking_store: - type: multiple_state + type: method service: workflow_service supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_guard_expression.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_guard_expression.yml index 433771601c..80a85a307b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_guard_expression.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_guard_expression.yml @@ -2,18 +2,16 @@ framework: workflows: article: type: workflow - marking_store: - type: multiple_state supports: - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - initial_places: [draft] + - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + initial_marking: [draft] places: - - draft - - wait_for_journalist - - approved_by_journalist - - wait_for_spellchecker - - approved_by_spellchecker - - published + - draft + - wait_for_journalist + - approved_by_journalist + - wait_for_spellchecker + - approved_by_spellchecker + - published transitions: request_review: from: [draft] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_multiple_transitions_with_same_name.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_multiple_transitions_with_same_name.yml index fee71c2645..12df7b79e7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_multiple_transitions_with_same_name.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_multiple_transitions_with_same_name.yml @@ -2,11 +2,9 @@ framework: workflows: article: type: workflow - marking_store: - type: multiple_state supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - initial_places: [draft] + initial_marking: [draft] places: - draft - wait_for_journalist diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml new file mode 100644 index 0000000000..520c689aac --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml @@ -0,0 +1,17 @@ +framework: + workflows: + my_workflow: + marking_store: + property: state + service: workflow_service + supports: + - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest + places: + - first + - last + transitions: + go: + from: + - first + to: + - last diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_support_and_support_strategy.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_support_and_support_strategy.yml index 743708485c..de0b36d8fa 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_support_and_support_strategy.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_support_and_support_strategy.yml @@ -1,8 +1,7 @@ framework: workflows: my_workflow: - marking_store: - type: multiple_state + type: workflow supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest support_strategy: foobar diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_without_support_and_support_strategy.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_without_support_and_support_strategy.yml index 6dc848d936..de74adbe59 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_without_support_and_support_strategy.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_without_support_and_support_strategy.yml @@ -1,8 +1,7 @@ framework: workflows: my_workflow: - marking_store: - type: multiple_state + type: workflow places: - 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 894d5dcde2..225106383d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows.yml @@ -2,11 +2,9 @@ framework: workflows: article: type: workflow - marking_store: - type: multiple_state supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - initial_places: [draft] + initial_marking: [draft] places: # simple format - draft @@ -29,11 +27,9 @@ framework: from: [approved_by_journalist, approved_by_spellchecker] to: [published] pull_request: - marking_store: - type: single_state supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - initial_places: [start] + initial_marking: start metadata: title: workflow title places: diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml index d154537470..bee231736b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled.yml @@ -6,7 +6,7 @@ framework: type: workflow supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - initial_places: [bar] + initial_marking: [bar] places: - bar - baz diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml index bb468254ac..c0462c9ab8 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflows_explicitly_enabled_named_workflows.yml @@ -5,7 +5,7 @@ framework: type: workflow supports: - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - initial_places: [bar] + initial_marking: [bar] places: - bar - baz diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 1b8a785a30..332ac8162d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -307,12 +307,23 @@ abstract class FrameworkExtensionTest extends TestCase } /** + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage "property" and "service" cannot be used together. + */ + public function testWorkflowCannotHaveBothPropertyAndService() + { + $this->createContainerFromFile('workflow_with_property_and_service'); + } + + /** + * @legacy + * * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "type" and "service" cannot be used together. */ public function testWorkflowCannotHaveBothTypeAndService() { - $this->createContainerFromFile('workflow_with_type_and_service'); + $this->createContainerFromFile('workflow_legacy_with_type_and_service'); } /** @@ -339,7 +350,7 @@ abstract class FrameworkExtensionTest extends TestCase */ public function testWorkflowCannotHaveBothArgumentsAndService() { - $this->createContainerFromFile('workflow_with_arguments_and_service'); + $this->createContainerFromFile('workflow_legacy_with_arguments_and_service'); } public function testWorkflowMultipleTransitionsWithSameName() From 87839cfaf94e3a6b426036b7ab63b80ef89a6fe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 6 Apr 2019 14:37:18 +0200 Subject: [PATCH 2/3] [Workflow] Finished integration of initial_marking + deprecated support for workflow + single state markin store --- .../DependencyInjection/Configuration.php | 15 ++-- .../FrameworkExtension.php | 14 ++-- .../Fixtures/php/workflow-legacy.php | 8 +- .../workflow_with_property_and_service.php | 32 -------- .../Fixtures/xml/workflow-legacy.xml | 5 +- .../xml/workflow_with_guard_expression.xml | 4 - ...th_multiple_transitions_with_same_name.xml | 4 - .../workflow_with_property_and_service.xml | 21 ------ .../Fixtures/xml/workflows.xml | 5 +- .../Fixtures/yml/workflow-legacy.yml | 6 +- .../workflow_with_property_and_service.yml | 17 ----- .../FrameworkExtensionTest.php | 25 +++---- .../PhpFrameworkExtensionTest.php | 73 +------------------ 13 files changed, 43 insertions(+), 186 deletions(-) delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml delete mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index 8a7062c4b6..a398054c5f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -282,8 +282,15 @@ class Configuration implements ConfigurationInterface ->fixXmlConfig('argument') ->children() ->enumNode('type') - ->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.') ->values(['multiple_state', 'single_state', 'method']) + ->validate() + ->ifTrue(function ($v) { return 'method' !== $v; }) + ->then(function ($v) { + @trigger_error('Passing something else than "method" has been deprecated in Symfony 4.3.', E_USER_DEPRECATED); + + return $v; + }) + ->end() ->end() ->arrayNode('arguments') ->setDeprecated('The "%path%.%node%" configuration key has been deprecated in Symfony 4.3. Use "property" instead.') @@ -296,7 +303,7 @@ class Configuration implements ConfigurationInterface ->end() ->end() ->scalarNode('property') - ->defaultNull() + ->defaultValue('marking') ->end() ->scalarNode('service') ->cannotBeEmpty() @@ -310,10 +317,6 @@ class Configuration implements ConfigurationInterface ->ifTrue(function ($v) { return !empty($v['arguments']) && isset($v['service']); }) ->thenInvalid('"arguments" and "service" cannot be used together.') ->end() - ->validate() - ->ifTrue(function ($v) { return !empty($v['property']) && isset($v['service']); }) - ->thenInvalid('"property" and "service" cannot be used together.') - ->end() ->end() ->arrayNode('supports') ->beforeNormalization() diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index e10af2e178..a4e33ba744 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -644,14 +644,15 @@ class FrameworkExtension extends Extension // Create MarkingStore if (isset($workflow['marking_store']['type'])) { $markingStoreDefinition = new ChildDefinition('workflow.marking_store.'.$workflow['marking_store']['type']); - foreach ($workflow['marking_store']['arguments'] as $argument) { - $markingStoreDefinition->addArgument($argument); - } if ('method' === $workflow['marking_store']['type']) { $markingStoreDefinition->setArguments([ 'state_machine' === $type, //single state - $workflow['marking_store']['property'] ?? 'marking', + $workflow['marking_store']['property'], ]); + } else { + foreach ($workflow['marking_store']['arguments'] as $argument) { + $markingStoreDefinition->addArgument($argument); + } } } elseif (isset($workflow['marking_store']['service'])) { $markingStoreDefinition = new Reference($workflow['marking_store']['service']); @@ -676,10 +677,6 @@ class FrameworkExtension extends Extension case 'state_machine' === $workflow['type']: $validator = new Workflow\Validator\StateMachineValidator(); break; - case 'method' === ($workflow['marking_store']['type'] ?? null): - $singlePlace = $workflow['marking_store']['arguments'][0] ?? false; - $validator = new Workflow\Validator\WorkflowValidator($singlePlace); - break; case 'single_state' === ($workflow['marking_store']['type'] ?? null): $validator = new Workflow\Validator\WorkflowValidator(true); break; @@ -687,6 +684,7 @@ class FrameworkExtension extends Extension $validator = new Workflow\Validator\WorkflowValidator(false); break; } + if ($validator) { $realDefinition = (new Workflow\DefinitionBuilder($places)) ->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition { diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php index 729fe03f33..cad94fc773 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow-legacy.php @@ -3,7 +3,13 @@ $container->loadFromExtension('framework', [ 'workflows' => [ 'legacy' => [ - 'type' => 'workflow', + 'type' => 'state_machine', + 'marking_store' => [ + 'type' => 'single_state', + 'arguments' => [ + 'state', + ], + ], 'supports' => [ stdClass::class, ], diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php deleted file mode 100644 index 4129332d00..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/workflow_with_property_and_service.php +++ /dev/null @@ -1,32 +0,0 @@ -loadFromExtension('framework', [ - 'workflows' => [ - 'my_workflow' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'property' => 'states', - 'service' => 'workflow_service', - ], - 'supports' => [ - FrameworkExtensionTest::class, - ], - 'places' => [ - 'first', - 'last', - ], - 'transitions' => [ - 'go' => [ - 'from' => [ - 'first', - ], - 'to' => [ - 'last', - ], - ], - ], - ], - ], -]); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml index b59bd6c29f..5a46d24d0d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow-legacy.xml @@ -7,7 +7,10 @@ http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + + + state + stdClass diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml index e310c0d11d..ffc12c4d0d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_guard_expression.xml @@ -9,10 +9,6 @@ draft - - a - a - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest draft wait_for_journalist diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml index 5cb7d75e88..db79f9323c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_multiple_transitions_with_same_name.xml @@ -9,10 +9,6 @@ draft - - a - a - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml deleted file mode 100644 index 2b2de8c368..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflow_with_property_and_service.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - - - - a - a - - - - 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 e0340d5418..0c6a638df4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/workflows.xml @@ -9,10 +9,7 @@ draft - - a - a - + Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml index 7ff70074d4..19f51dc9f4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow-legacy.yml @@ -1,7 +1,11 @@ framework: workflows: legacy: - type: workflow + type: state_machine + marking_store: + type: single_state + arguments: + - state initial_place: draft supports: - stdClass diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml deleted file mode 100644 index 520c689aac..0000000000 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/workflow_with_property_and_service.yml +++ /dev/null @@ -1,17 +0,0 @@ -framework: - workflows: - my_workflow: - marking_store: - property: state - service: workflow_service - supports: - - Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\FrameworkExtensionTest - places: - - first - - last - 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 332ac8162d..7085327e5c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -275,15 +275,18 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertGreaterThan(0, \count($registryDefinition->getMethodCalls())); } + /** + * @group legacy + */ public function testWorkflowLegacy() { $container = $this->createContainerFromFile('workflow-legacy'); - $this->assertTrue($container->hasDefinition('workflow.legacy'), 'Workflow is registered as a service'); - $this->assertSame('workflow.abstract', $container->getDefinition('workflow.legacy')->getParent()); - $this->assertTrue($container->hasDefinition('workflow.legacy.definition'), 'Workflow definition is registered as a service'); + $this->assertTrue($container->hasDefinition('state_machine.legacy'), 'Workflow is registered as a service'); + $this->assertSame('state_machine.abstract', $container->getDefinition('state_machine.legacy')->getParent()); + $this->assertTrue($container->hasDefinition('state_machine.legacy.definition'), 'Workflow definition is registered as a service'); - $workflowDefinition = $container->getDefinition('workflow.legacy.definition'); + $workflowDefinition = $container->getDefinition('state_machine.legacy.definition'); $this->assertSame(['draft'], $workflowDefinition->getArgument(2)); @@ -307,17 +310,6 @@ abstract class FrameworkExtensionTest extends TestCase } /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException - * @expectedExceptionMessage "property" and "service" cannot be used together. - */ - public function testWorkflowCannotHaveBothPropertyAndService() - { - $this->createContainerFromFile('workflow_with_property_and_service'); - } - - /** - * @legacy - * * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "type" and "service" cannot be used together. */ @@ -347,6 +339,7 @@ abstract class FrameworkExtensionTest extends TestCase /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @expectedExceptionMessage "arguments" and "service" cannot be used together. + * @group legacy */ public function testWorkflowCannotHaveBothArgumentsAndService() { @@ -423,7 +416,7 @@ abstract class FrameworkExtensionTest extends TestCase ], $container->getDefinition($transitions[4])->getArguments()); } - public function testGuardExpressions() + public function testWorkflowGuardExpressions() { $container = $this->createContainerFromFile('workflow_with_guard_expression'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index 19bad8e825..259ada2f39 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -89,78 +89,8 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest } /** - * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException - * @expectedExceptionMessage The marking store of workflow "article" can not store many places. But the transition "a_to_b" has too many output (2). Only one is accepted. + * @group legacy */ - public function testWorkflowValidationMethodSingle() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'method', - 'arguments' => [ - true, - ], - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b', 'c'], - ], - ], - ], - ], - ]); - }); - } - - public function testWorkflowValidationMethodNotSingle() - { - $this->createContainerFromClosure(function ($container) { - $container->loadFromExtension('framework', [ - 'workflows' => [ - 'article' => [ - 'type' => 'workflow', - 'marking_store' => [ - 'type' => 'method', - 'arguments' => [ - false, - ], - ], - 'supports' => [ - __CLASS__, - ], - 'places' => [ - 'a', - 'b', - 'c', - ], - 'transitions' => [ - 'a_to_b' => [ - 'from' => ['a'], - 'to' => ['b', 'c'], - ], - ], - ], - ], - ]); - }); - - // the test ensures that the validation does not fail (i.e. it does not throw any exceptions) - $this->addToAssertionCount(1); - } - public function testWorkflowValidationMultipleState() { $this->createContainerFromClosure(function ($container) { @@ -197,6 +127,7 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest /** * @expectedException \Symfony\Component\Workflow\Exception\InvalidDefinitionException * @expectedExceptionMessage The marking store of workflow "article" can not store many places. But the transition "a_to_b" has too many output (2). Only one is accepted. + * @group legacy */ public function testWorkflowValidationSingleState() { From 039353546f570ca14ceecde1b21ace42ccbcc28b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Sat, 6 Apr 2019 15:32:53 +0200 Subject: [PATCH 3/3] [Workflow] Deprecate worflow and single state marking --- UPGRADE-4.3.md | 23 +++++++++++++ UPGRADE-5.0.md | 21 ++++++++++++ .../DependencyInjection/Configuration.php | 10 ++++++ .../PhpFrameworkExtensionTest.php | 34 +++++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index aeb2b1181f..020f3a4018 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -237,6 +237,29 @@ Workflow property: state ``` + * Using a workflow with a single state marking is deprecated. Use a state machine instead. + + Before: + ```yaml + framework: + workflows: + article: + type: workflow + marking_store: + type: single_state + ``` + + After: + ```yaml + framework: + workflows: + article: + type: state_machine + marking_store: + # type: single_state # Since the single_state marking store is deprecated, use method instead + type: method + ``` + Yaml ---- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index 70bfdf3542..68001974bb 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -430,6 +430,27 @@ Workflow property: state ``` + + * Support for using a workflow with a single state marking is dropped. Use a state machine instead. + + Before: + ```yaml + framework: + workflows: + article: + type: workflow + marking_store: + type: single_state + ``` + + After: + ```yaml + framework: + workflows: + article: + type: state_machine + ``` + Yaml ---- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php index a398054c5f..f50c951a3e 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php @@ -474,6 +474,16 @@ class Configuration implements ConfigurationInterface }) ->thenInvalid('"supports" or "support_strategy" should be configured.') ->end() + ->validate() + ->ifTrue(function ($v) { + return 'workflow' === $v['type'] && 'single_state' === ($v['marking_store']['type'] ?? false); + }) + ->then(function ($v) { + @trigger_error('Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead.', E_USER_DEPRECATED); + + return $v; + }) + ->end() ->end() ->end() ->end() diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php index 259ada2f39..a67a358447 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/PhpFrameworkExtensionTest.php @@ -88,6 +88,40 @@ class PhpFrameworkExtensionTest extends FrameworkExtensionTest }); } + /** + * @group legacy + * @expectedDeprecation Using a workflow with type=workflow and a marking_store=single_state is deprecated since Symfony 4.3. Use type=state_machine instead. + */ + public function testWorkflowDeprecateWorkflowSingleState() + { + $this->createContainerFromClosure(function ($container) { + $container->loadFromExtension('framework', [ + 'workflows' => [ + 'article' => [ + 'type' => 'workflow', + 'marking_store' => [ + 'type' => 'single_state', + ], + 'supports' => [ + __CLASS__, + ], + 'places' => [ + 'a', + 'b', + 'c', + ], + 'transitions' => [ + 'a_to_b' => [ + 'from' => ['a'], + 'to' => ['b'], + ], + ], + ], + ], + ]); + }); + } + /** * @group legacy */