8000 feature #34591 [Workflow] Added `Registry::has()` to check if a workf… · symfony/symfony@0a91f9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a91f9b

Browse files
committed
feature #34591 [Workflow] Added Registry::has() to check if a workflow exists (lyrixx)
This PR was merged into the 5.1-dev branch. Discussion ---------- [Workflow] Added `Registry::has()` to check if a workflow exists | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #34584 | License | MIT | Doc PR | --- Allow to use ```php $registry->has($subject); // or $registry->has($subject, 'workflow_a') ``` Commits ------- 8a4f03d [Workflow] Added `Registry::has()` to check if a workflow exists
2 parents 7466148 + 8a4f03d commit 0a91f9b

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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
* Added context to `TransitionException` and its child classes whenever they are thrown in `Workflow::apply()`
8+
* Added `Registry::has()` to check if a workflow exists
89

910
5.0.0
1011
-----

src/Symfony/Component/Workflow/Registry.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ public function addWorkflow(WorkflowInterface $workflow, WorkflowSupportStrategy
2727
$this->workflows[] = [$workflow, $supportStrategy];
2828
}
2929

30+
public function has(object $subject, string $workflowName = null): bool
31+
{
32+
foreach ($this->workflows as list($workflow, $supportStrategy)) {
33+
if ($this->supports($workflow, $supportStrategy, $subject, $workflowName)) {
34+
return true;
35+
}
36+
}
37+
38+
return false;
39+
}
40+
3041
/**
3142
* @return Workflow
3243
*/

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ protected function tearDown(): void
2828
$this->registry = null;
2929
}
3030

31+
public function testHasWithMatch()
32+
{
33+
$this->assertTrue($this->registry->has(new Subject1()));
34+
}
35+
36+
public function testHasWithoutMatch()
37+
{
38+
$this->assertFalse($this->registry->has(new Subject1(), 'nope'));
39+
}
40+
3141
public function testGetWithSuccess()
3242
{
3343
$workflow = $this->registry->get(new Subject1());

0 commit comments

Comments
 (0)
0