Skip to content

Commit

Permalink
feature #34591 [Workflow] Added Registry::has() to check if a workf…
Browse files Browse the repository at this point in the history
…low 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
  • Loading branch information
lyrixx committed Nov 29, 2019
2 parents 7466148 + 8a4f03d commit 0a91f9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
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
-----

* Added context to `TransitionException` and its child classes whenever they are thrown in `Workflow::apply()`
* Added `Registry::has()` to check if a workflow exists

5.0.0
-----
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Workflow/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ public function addWorkflow(WorkflowInterface $workflow, WorkflowSupportStrategy
$this->workflows[] = [$workflow, $supportStrategy];
}

public function has(object $subject, string $workflowName = null): bool
{
foreach ($this->workflows as list($workflow, $supportStrategy)) {
if ($this->supports($workflow, $supportStrategy, $subject, $workflowName)) {
return true;
}
}

return false;
}

/**
* @return Workflow
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Workflow/Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ protected function tearDown(): void
$this->registry = null;
}

public function testHasWithMatch()
{
$this->assertTrue($this->registry->has(new Subject1()));
}

public function testHasWithoutMatch()
{
$this->assertFalse($this->registry->has(new Subject1(), 'nope'));
}

public function testGetWithSuccess()
{
$workflow = $this->registry->get(new Subject1());
Expand Down

0 comments on commit 0a91f9b

Please sign in to comment.