Создает экземпляр класса и проверяет то что созданный объект имплементирует заданный интерфейс

@param $className
@param $interface

@return mixed

@throws  Exception\WorkflowDispatchEventException
547251
protected function factoryClassName($className, $interface)
    {
        $r = new ReflectionClass($className);

        $instance = $r->newInstance();

        if (!$instance instanceof $interface) {
            $errMsg = sprintf('Class %s not implement %s', $className, $interface);
            throw new Exception\WorkflowDispatchEventException($errMsg);
        }

        return $instance;
    }
656524
protected function getMatchedQueue(
        /*# : string */ $eventName
    )/*# : EventQueueInterface */ {
        if ($this->hasEvent($eventName)) {
            return $this->events[$eventName];
        } else {
            return $this->newEventQueue();
        }
    }
154041
private function classGetter($className, $types)
    {
        if (!class_exists($className)) {
            return;
        }

        $obj = $this->get($className);

        foreach ($types as $type) {
            if ($obj instanceof $type) {
                return $obj;
            }
        }
    }
737556
public function isClassImplementationOf($className, $interfaceName)
    {
        $className = $this->prepareClassReflectionForUsage($className);

        $interfaceName = $this->cleanClassName($interfaceName);
        $this->loadOrReflectClassIfNecessary($interfaceName);

        return (isset($this->classReflectionData[$interfaceName][self::DATA_INTERFACE_IMPLEMENTATIONS][$className]));
    }
1095925
public function onCheckRunWorkflowHandler(WorkflowDispatchEventInterface $e)
    {
        $metadata = $e->getMetadata();
        if (!$metadata->getFlagHasConditions()) {
            return null;
        }

        try {
            $conditions = $metadata->getConditions();

            $validatorManager = $this->getValidatorManager();

            /** @var ValidatorChain $validatorChains */
            $validatorChains = $validatorManager->get(ValidatorChain::class);
        } catch (\Exception $e) {
            throw new Exception\PrepareDataException($e->getMessage(), $e->getCode(), $e);
        }



        $mvcEvent = $e->getMvcEvent();
        $controller = $mvcEvent->getTarget();
        if (!$controller instanceof AbstractController) {
            $controller = null;
        }


        foreach ($conditions as $condition) {
            try {
                $type = $condition->getType();
                $handler = $condition->getHandler();
                switch ($type) {
                    case 'method': {
                        if (null === $controller) {
                            $errMsg = 'Controller not specified';
                            throw new Exception\CheckRunWorkflowEventException($errMsg);
                        }
                        $callback = [$controller, $handler];

                        /** @var ValidatorInterface $callbackValidator */
                        $callbackValidator = $validatorManager->get('callback', $callback);

                        $validatorChains->attach($callbackValidator);

                        break;
                    }
                    case 'service': {
                        $validatorParams = $condition->getParams();

                        /** @var ValidatorInterface $validator */
                        $validator = $validatorManager->get($handler, $validatorParams);

                        $validatorChains->attach($validator);

                        break;
                    }
                    default: {
                        $errMsg = sprintf('Preparing data for Workflow will fail. Unknown handler type %s.', $type);
                        throw new Exception\PrepareDataException($errMsg);
                    }
                }
            } catch (\Exception $e) {
                throw new Exception\PrepareDataException($e->getMessage(), $e->getCode(), $e);
            }
        }

        return $validatorChains->isValid($e);
    }
832957
public function create(OrderEvent $event, $eventName, EventDispatcherInterface $dispatcher)
    {
        $session = $this->getSession();

        $order = $event->getOrder();
        $paymentModule = ModuleQuery::create()->findPk($order->getPaymentModuleId());

        $placedOrder = $this->createOrder(
            $dispatcher,
            $event->getOrder(),
            $session->getCurrency(),
            $session->getLang(),
            $session->getSessionCart($dispatcher),
            $this->securityContext->getCustomerUser()
        );

        $dispatcher->dispatch(TheliaEvents::ORDER_BEFORE_PAYMENT, new OrderEvent($placedOrder));

        /* but memorize placed order */
        $event->setOrder(new OrderModel());
        $event->setPlacedOrder($placedOrder);

        /* call pay method */
        $payEvent = new OrderPaymentEvent($placedOrder);

        $dispatcher->dispatch(TheliaEvents::MODULE_PAY, $payEvent);

        if ($payEvent->hasResponse()) {
            $event->setResponse($payEvent->getResponse());
        }
    }
253127
protected function getObjectByClass(/*# string */ $classname)
    {
        if ($this->getResolver()->hasService($classname)) {
            $serviceId = ObjectResolver::getServiceId($classname);
            return $this->getResolver()->get($serviceId);
        }
        throw new LogicException(
            Message::get(Message::DI_CLASS_UNKNOWN, $classname),
            Message::DI_CLASS_UNKNOWN
        );
    }
77846
public function loadMetadataForAction($controllerClassName, $actionMethod)
    {
        $key = $controllerClassName . '_' . $actionMethod;
        if (array_key_exists($key, $this->classAnnotations)) {
            return $this->classAnnotations[$key];
        }

        $r = new \ReflectionClass($controllerClassName);
        $rMethod = $r->getMethod($actionMethod);

        $metadata = new Metadata();


        /** @var Annotation\WorkflowDispatch|null $workflowDispatchAnnotation */
        $workflowDispatchAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\WorkflowDispatch::class);
        if (null !== $workflowDispatchAnnotation) {
            $metadata->setWorkflowDispatch($workflowDispatchAnnotation->enabled);
            $metadata->setWorkflowRunType($workflowDispatchAnnotation->activity);
        }

        /** @var Annotation\PrepareData|null $prepareDataAnnotation */
        $prepareDataAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\PrepareData::class);
        if ($prepareDataAnnotation) {
            $metadata->setFlagRunPrepareData($prepareDataAnnotation->enabled);
            $metadata->setPrepareDataMethod($prepareDataAnnotation->type);
            $metadata->setPrepareDataHandler($prepareDataAnnotation->handler);
        }


        /** @var Annotation\DispatchConditions|null $dispatchConditionsAnnotation */
        $dispatchConditionsAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\DispatchConditions::class);
        if ($dispatchConditionsAnnotation && is_array($dispatchConditionsAnnotation->conditions) && count($dispatchConditionsAnnotation->conditions) > 0) {
            $metadata->setFlagHasConditions(true);
            foreach ($dispatchConditionsAnnotation->conditions as $condition) {
                if (!$condition instanceof Condition) {
                    $errMsg = 'Invalid condition annotation';
                    throw new Exception\AnnotationReaderException($errMsg);
                }
                $conditionMetadata = new DispatchConditionMetadata($condition->type, $condition->handler, $condition->params);

                $metadata->addConditions($conditionMetadata);
            }
        }
//
//        /** @var Annotation\WorkflowRouterMap|null $workflowRouterMapAnnotation */
//        $workflowRouterMapAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\WorkflowRouterMap::class);
//        if ($workflowRouterMapAnnotation) {
//            $metadata->setWorkflowManagerNameRouterParam($workflowRouterMapAnnotation->managerName);
//            $metadata->setWorkflowActionNameRouterParam($workflowRouterMapAnnotation->actionName);
//            $metadata->setWorkflowNameRouterParam($workflowRouterMapAnnotation->name);
//            $metadata->setEntryIdRouterParam($workflowRouterMapAnnotation->entryId);
//        }
//
//        $metadata->validate();

        return $metadata;
    }
95167
public function getRunWorkflowParam()
    {
        if (null === $this->runWorkflowParam) {
            $errMsg = 'runWorkflowParam not found';
            throw new Exception\WorkflowDispatchEventException($errMsg);
        }
        return $this->runWorkflowParam;
    }
507040
public function getMetadata()
    {
        if (null === $this->metadata) {
            $errMsg = 'metadata not found';
            throw new Exception\WorkflowDispatchEventException($errMsg);
        }

        return $this->metadata;
    }
258845
public function getCondition($type, array $args = [])
    {
        $className = null;
        if (array_key_exists($type, $this->conditions)) {
            $className = $this->conditions[$type];
        } elseif (array_key_exists(static::CLASS_NAME, $args)) {
            $className = $args[static::CLASS_NAME];
        }

        if (null === $className) {
            $type = (string)$type;
            $errMsg = sprintf(
                'Нет типа(%s) или аргумента class.name',
                $type
            );
            throw new WorkflowException($errMsg);
        }

        if (!class_exists($className)) {
            $errMsg = sprintf(
                'Отсутствует класс %s',
                $className
            );
            throw new WorkflowException($errMsg);
        }

        $condition = new $className();


        if (!$condition instanceof ConditionInterface) {
            $errMsg = sprintf(
                'Condition должен реализовывать интерфейс %s',
                ConditionInterface::class
            );
            throw new WorkflowException($errMsg);
        }

        return $condition;
    }
427410
private function doDetectByInterfaces($className)
    {
        $interfaces = $this->getOrderedInterfaces($className);
        foreach ($interfaces as $interface) {
            $candidate = $this->doDetectByRoutes($interface);
            if ($candidate) {
                return $candidate;
            }
        }

        return;
    }
331634
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        /** @var Dispatcher $dispatcher */
        $dispatcher = $serviceLocator->get(Dispatcher::class);

        $options = [
            'dispatcher' => $dispatcher
        ];

        return new WorkflowDispatchListener($options);
    }
349907
public function handlerIdByClassName($className)
    {
        foreach ($this->handlers() as $id => $class) {
            if ($class->className() === $className) {
                return $id;
            }
        }

        throw new Exception("Handler with classname {$className} not found.");
    }
524942
protected function getCoreInstance($className)
    {
        $className = self::prepareClassName($className);

        switch ($className) {
            case '\\Zepi\\Turbo\\Backend\\VirtualModuleBackend':
                $path = $this->rootDirectory . '/data/modules.data';
                return new \Zepi\Turbo\Backend\FileObjectBackend($path);
                break;
            case '\\Zepi\\Turbo\\Backend\\VirtualHandlerBackend':
                $path = $this->rootDirectory . '/data/handlers.data';
                return new \Zepi\Turbo\Backend\FileObjectBackend($path);
                break;
            case '\\Zepi\\Turbo\\Backend\\VirtualRouteBackend':
                $path = $this->rootDirectory . '/data/routes.data';
                return new \Zepi\Turbo\Backend\FileObjectBackend($path);
                break;
            case '\\Zepi\\Turbo\\Backend\\VirtualDataSourceBackend':
                $path = $this->rootDirectory . '/data/data-sources.data';
                return new \Zepi\Turbo\Backend\FileObjectBackend($path);
                break;
            default:
                if (class_exists($className, true)) {
                    return new $className();
                } else {
                    throw new Exception('Class "' . $className . '" is not defined.');
                }
                break;
        }
    }
620698
public function getImplementorMap($interface, $baseClass = null)
    {
        // Create Map Array:
        
        $map = [];
        
        // Define Base Class (if none given):
        
        if (!$baseClass) {
            $baseClass = SiteTree::class;
        }
        
        // Obtain Implementors:
        
        if ($implementors = ClassInfo::implementorsOf($interface)) {
            
            // Filter Implementors:
            
            $records = $baseClass::get()->filter([
                'ClassName' => $implementors
            ])->sort('ClassName');
            
            // Define Map Array:
            
            foreach ($records as $record) {
                $map[$record->ID] = sprintf(
                    '%s (%s)',
                    $record->hasMethod('NestedTitle') ? $record->NestedTitle(5, ' > ') : $record->Title,
                    $record->i18n_singular_name()
                );
            }
            
        }
        
        // Answer Map Array:
        
        return $map;
    }
854640
public function createEntry($workflowName)
    {
        $id = static::$globalEntryId++;
        $entry = new SimpleWorkflowEntry($id, $workflowName, WorkflowEntryInterface::CREATED);
        static::$entryCache[$id] = $entry;

        return $entry;
    }