@param object      $subject
@param string|null $workflowName

@return Workflow
438025
public function get($subject, $workflowName = null)
    {
        $matched = null;

        foreach ($this->workflows as list($workflow, $supportStrategy)) {
            if ($this->supports($workflow, $supportStrategy, $subject, $workflowName)) {
                if ($matched) {
                    throw new InvalidArgumentException('At least two workflows match this subject. Set a different name on each and use the second (name) argument of this method.');
                }
                $matched = $workflow;
            }
        }

        if (!$matched) {
            throw new InvalidArgumentException(sprintf('Unable to find a workflow for class "%s".', \get_class($subject)));
        }

        return $matched;
    }
145856
public function canTransition($subject, $transitionName, $name = null)
    {
        return $this->workflowRegistry->get($subject, $name)->can($subject, $transitionName);
    }
675537
public function getWorkflow($workflow)
    {
        if (!isset($this->workflows[$workflow])) {
            $this->loadWorkflow($workflow);
        }

        return $this->workflows[$workflow];
    }
207464
public function getStatus($name)
    {
        foreach ($this->states as $status) {
            if ($status->getName() == $name) {
                return $status;
            }
        }
        throw new WorkflowException('No status found with the name ' . $name, 70, NULL);
    }
740636
public function hasWorkflowManager($workflowManagerName)
    {
        $workflowManagerServiceName = $this->getWorkflowManagerServiceName($workflowManagerName);

        return $this->getServiceLocator()->has($workflowManagerServiceName);
    }
549427
protected function call($eventName, $subject = null, $message = null)
    {
        if (!isset($this->events[$eventName])) {
            return $subject;
        }

        foreach ($this->events[$eventName] as $listener) {
            if ($this->stop) {
                break;
            }

            $subject = $listener($this->container, $subject, $message, $eventName);
        }

        return $subject;
    }
243402
public function getAvailableTransitions(Workflow $workflow, AbstractSubject $subject, array $metaData = null): Generator
    {
        if (!$workflow instanceof StateMachine) {
            throw new Exception(sprintf('Generator %s only support model type state machine', static::getName()));
        }

        $graph = $this->graphBuilder->build($workflow);
        $algorithm = new Bruteforce($graph);
        $edges = $algorithm->getEdges();
        $edges = $edges->getVector();
        while (!empty($edges)) {
            $edge = array_shift($edges);
            $transitionName = $edge->getAttribute('name');
            if ($workflow->can($subject, $transitionName)) {
                yield $transitionName;
            } else {
                break;
            }
        }
    }
1106963
static function runWorkflow( $workflowProcess )
    {
        $workflow = eZWorkflow::fetch( $workflowProcess->attribute( "workflow_id" ) );
        $workflowEvent = null;

        $workflowStatus = $workflowProcess->run( $workflow, $workflowEvent, $eventLog );

        $db = eZDB::instance();
        $db->begin();
        $workflowProcess->store();

        switch ( $workflowStatus )
        {
            case eZWorkflow::STATUS_FAILED:
            case eZWorkflow::STATUS_CANCELLED:
            case eZWorkflow::STATUS_NONE:
            case eZWorkflow::STATUS_BUSY:
            {
                $workflowProcess->removeThis();
                $db->commit();
                return array( 'Status' => eZTrigger::WORKFLOW_CANCELLED,
                              'Result' => null );
            } break;
            case eZWorkflow::STATUS_FETCH_TEMPLATE:
            case eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT:
            {
                $tpl = eZTemplate::factory();
                $result = array();
                foreach ( array_keys( $workflowProcess->Template['templateVars'] ) as $key )
                {
                    $value = $workflowProcess->Template['templateVars'][$key];
                    $tpl->setVariable( $key, $value );
                }
                $result['content'] = $tpl->fetch( $workflowProcess->Template['templateName'] );
                if ( isset( $workflowProcess->Template['path'] ) )
                    $result['path'] = $workflowProcess->Template['path'];

                    $db->commit();
                if ( $workflowStatus == eZWorkflow::STATUS_FETCH_TEMPLATE )
                {
                    $triggerStatus = eZTrigger::FETCH_TEMPLATE;
                }
                elseif ( $workflowStatus == eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT )
                {
                    $triggerStatus = eZTrigger::FETCH_TEMPLATE_REPEAT;
                }
                return array( 'Status' => $triggerStatus,
                              'WorkflowProcess' => $workflowProcess,
                              'Result' => $result );
            } break;
            case eZWorkflow::STATUS_REDIRECT:
            {
//                var_dump( $workflowProcess->RedirectUrl  );
                $db->commit();
                return array( 'Status' => eZTrigger::REDIRECT,
                              'WorkflowProcess' => $workflowProcess,
                              'Result' => $workflowProcess->RedirectUrl );

            } break;
            case eZWorkflow::STATUS_DEFERRED_TO_CRON:
            {

                $db->commit();
                return array( 'Status' => eZTrigger::STATUS_CRON_JOB,
                              'WorkflowProcess' => $workflowProcess,
                              'Result' => array( 'content' => 'Deffered to cron. Operation halted during execution. <br/>Refresh page to continue<br/><br/><b>Note: The halt is just a temporary test</b><br/>',
                                                 'path' => array( array( 'text' => 'Operation halt',
                                                                         'url' => false ) ) ) );
/*
                return array( 'Status' => eZTrigger::STATUS_CRON_JOB,
                              'Result' => $workflowProcess->attribute( 'id') );
*/
            } break;
            case eZWorkflow::STATUS_RESET:
            {
                $db->commit();
                return array( 'Status' => eZTrigger::WORKFLOW_RESET,
                              'WorkflowProcess' => $workflowProcess,
                              'Result' => array( 'content' => 'Workflow was reset',
                                                 'path' => array( array( 'text' => 'Operation halt',
                                                                         'url' => false ) ) ) );
            } break;
            case eZWorkflow::STATUS_DONE:
            {
                $workflowProcess->removeThis();
                $db->commit();
                return array( 'Status' => eZTrigger::WORKFLOW_DONE,
                              'Result' => null );
            }
        }

        $db->commit();
        return array( 'Status' => eZTrigger::WORKFLOW_CANCELLED,
                      'Result' => null );



    }
905379
public function subject($subject = null)
    {
        if ($subject !== null) {
            $this->_subject = $subject;

            return $this;
        }

        return $this->_subject;
    }
1004238
protected function loadWorkflow($workflowName)
    {
        $workflowFile = "{$this->workflowPath}/{$workflowName}.yml";
        if (!file_exists($workflowFile)) {
            throw new FileNotFoundException("The workflow configuration file {$workflowName}.yml doesn't exist.");
        }

        $yamlParser = new Parser();

        $workflowConfiguration = $yamlParser->parse(file_get_contents($workflowFile));
        $workflow = new Workflow($workflowName);

        foreach ($workflowConfiguration['tasks'] as $name => $serviceId)
        {
            $workflow->setTask($name, new Task($name, $serviceId));
        }

        $this->workflows[$workflowName] = $workflow;
    }
792570
public function closeSubjectAction(Subject $subject)
    {
        $forum = $subject->getCategory()->getForum();
        $this->checkAccess($forum);
        $this->manager->closeSubject($subject);

        return new RedirectResponse(
            $this->generateUrl('claro_forum_subjects', array('category' => $subject->getCategory()->getId()))
        );
    }
283373
public function applyTransition(Workflow $workflow, AbstractSubject $subject, string $transitionName): bool
    {
        try {
            $workflow->apply($subject, $transitionName);
        } catch (TransitionException $exception) {
            return false;
        }

        return true;
    }
713404
public function create($subjectOrName)
    {
        // Check if container or name is defined
        if (
            !$subjectOrName instanceof ContentSubjectInterface &&
            !(is_string($subjectOrName) && 0 < strlen($subjectOrName))
        ) {
            throw new InvalidOperationException("Excepted instance of ContentSubjectInterface or string.");
        }

        // New instance
        $content = $this->editor->getRepository()->createContent();

        // Create default container
        $this->editor->getContainerManager()->create($content);

        // Add to container if available
        if ($subjectOrName instanceof ContentSubjectInterface) {
            $subjectOrName->setContent($content);
        } else {
            $content->setName($subjectOrName);
        }

        return $content;
    }
685139
public function getOrCreateSubject($name)
    {
        if (isset($this->subjects[$name])) {
            return $this->subjects[$name];
        }

        $this->subjects[$name] = new SubjectMetadata($this, $name);

        return $this->subjects[$name];
    }
834842
public function defineFromTemplate(WorkflowDefinition $definition, $templateName)
    {
        $template = null;
        /* @var $template WorkflowTemplate */

        if (!is_array($this->templates)) {
            return;
        }

        $template = $this->getNamedTemplate($templateName);

        if (!$template) {
            return;
        }

        $template->createRelations($definition);

        // Set the version and do the write at the end so that we don't trigger an infinite loop!!
        if (!$definition->Description) {
            $definition->Description = $template->getDescription();
        }
        $definition->TemplateVersion = $template->getVersion();
        $definition->RemindDays = $template->getRemindDays();
        $definition->Sort = $template->getSort();
        $definition->write();
        return $definition;
    }
890727
public function transform($workflowTransition, array $params = array())
    {
        if (!$workflowTransition instanceof WorkflowTransitionInterface) {
            throw new TransformerParameterTypeException();
        }

        $facade = $this->newFacade();
        $facade->statusFrom = $this->getContext()->transform('status', $workflowTransition->getStatusFrom());
        $facade->statusTo = $this->getContext()->transform('status', $workflowTransition->getStatusTo());

        return $facade;
    }
109679
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $start = microtime(true);

        $this->getContainer()->get('ez_migration_bundle.step_executed_listener.tracing')->setOutput($output);

        $workflowService = $this->getWorkflowService();

        $workflowName = $input->getOption('workflow');
        if ($workflowName != null) {
            $suspendedWorkflow = $workflowService->getWorkflow($workflowName);
            if (!$suspendedWorkflow) {
                throw new \Exception("Workflow '$workflowName' not found");
            }
            if ($suspendedWorkflow->status != Migration::STATUS_SUSPENDED) {
                throw new \Exception("Workflow '$workflowName' is not suspended, can not resume it");
            }

            $suspendedWorkflows = array($suspendedWorkflow);
        } else {
            $suspendedWorkflows = $workflowService->getWorkflowsByStatus(Migration::STATUS_SUSPENDED);
        };

        $output->writeln('<info>Found ' . count($suspendedWorkflows) . ' suspended workflows</info>');

        if (!count($suspendedWorkflows)) {
            $output->writeln('Nothing to do');
            return;
        }

        // ask user for confirmation to make changes
        if ($input->isInteractive() && !$input->getOption('no-interaction')) {
            $dialog = $this->getHelperSet()->get('dialog');
            if (!$dialog->askConfirmation(
                $output,
                '<question>Careful, the database will be modified. Do you want to continue Y/N ?</question>',
                false
            )
            ) {
                $output->writeln('<error>Workflow resuming cancelled!</error>');
                return 0;
            }
        }

        $executed = 0;
        $failed = 0;

        foreach($suspendedWorkflows as $suspendedWorkflow) {
            $output->writeln("<info>Resuming {$suspendedWorkflow->name}</info>");

            try {
                $workflowService->resumeWorkflow($suspendedWorkflow, !$input->getOption('no-transactions'));
                $executed++;
            } catch (\Exception $e) {
                $output->writeln("\n<error>Workflow failed! Reason: " . $e->getMessage() . "</error>\n");
                $failed++;
            }
        }

        $time = microtime(true) - $start;
        $output->writeln("Resumed $executed workflows, failed $failed");
        $output->writeln("Time taken: ".sprintf('%.2f', $time)." secs, memory: ".sprintf('%.2f', (memory_get_peak_usage(true) / 1000000)). ' MB');

        if ($failed) {
            return 2;
        }
    }