mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-01 20:43:49 +00:00
105 worflow
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Workflow;
|
||||
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
|
||||
class EntityWorkflowManager
|
||||
{
|
||||
/**
|
||||
* @var iterable|EntityWorkflowHandlerInterface[]
|
||||
*/
|
||||
private iterable $handlers;
|
||||
|
||||
private Registry $registry;
|
||||
|
||||
public function __construct(iterable $handlers, Registry $registry)
|
||||
{
|
||||
$this->handlers = $handlers;
|
||||
$this->registry = $registry;
|
||||
}
|
||||
|
||||
public function getHandler(EntityWorkflow $entityWorkflow, array $options = []): EntityWorkflowHandlerInterface
|
||||
{
|
||||
foreach ($this->handlers as $handler) {
|
||||
if ($handler->supports($entityWorkflow, $options)) {
|
||||
return $handler;
|
||||
}
|
||||
}
|
||||
|
||||
throw new HandlerNotFoundException();
|
||||
}
|
||||
|
||||
public function getSupportedWorkflows(EntityWorkflow $entityWorkflow): array
|
||||
{
|
||||
return $this->registry->all($entityWorkflow);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user