From 4d002e839741f1ed31e5126c3beb25658880dc48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 28 Jun 2019 15:01:48 +0200 Subject: [PATCH] [Workflow] Deprecated DefinitionBuilder::setInitialPlace() Added missing part of #30468 --- UPGRADE-4.3.md | 2 ++ UPGRADE-5.0.md | 5 ++-- .../FrameworkExtension.php | 11 +++----- src/Symfony/Component/Workflow/CHANGELOG.md | 1 + src/Symfony/Component/Workflow/Definition.php | 4 +-- .../Component/Workflow/DefinitionBuilder.php | 26 +++++++++++++++---- .../Workflow/Tests/DefinitionBuilderTest.php | 10 +++++++ 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/UPGRADE-4.3.md b/UPGRADE-4.3.md index 531a8e61b99b..7a6abcca8156 100644 --- a/UPGRADE-4.3.md +++ b/UPGRADE-4.3.md @@ -297,6 +297,8 @@ Workflow type: method ``` + * Using `DefinitionBuilder::setInitialPlace()` is deprecated, use `DefinitionBuilder::setInitialPlaces()` instead. + Yaml ---- diff --git a/UPGRADE-5.0.md b/UPGRADE-5.0.md index b75393100832..e16fb86c7985 100644 --- a/UPGRADE-5.0.md +++ b/UPGRADE-5.0.md @@ -385,11 +385,11 @@ TwigBundle * The default value (`false`) of the `twig.strict_variables` configuration option has been changed to `%kernel.debug%`. * The `transchoice` tag and filter have been removed, use the `trans` ones instead with a `%count%` parameter. * Removed support for legacy templates directories `src/Resources/views/` and `src/Resources//views/`, use `templates/` and `templates/bundles//` instead. - + TwigBridge ---------- - * removed the `$requestStack` and `$requestContext` arguments of the + * removed the `$requestStack` and `$requestContext` arguments of the `HttpFoundationExtension`, pass a `Symfony\Component\HttpFoundation\UrlHelper` instance as the only argument instead @@ -417,6 +417,7 @@ Workflow * `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`. * Removed support of `initial_place`. Use `initial_places` instead. * `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead. + * `DefinitionBuilder::setInitialPlace()` has been removed, use `DefinitionBuilder::setInitialPlaces()` instead. Before: ```yaml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index fdff97bfcd42..b5bb52a17f13 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -706,13 +706,10 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $ } if ($validator) { - $realDefinition = (new Workflow\DefinitionBuilder($places)) - ->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition { - return $container->get((string) $ref); - }, $transitions)) - ->setInitialPlace($initialMarking) - ->build() - ; + $trs = array_map(function (Reference $ref) use ($container): Workflow\Transition { + return $container->get((string) $ref); + }, $transitions); + $realDefinition = new Workflow\Definition($places, $trs, $initialMarking); $validator->validate($realDefinition, $name); } diff --git a/src/Symfony/Component/Workflow/CHANGELOG.md b/src/Symfony/Component/Workflow/CHANGELOG.md index 5a32b915e50e..2d0870d34b7c 100644 --- a/src/Symfony/Component/Workflow/CHANGELOG.md +++ b/src/Symfony/Component/Workflow/CHANGELOG.md @@ -28,6 +28,7 @@ CHANGELOG * Dispatch `CompletedEvent` on `workflow.completed` * Dispatch `AnnounceEvent` on `workflow.announce` * Added support for many `initialPlaces` + * Deprecated `DefinitionBuilder::setInitialPlace()` method, use `DefinitionBuilder::setInitialPlaces()` instead. * Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead. * Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead. diff --git a/src/Symfony/Component/Workflow/Definition.php b/src/Symfony/Component/Workflow/Definition.php index 1ecbc0dfb56e..8a6e94206d49 100644 --- a/src/Symfony/Component/Workflow/Definition.php +++ b/src/Symfony/Component/Workflow/Definition.php @@ -48,13 +48,13 @@ public function __construct(array $places, array $transitions, $initialPlaces = } /** - * @deprecated since Symfony 4.3. Use the getInitialPlaces() instead. + * @deprecated since Symfony 4.3. Use getInitialPlaces() instead. * * @return string|null */ public function getInitialPlace() { - @trigger_error(sprintf('Calling %s::getInitialPlace() is deprecated. Call %s::getInitialPlaces() instead.', __CLASS__, __CLASS__)); + @trigger_error(sprintf('Calling %s::getInitialPlace() is deprecated since Symfony 4.3. Call getInitialPlaces() instead.', __CLASS__), E_USER_DEPRECATED); if (!$this->initialPlaces) { return null; diff --git a/src/Symfony/Component/Workflow/DefinitionBuilder.php b/src/Symfony/Component/Workflow/DefinitionBuilder.php index 8fa90471ddec..4bb6df4b0dc5 100644 --- a/src/Symfony/Component/Workflow/DefinitionBuilder.php +++ b/src/Symfony/Component/Workflow/DefinitionBuilder.php @@ -24,7 +24,7 @@ class DefinitionBuilder { private $places = []; private $transitions = []; - private $initialPlace; + private $initialPlaces; private $metadataStore; /** @@ -42,7 +42,7 @@ public function __construct(array $places = [], array $transitions = []) */ public function build() { - return new Definition($this->places, $this->transitions, $this->initialPlace, $this->metadataStore); + return new Definition($this->places, $this->transitions, $this->initialPlaces, $this->metadataStore); } /** @@ -54,20 +54,36 @@ public function clear() { $this->places = []; $this->transitions = []; - $this->initialPlace = null; + $this->initialPlaces = null; $this->metadataStore = null; return $this; } /** + * @deprecated since Symfony 4.3. Use setInitialPlaces() instead. + * * @param string $place * * @return $this */ public function setInitialPlace($place) { - $this->initialPlace = $place; + @trigger_error(sprintf('Calling %s::setInitialPlace() is deprecated since Symfony 4.3. Call setInitialPlaces() instead.', __CLASS__), E_USER_DEPRECATED); + + $this->initialPlaces = $place; + + return $this; + } + + /** + * @param string|string[]|null $initialPlaces + * + * @return $this + */ + public function setInitialPlaces($initialPlaces) + { + $this->initialPlaces = $initialPlaces; return $this; } @@ -80,7 +96,7 @@ public function setInitialPlace($place) public function addPlace($place) { if (!$this->places) { - $this->initialPlace = $place; + $this->initialPlaces = $place; } $this->places[$place] = $place; diff --git a/src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php b/src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php index 62351d7d9218..df8d9bb8b36b 100644 --- a/src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php +++ b/src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php @@ -9,6 +9,7 @@ class DefinitionBuilderTest extends TestCase { + /** @group legacy */ public function testSetInitialPlace() { $builder = new DefinitionBuilder(['a', 'b']); @@ -18,6 +19,15 @@ public function testSetInitialPlace() $this->assertEquals(['b'], $definition->getInitialPlaces()); } + public function testSetInitialPlaces() + { + $builder = new DefinitionBuilder(['a', 'b']); + $builder->setInitialPlaces('b'); + $definition = $builder->build(); + + $this->assertEquals(['b'], $definition->getInitialPlaces()); + } + public function testAddTransition() { $places = range('a', 'b');