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

[Workflow][Registry] Added a new 'all' method (Symfony 3.4) #26659

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 17 additions & 0 deletions 17 src/Symfony/Component/Workflow/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
27 changes: 27 additions & 0 deletions 27 src/Symfony/Component/Workflow/Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.