diff --git a/src/Symfony/Component/Workflow/Registry.php b/src/Symfony/Component/Workflow/Registry.php index 4bc806d200ba0..17a2b7197fd34 100644 --- a/src/Symfony/Component/Workflow/Registry.php +++ b/src/Symfony/Component/Workflow/Registry.php @@ -64,6 +64,23 @@ public function get($subject, $workflowName = null) return $matched; } + /** + * @param object $subject + * + * @return Workflow[] + */ + public function all($subject): array + { + $matched = array(); + foreach ($this->workflows as list($workflow, $supportStrategy)) { + if ($supportStrategy->supports($workflow, $subject)) { + $matched[] = $workflow; + } + } + + return $matched; + } + private function supports(Workflow $workflow, $supportStrategy, $subject, $workflowName) { if (null !== $workflowName && $workflowName !== $workflow->getName()) { diff --git a/src/Symfony/Component/Workflow/Tests/RegistryTest.php b/src/Symfony/Component/Workflow/Tests/RegistryTest.php index 262e7cfe59ddf..8713153b2bf54 100644 --- a/src/Symfony/Component/Workflow/Tests/RegistryTest.php +++ b/src/Symfony/Component/Workflow/Tests/RegistryTest.php @@ -65,6 +65,33 @@ public function testGetWithNoMatch() $this->assertSame('workflow1', $w1->getName()); } + public function testAllWithOneMatchWithSuccess() + { + $workflows = $this->registry->all(new Subject1()); + $this->assertInternalType('array', $workflows); + $this->assertCount(1, $workflows); + $this->assertInstanceOf(Workflow::class, $workflows[0]); + $this->assertSame('workflow1', $workflows[0]->getName()); + } + + public function testAllWithMultipleMatchWithSuccess() + { + $workflows = $this->registry->all(new Subject2()); + $this->assertInternalType('array', $workflows); + $this->assertCount(2, $workflows); + $this->assertInstanceOf(Workflow::class, $workflows[0]); + $this->assertInstanceOf(Workflow::class, $workflows[1]); + $this->assertSame('workflow2', $workflows[0]->getName()); + $this->assertSame('workflow3', $workflows[1]->getName()); + } + + public function testAllWithNoMatch() + { + $workflows = $this->registry->all(new \stdClass()); + $this->assertInternalType('array', $workflows); + $this->assertCount(0, $workflows); + } + /** * @group legacy */ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy