mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 10:33:49 +00:00
implementing workflow on tasks
This commit is contained in:
@@ -28,14 +28,56 @@ use Symfony\Component\Workflow\Workflow;
|
||||
*/
|
||||
class TaskWorkflowManager implements SupportStrategyInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var TaskWorkflowDefinition[]
|
||||
*/
|
||||
protected $definitions = array();
|
||||
|
||||
public function addDefinition(TaskWorkflowDefinition $definition) {
|
||||
$this->definitions[] = $definition;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param AbstractTask $task
|
||||
* @return TaskWorkflowDefinition
|
||||
* @throws \LogicException
|
||||
*/
|
||||
public function getTaskWorkflowDefinition(AbstractTask $task)
|
||||
{
|
||||
$definitions = array();
|
||||
|
||||
foreach($this->definitions as $tested) {
|
||||
if ($tested->supports($task)) {
|
||||
$definitions[] = $tested;
|
||||
}
|
||||
}
|
||||
|
||||
$count = count($definitions);
|
||||
if ($count > 1) {
|
||||
throw new \LogicException("More than one TaskWorkflowDefinition supports "
|
||||
. "this task. This should not happens.");
|
||||
} elseif ($count === 0) {
|
||||
throw new \LogicException("No taskWorkflowDefinition supports this task.");
|
||||
}
|
||||
|
||||
return $definitions[0];
|
||||
}
|
||||
|
||||
public function supports(Workflow $workflow, $subject): bool
|
||||
{
|
||||
if (!$subject instanceof AbstractTask) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dump($workflow->getName());
|
||||
|
||||
return $workflow->getName() === 'task_default';
|
||||
return $workflow->getName() === $this
|
||||
->getTaskWorkflowDefinition($subject)->getAssociatedWorkflowName();
|
||||
}
|
||||
|
||||
public function getWorkflowMetadata(AbstractTask $task, string $key, $metadataSubject = null, string $name = null)
|
||||
{
|
||||
return $this->getTaskWorkflowDefinition($task)
|
||||
->getWorkflowMetadata($key, $metadataSubject);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user