Skip to content

Commit

Permalink
minor #32258 [Workflow] Deprecated DefinitionBuilder::setInitialPlace…
Browse files Browse the repository at this point in the history
…() (lyrixx)

This PR was merged into the 4.3 branch.

Discussion
----------

[Workflow] Deprecated DefinitionBuilder::setInitialPlace()

Added missing part of #30468

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

Commits
-------

4d002e8 [Workflow] Deprecated DefinitionBuilder::setInitialPlace()
  • Loading branch information
lyrixx committed Jun 28, 2019
2 parents a218efe + 4d002e8 commit 0d5258a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 16 deletions.
2 changes: 2 additions & 0 deletions UPGRADE-4.3.md
Expand Up @@ -297,6 +297,8 @@ Workflow
type: method
```

* Using `DefinitionBuilder::setInitialPlace()` is deprecated, use `DefinitionBuilder::setInitialPlaces()` instead.

Yaml
----

Expand Down
5 changes: 3 additions & 2 deletions UPGRADE-5.0.md
Expand Up @@ -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/<BundleName>/views/`, use `templates/` and `templates/bundles/<BundleName>/` 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

Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Workflow/CHANGELOG.md
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Workflow/Definition.php
Expand Up @@ -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;
Expand Down
26 changes: 21 additions & 5 deletions src/Symfony/Component/Workflow/DefinitionBuilder.php
Expand Up @@ -24,7 +24,7 @@ class DefinitionBuilder
{
private $places = [];
private $transitions = [];
private $initialPlace;
private $initialPlaces;
private $metadataStore;

/**
Expand All @@ -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);
}

/**
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Workflow/Tests/DefinitionBuilderTest.php
Expand Up @@ -9,6 +9,7 @@

class DefinitionBuilderTest extends TestCase
{
/** @group legacy */
public function testSetInitialPlace()
{
$builder = new DefinitionBuilder(['a', 'b']);
Expand All @@ -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');
Expand Down

0 comments on commit 0d5258a

Please sign in to comment.