[Workflow] Added Registry::has()
to check if a workflow exists
This commit is contained in:
parent
7719fc709e
commit
8a4f03dee8
@ -5,6 +5,7 @@ CHANGELOG
|
|||||||
-----
|
-----
|
||||||
|
|
||||||
* Added context to `TransitionException` and its child classes whenever they are thrown in `Workflow::apply()`
|
* 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
|
5.0.0
|
||||||
-----
|
-----
|
||||||
|
@ -27,6 +27,17 @@ class Registry
|
|||||||
$this->workflows[] = [$workflow, $supportStrategy];
|
$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
|
* @return Workflow
|
||||||
*/
|
*/
|
||||||
|
@ -28,6 +28,16 @@ class RegistryTest extends TestCase
|
|||||||
$this->registry = null;
|
$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()
|
public function testGetWithSuccess()
|
||||||
{
|
{
|
||||||
$workflow = $this->registry->get(new Subject1());
|
$workflow = $this->registry->get(new Subject1());
|
||||||
|
Reference in New Issue
Block a user