implementing workflow on tasks

This commit is contained in:
2018-04-25 15:35:52 +02:00
parent 4fe9c4296e
commit c99583b665
13 changed files with 429 additions and 12 deletions

View File

@@ -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);
}
}