Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Workflow] determines places from transitions #53866

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
Feb 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,6 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
return array_values($places);
})
->end()
->isRequired()
->requiresAtLeastOneElement()
->prototype('array')
->children()
->scalarNode('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 @@ -5,6 +5,7 @@ CHANGELOG
---

* Add method `getEnabledTransition()` to `WorkflowInterface`
* Automatically register places from transitions

7.0
---
Expand Down
10 changes: 4 additions & 6 deletions src/Symfony/Component/Workflow/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,15 @@ private function addPlace(string $place): void

private function addTransition(Transition $transition): void
{
$name = $transition->getName();

foreach ($transition->getFroms() as $from) {
if (!isset($this->places[$from])) {
throw new LogicException(sprintf('Place "%s" referenced in transition "%s" does not exist.', $from, $name));
if (!\array_key_exists($from, $this->places)) {
$this->addPlace($from);
}
}

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

Expand Down
12 changes: 4 additions & 8 deletions src/Symfony/Component/Workflow/Tests/DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,15 @@ public function testAddTransitionAndFromPlaceIsNotDefined()
{
$places = range('a', 'b');

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');

new Definition($places, [new Transition('name', 'c', $places[1])]);
$definition = new Definition($places, [new Transition('name', 'c', $places[1])]);
$this->assertContains('c', $definition->getPlaces());
}

public function testAddTransitionAndToPlaceIsNotDefined()
{
$places = range('a', 'b');

$this->expectException(LogicException::class);
$this->expectExceptionMessage('Place "c" referenced in transition "name" does not exist.');

new Definition($places, [new Transition('name', $places[0], 'c')]);
$definition = new Definition($places, [new Transition('name', $places[0], 'c')]);
$this->assertContains('c', $definition->getPlaces());
}
}