Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit baec431

Browse filesBrowse files
alexpozzilyrixx
authored andcommitted
[Workflow][Registry] Added the 'all' method which returns all the workflows associated to a specific object #26618
1 parent 6e95c2a commit baec431
Copy full SHA for baec431

File tree

Expand file treeCollapse file tree

3 files changed

+45
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+45
-0
lines changed

‎src/Symfony/Component/Workflow/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Added TransitionBlockers as a way to pass around reasons why exactly
1212
transitions can't be made.
1313
* Added a `MetadataStore`.
14+
* Added Registry::all to return all the workflows associated with the specific subject
1415

1516
4.0.0
1617
-----

‎src/Symfony/Component/Workflow/Registry.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Registry.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ public function get($subject, $workflowName = null)
6666
return $matched;
6767
}
6868

69+
/**
70+
* @param object $subject
71+
*
72+
* @return Workflow[]
73+
*/
74+
public function all($subject): array
75+
{
76+
$matched = array();
77+
foreach ($this->workflows as list($workflow, $supportStrategy)) {
78+
if ($supportStrategy->supports($workflow, $subject)) {
79+
$matched[] = $workflow;
80+
}
81+
}
82+
83+
return $matched;
84+
}
85+
6986
private function supports(WorkflowInterface $workflow, $supportStrategy, $subject, $workflowName): bool
7087
{
7188
if (null !== $workflowName && $workflowName !== $workflow->getName()) {

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/RegistryTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ public function testGetWithNoMatch()
8181
$this->assertSame('workflow1', $w1->getName());
8282
}
8383

84+
public function testAllWithOneMatchWithSuccess()
85+
{
86+
$workflows = $this->registry->all(new Subject1());
87+
$this->assertInternalType('array', $workflows);
88+
$this->assertCount(1, $workflows);
89+
$this->assertInstanceOf(Workflow::class, $workflows[0]);
90+
$this->assertSame('workflow1', $workflows[0]->getName());
91+
}
92+
93+
public function testAllWithMultipleMatchWithSuccess()
94+
{
95+
$workflows = $this->registry->all(new Subject2());
96+
$this->assertInternalType('array', $workflows);
97+
$this->assertCount(2, $workflows);
98+
$this->assertInstanceOf(Workflow::class, $workflows[0]);
99+
$this->assertInstanceOf(Workflow::class, $workflows[1]);
100+
$this->assertSame('workflow2', $workflows[0]->getName());
101+
$this->assertSame('workflow3', $workflows[1]->getName());
102+
}
103+
104+
public function testAllWithNoMatch()
105+
{
106+
$workflows = $this->registry->all(new \stdClass());
107+
$this->assertInternalType('array', $workflows);
108+
$this->assertCount(0, $workflows);
109+
}
110+
84111
/**
85112
* @group legacy
86113
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.