8000 [Workflow] Deprecated DefinitionBuilder::setInitialPlace() by lyrixx · Pull Request #32258 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Workflow] Deprecated DefinitionBuilder::setInitialPlace() #32258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-4.3.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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