[Workflow] Deprecated DefinitionBuilder::setInitialPlace()

Added missing part of #30468
This commit is contained in:
Grégoire Pineau 2019-06-28 15:01:48 +02:00
parent a218efebee
commit 4d002e8397
7 changed files with 43 additions and 16 deletions

View File

@ -297,6 +297,8 @@ Workflow
type: method type: method
``` ```
* Using `DefinitionBuilder::setInitialPlace()` is deprecated, use `DefinitionBuilder::setInitialPlaces()` instead.
Yaml Yaml
---- ----

View File

@ -417,6 +417,7 @@ Workflow
* `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`. * `MarkingStoreInterface::setMarking()` has a third argument: `array $context = []`.
* Removed support of `initial_place`. Use `initial_places` instead. * Removed support of `initial_place`. Use `initial_places` instead.
* `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead. * `MultipleStateMarkingStore` has been removed. Use `MethodMarkingStore` instead.
* `DefinitionBuilder::setInitialPlace()` has been removed, use `DefinitionBuilder::setInitialPlaces()` instead.
Before: Before:
```yaml ```yaml

View File

@ -706,13 +706,10 @@ class FrameworkExtension extends Extension
} }
if ($validator) { if ($validator) {
$realDefinition = (new Workflow\DefinitionBuilder($places)) $trs = array_map(function (Reference $ref) use ($container): Workflow\Transition {
->addTransitions(array_map(function (Reference $ref) use ($container): Workflow\Transition {
return $container->get((string) $ref); return $container->get((string) $ref);
}, $transitions)) }, $transitions);
->setInitialPlace($initialMarking) $realDefinition = new Workflow\Definition($places, $trs, $initialMarking);
->build()
;
$validator->validate($realDefinition, $name); $validator->validate($realDefinition, $name);
} }

View File

@ -28,6 +28,7 @@ CHANGELOG
* Dispatch `CompletedEvent` on `workflow.completed` * Dispatch `CompletedEvent` on `workflow.completed`
* Dispatch `AnnounceEvent` on `workflow.announce` * Dispatch `AnnounceEvent` on `workflow.announce`
* Added support for many `initialPlaces` * Added support for many `initialPlaces`
* Deprecated `DefinitionBuilder::setInitialPlace()` method, use `DefinitionBuilder::setInitialPlaces()` instead.
* Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead. * Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead.
* Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead. * Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead.

View File

@ -48,13 +48,13 @@ final class Definition
} }
/** /**
* @deprecated since Symfony 4.3. Use the getInitialPlaces() instead. * @deprecated since Symfony 4.3. Use getInitialPlaces() instead.
* *
* @return string|null * @return string|null
*/ */
public function getInitialPlace() 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) { if (!$this->initialPlaces) {
return null; return null;

View File

@ -24,7 +24,7 @@ class DefinitionBuilder
{ {
private $places = []; private $places = [];
private $transitions = []; private $transitions = [];
private $initialPlace; private $initialPlaces;
private $metadataStore; private $metadataStore;
/** /**
@ -42,7 +42,7 @@ class DefinitionBuilder
*/ */
public function build() 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 @@ class DefinitionBuilder
{ {
$this->places = []; $this->places = [];
$this->transitions = []; $this->transitions = [];
$this->initialPlace = null; $this->initialPlaces = null;
$this->metadataStore = null; $this->metadataStore = null;
return $this; return $this;
} }
/** /**
* @deprecated since Symfony 4.3. Use setInitialPlaces() instead.
*
* @param string $place * @param string $place
* *
* @return $this * @return $this
*/ */
public function setInitialPlace($place) 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; return $this;
} }
@ -80,7 +96,7 @@ class DefinitionBuilder
public function addPlace($place) public function addPlace($place)
{ {
if (!$this->places) { if (!$this->places) {
$this->initialPlace = $place; $this->initialPlaces = $place;
} }
$this->places[$place] = $place; $this->places[$place] = $place;

View File

@ -9,6 +9,7 @@ use Symfony\Component\Workflow\Transition;
class DefinitionBuilderTest extends TestCase class DefinitionBuilderTest extends TestCase
{ {
/** @group legacy */
public function testSetInitialPlace() public function testSetInitialPlace()
{ {
$builder = new DefinitionBuilder(['a', 'b']); $builder = new DefinitionBuilder(['a', 'b']);
@ -18,6 +19,15 @@ class DefinitionBuilderTest extends TestCase
$this->assertEquals(['b'], $definition->getInitialPlaces()); $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() public function testAddTransition()
{ {
$places = range('a', 'b'); $places = range('a', 'b');