Набор утилит для запуска сервисов workflow

@return ServiceUtilInterface

@throws Exception\RuntimeException
341499
public function getServiceUtil()
    {
        if ($this->serviceUtil) {
            return $this->serviceUtil;
        }

        $className = $this->getServiceUtilClassName();
        $r = new ReflectionClass($className);
        $instance = $r->newInstance();

        if (!$instance instanceof ServiceUtilInterface) {
            $errMsg = sprintf('Service util not implement %s', ServiceUtilInterface::class);
            throw new Exception\RuntimeException($errMsg);
        }
        $this->serviceUtil = $instance;

        return $this->serviceUtil;
    }
689951
public function send()
    {
        if (empty($this->message)) {
            throw new RuntimeException('No message to send.');
        }

        if ($this->message instanceof RawMessage) {
            $message = json_decode($this->message->get('content'), true);
        } else {
            $prepends = [
                'touser' => $this->to,
            ];
            if ($this->account) {
                $prepends['customservice'] = ['kf_account' => $this->account];
            }
            $message = $this->message->transformForJsonRequest($prepends);
        }

        return $this->client->send($message);
    }
319282
public function get()
    {
        $config = $this->getConfig();
        if (!isset($config['input'])) {
            throw new \RuntimeException('No input file provided.');
        }
        $path = $this->getProjectPath() . '/' . $config['input'];
        if (!is_readable($path)) {
            throw new \RuntimeException(sprintf('Input file "%s" not found.', $path));
        }
        return file_get_contents($path);
    }
86196
public function start()
    {
        $cmd = $this->command->getPreparedCommand();
        $cwd = realpath(CRAFT_BASE_PATH);

        $process = Process::fromShellCommandline($cmd, $cwd);

        try {
            $process->run();
        } catch (\Symfony\Component\Process\Exception\RuntimeException $e) {
            $e = new RuntimeException($e->getMessage());
            $e->setProcess($process);
            throw $e;
        } catch (\Symfony\Component\Process\Exception\LogicException $e) {
            $e = new LogicException($e->getMessage());
            $e->setProcess($process);
            throw $e;
        }

        return $process;
    }
1059025
public final function getResponse(): ResponseInterface
   {
       if (!$this->response) {
           try {
               $this->send();
           } catch (RuntimeException $e) {
               throw new RuntimeException(
                   "Can't get response: " . $e->getMessage());
           }
       }
       return $this->response;
   }
1171785
public function get()
    {
        $customer = null;
        $user = null;

        if (true === $this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
            // user is authenticated
            $user = $this->securityContext->getToken()->getUser();

            if (!$user instanceof UserInterface) {
                throw new \RuntimeException('User must be an instance of Symfony\Component\Security\Core\User\UserInterface');
            }

            $customer = $this->customerManager->findOneBy([
                'user' => $user->getId(),
            ]);
        }

        if (!$customer) {
            $basket = $this->getBasket();

            if ($basket && $basket->getCustomer()) {
                $customer = $basket->getCustomer();
            }
        }

        if (!$customer) {
            $customer = $this->customerManager->create();
        }

        if (!$customer->getLocale()) {
            $customer->setLocale($this->locale);
        }

        if ($user && $customer) {
            $customer->setUser($user);
        }

        return $customer;
    }
1125598
public function run()
    {
        $this->process->run();
        if (!$this->process->isSuccessful()) {
            throw new \RuntimeException($this->process->getErrorOutput());
        }

        return $this->process->getOutput();
    }
73929
protected function sourceFactory()
    {
        if (!isset($this->sourceFactory)) {
            throw new RuntimeException(
                sprintf('Source factory is not set for "%s"', get_class($this))
            );
        }
        return $this->sourceFactory;
    }
511228
public function getRuntimeConfigurableWrapper()
    {
        if ($this->wrapper === null) {
            $this->wrapper = new RuntimeConfigurable($this, $this->getTaskName());
        }

        return $this->wrapper;
    }
1039827
public function build()
    {
        if (is_null($this->selectFields)) {
            throw new RuntimeException('The `select()` function must be' .
                ' called prior to this function');
        }

        $awql = $this->buildSelectClause();
        $awql = $this->appendWhereClause($awql);
        $awql = $this->appendOrderByClause($awql);

        if (is_null($this->startIndex) && is_null($this->pageSize)) {
            return new ServiceQuery($awql);
        }
        return new ServiceQuery(
            $awql,
            $this->startIndex,
            $this->pageSize
        );
    }
2067
private function validateServicesDefined() {
        if(!$this->getDi()->has(AclInterface::DI_NAME)) {
            throw new \Exception('Service ' . AclInterface::class . '::DI_NAME must be defined with a type of: ' . AclInterface::class);
        }
        if(!$this->getDi()->has(OutputInterface::DI_NAME)) {
            throw new \Exception('Service ' . OutputInterface::class . '::DI_NAME must be defined with a type of: ' . OutputInterface::class);
        }
    }
112312
public function createService(ServiceLocatorInterface $serviceLocator)
    {

        $pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
        $plugins = new $pluginManagerClass;
        $plugins->setServiceLocator($serviceLocator);
        $configuration    = $serviceLocator->get('Config');

        if (isset($configuration['di']) && $serviceLocator->has('Di')) {
            $di = $serviceLocator->get('Di');
            $plugins->addAbstractFactory(
                new DiAbstractServiceFactory($di, DiAbstractServiceFactory::USE_SL_BEFORE_DI)
            );
        }

        foreach ($this->defaultHelperMapClasses as $configClass) {
            if (is_string($configClass) && class_exists($configClass)) {
                $config = new $configClass;
            }

            if (!$config instanceof ConfigInterface) {
                throw new Exception\RuntimeException(sprintf(
                    'Invalid service manager configuration class provided; received "%s", expected class implementing %s',
                    $configClass,
                    'Zend\ServiceManager\ConfigInterface'
                ));
            }

            $config->configureServiceManager($plugins);
        }

        // Configure URL view helper with router
        $plugins->setFactory('url', function($sm) use($serviceLocator) {
            $helper = new ViewHelper\Url;
            $helper->setRouter($serviceLocator->get('Router'));

            $match = $serviceLocator->get('application')
                ->getMvcEvent()
                ->getRouteMatch();

            if ($match instanceof RouteMatch) {

                $helper->setRouteMatch($match);
            }

            return $helper;
        });

        $plugins->setFactory('basepath', function($sm) use($serviceLocator) {
            $config = $serviceLocator->get('Config');
            $config = $config['view_manager'];
            $basePathHelper = new ViewHelper\BasePath;
            if (isset($config['base_path'])) {
                $basePath = $config['base_path'];
            } else {
                $basePath = $serviceLocator->get('Request')->getBasePath();
            }
            $basePathHelper->setBasePath($basePath);
            return $basePathHelper;
        });

        /**
         * Configure doctype view helper with doctype from configuration, if available.
         *
         * Other view helpers depend on this to decide which spec to generate their tags
         * based on. This is why it must be set early instead of later in the layout phtml.
         */
        $plugins->setFactory('doctype', function($sm) use($serviceLocator) {
            $config = $serviceLocator->get('Config');
            $config = $config['view_manager'];
            $doctypeHelper = new ViewHelper\Doctype;
            if (isset($config['doctype'])) {
                $doctypeHelper->setDoctype($config['doctype']);
            }
            return $doctypeHelper;
        });

        return $plugins;
    }
1286645
public function create()
    {
        if ($this->getIsNewRecord() == false) {
            throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
        }

        $transaction = $this->getDb()->beginTransaction();

        try {
            $this->password = ($this->password == null && $this->module->enableGeneratingPassword) ? Password::generate(8) : $this->password;

            $this->trigger(self::BEFORE_CREATE);

            if (!$this->save()) {
                $transaction->rollBack();
                return false;
            }

            $this->confirm();

            $this->mailer->sendWelcomeMessage($this, null, true);
            $this->trigger(self::AFTER_CREATE);

            $transaction->commit();

            return true;
        } catch (\Exception $e) {
            $transaction->rollBack();
            \Yii::warning($e->getMessage());
            throw $e;
        }
    }
928057
public function eventFactory()
    {
        if (null !== $this->eventPrototype) {
            return clone $this->eventPrototype;
        }

        try {
            /** @var ModuleOptions $moduleOptions */
            $moduleOptions = $this->get(ModuleOptions::class);

            $moduleOptionsEventClassName = $moduleOptions->getModuleOptionsEventClassName();
            $r = new ReflectionClass($moduleOptionsEventClassName);

            $eventPrototype = $r->newInstance();
            if (!$eventPrototype instanceof EventInterface) {
                $errMsg = sprintf(
                    'Event of type %s is invalid; must implement %s',
                    (is_object($eventPrototype) ? get_class($eventPrototype) : gettype($eventPrototype)),
                    ModuleOptionsEventInterface::class
                );
                throw new Exception\RuntimeException($errMsg);
            }
            $this->eventPrototype = $eventPrototype;
        } catch (\Exception $e) {
            throw new Exception\InvalidEventException($e->getMessage(), $e->getCode(), $e);
        }

        return clone $this->eventPrototype;
    }
631252
protected function doExecute()
    {
        if ($this->console->getMode() !== 'dev') {
            throw new \RuntimeException(
                '<error>STOP!</error> please run <info>' . $this->getEnvCmd() . '</info>.'
            );
        }

        $repository = $this->getRepository();

        if (!$this->getOption('no-backup')) {
            // backup
            $this->backup();
        }

        $repository['path'] = $this->console->get('migration.dir');

        try {
            $repository->migrate($this->getArgument(0, null));

            if ($this->getOption('seed') && (string) $this->getArgument(0) !== '0') {
                $io = clone $this->io;

                $io->setArguments(['seed', 'import']);
                $io->setOption('no-backup', true);

                $this->console->getRootCommand()->setIO($io)->execute();
            }
        } catch (\Exception $e) {
            $prompter = new BooleanPrompter();

            $this->out()->out('<error>An error occurred: ' . $e->getMessage() . '</error>');

            if ($prompter->ask('Do you want to restore to last backup? [Y/n] (Y): ', true)) {
                $this->getBackupRepository()->restoreLatest();
            }

            throw $e;
        }

        return true;
    }
425506
public function isValid(): AssertionInterface
    {
        if (!$this->proxy instanceof AutomatedInterface) {
            throw new \RuntimeException('Error, the proxy is not a valid AutomatedInterface instance');
        }

        foreach ($this->statesList as $state) {
            $this->proxy->enableState($state);
        }

        return $this;
    }
99465
private function getProvider()
    {
        $app = $this->app;

        $version = intval($app::VERSION);

        switch ($version) {
            case 4:
              return new ServiceProviderLaravel4($app);

            case 5:
              return new ServiceProviderLaravel5($app);

            default:
              throw new RuntimeException('Your version of Laravel is not supported');
        }
    }