Skip to content

Commit 98beaa7

Browse files
committed
[Workflow] Deprecated DefinitionBuilder::setInitialPlace()
Added missing part of #30468
1 parent b77526f commit 98beaa7

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ CHANGELOG
2828
* Dispatch `CompletedEvent` on `workflow.completed`
2929
* Dispatch `AnnounceEvent` on `workflow.announce`
3030
* Added support for many `initialPlaces`
31+
* Deprecated `DefinitionBuilder::setInitialPlace()` method, use `DefinitionBuilder::setInitialPlaces()` instead.
3132
* Deprecated the `MultipleStateMarkingStore` class, use the `MethodMarkingStore` instead.
3233
* Deprecated the `SingleStateMarkingStore` class, use the `MethodMarkingStore` instead.
3334

Definition.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public function __construct(array $places, array $transitions, $initialPlaces =
4848
}
4949

5050
/**
51-
* @deprecated since Symfony 4.3. Use the getInitialPlaces() instead.
51+
* @deprecated since Symfony 4.3. Use getInitialPlaces() instead.
5252
*
5353
* @return string|null
5454
*/
5555
public function getInitialPlace()
5656
{
57-
@trigger_error(sprintf('Calling %s::getInitialPlace() is deprecated. Call %s::getInitialPlaces() instead.', __CLASS__, __CLASS__));
57+
@trigger_error(sprintf('Calling %s::getInitialPlace() is deprecated since Symfony 4.3. Call getInitialPlaces() instead.', __CLASS__), E_USER_DEPRECATED);
5858

5959
if (!$this->initialPlaces) {
6060
return null;

DefinitionBuilder.php

+21-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DefinitionBuilder
2424
{
2525
private $places = [];
2626
private $transitions = [];
27-
private $initialPlace;
27+
private $initialPlaces;
2828
private $metadataStore;
2929

3030
/**
@@ -42,7 +42,7 @@ public function __construct(array $places = [], array $transitions = [])
4242
*/
4343
public function build()
4444
{
45-
return new Definition($this->places, $this->transitions, $this->initialPlace, $this->metadataStore);
45+
return new Definition($this->places, $this->transitions, $this->initialPlaces, $this->metadataStore);
4646
}
4747

4848
/**
@@ -54,20 +54,36 @@ public function clear()
5454
{
5555
$this->places = [];
5656
$this->transitions = [];
57-
$this->initialPlace = null;
57+
$this->initialPlaces = null;
5858
$this->metadataStore = null;
5959

6060
return $this;
6161
}
6262

6363
/**
64+
* @deprecated since Symfony 4.3. Use setInitialPlaces() instead.
65+
*
6466
* @param string $place
6567
*
6668
* @return $this
6769
*/
6870
public function setInitialPlace($place)
6971
{
70-
$this->initialPlace = $place;
72+
@trigger_error(sprintf('Calling %s::setInitialPlace() is deprecated since Symfony 4.3. Call setInitialPlaces() instead.', __CLASS__), E_USER_DEPRECATED);
73+
74+
$this->initialPlaces = $place;
75+
76+
return $this;
77+
}
78+
79+
/**
80+
* @param string|string[]|null $initialPlaces
81+
*
82+
* @return $this
83+
*/
84+
public function setInitialPlaces($initialPlaces)
85+
{
86+
$this->initialPlaces = $initialPlaces;
7187

7288
return $this;
7389
}
@@ -80,7 +96,7 @@ public function setInitialPlace($place)
8096
public function addPlace($place)
8197
{
8298
if (!$this->places) {
83-
$this->initialPlace = $place;
99+
$this->initialPlaces = $place;
84100
}
85101

86102
$this->places[$place] = $place;

Tests/DefinitionBuilderTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class DefinitionBuilderTest extends TestCase
1111
{
12+
/** @group legacy */
1213
public function testSetInitialPlace()
1314
{
1415
$builder = new DefinitionBuilder(['a', 'b']);
@@ -18,6 +19,15 @@ public function testSetInitialPlace()
1819
$this->assertEquals(['b'], $definition->getInitialPlaces());
1920
}
2021

22+
public function testSetInitialPlaces()
23+
{
24+
$builder = new DefinitionBuilder(['a', 'b']);
25+
$builder->setInitialPlaces('b');
26+
$definition = $builder->build();
27+
28+
$this->assertEquals(['b'], $definition->getInitialPlaces());
29+
}
30+
2131
public function testAddTransition()
2232
{
2333
$places = range('a', 'b');

0 commit comments

Comments
 (0)