Skip to content

Commit 0c362d2

Browse files
committed
feature symfony#53866 [Workflow] determines places from transitions (lyrixx)
This PR was merged into the 7.1 branch. Discussion ---------- [Workflow] determines places from transitions | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix symfony#52378 | License | MIT Commits ------- ed30d81 [workflow] determines places form transitions
2 parents bc2d994 + ed30d81 commit 0c362d2

File tree

4 files changed

+9
-16
lines changed

4 files changed

+9
-16
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,6 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
484484
return array_values($places);
485485
})
486486
->end()
487-
->isRequired()
488-
->requiresAtLeastOneElement()
489487
->prototype('array')
490488
->children()
491489
->scalarNode('name')

src/Symfony/Component/Workflow/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add method `getEnabledTransition()` to `WorkflowInterface`
8+
* Automatically register places from transitions
89

910
7.0
1011
---

src/Symfony/Component/Workflow/Definition.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,15 @@ private function addPlace(string $place): void
104104

105105
private function addTransition(Transition $transition): void
106106
{
107-
$name = $transition->getName();
108-
109107
foreach ($transition->getFroms() as $from) {
110-
if (!isset($this->places[$from])) {
111-
throw new LogicException(sprintf('Place "%s" referenced in transition "%s" does not exist.', $from, $name));
108+
if (!\array_key_exists($from, $this->places)) {
109+
$this->addPlace($from);
112110
}
113111
}
114112

115113
foreach ($transition->getTos() as $to) {
116-
if (!isset($this->places[$to])) {
117-
throw new LogicException(sprintf('Place "%s" referenced in transition "%s" does not exist.', $to, $name));
114+
if (!\array_key_exists($to, $this->places)) {
115+
$this->addPlace($to);
118116
}
119117
}
120118

src/Symfony/Component/Workflow/Tests/DefinitionTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,15 @@ public function testAddTransitionAndFromPlaceIsNotDefined()
6666
{
6767
$places = range('a', 'b');
6868

69-
$this->expectException(LogicException::class);
70-
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');
71-
72-
new Definition($places, [new Transition('name', 'c', $places[1])]);
69+
$definition = new Definition($places, [new Transition('name', 'c', $places[1])]);
70+
$this->assertContains('c', $definition->getPlaces());
7371
}
7472

7573
public function testAddTransitionAndToPlaceIsNotDefined()
7674
{
7775
$places = range('a', 'b');
7876

79-
$this->expectException(LogicException::class);
80-
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');
81-
82-
new Definition($places, [new Transition('name', $places[0], 'c')]);
77+
$definition = new Definition($places, [new Transition('name', $places[0], 'c')]);
78+
$this->assertContains('c', $definition->getPlaces());
8379
}
8480
}

0 commit comments

Comments
 (0)