public function create(Configuration $config)
 {
     $cachePath = $config->getString('cachePath', NULL);
     $createFolder = $config->getBoolean('createFolder', false);
     if ($cachePath !== NULL) {
         if (!is_dir($cachePath)) {
             if (!$createFolder) {
                 throw new \RuntimeException(sprintf('Cache directory not found: "%s"', $cachePath));
             }
             $cachePath = Filesystem::createDirectory($cachePath);
         }
         if (!is_readable($cachePath)) {
             throw new \RuntimeException(sprintf('Cache directory not readable: "%s"', $cachePath));
         }
         if (!is_writable($cachePath)) {
             throw new \RuntimeException(sprintf('Cache directory not writable: "%s"', $cachePath));
         }
     }
     return new ExpressViewFactory($cachePath, $this->logger);
 }
 public function createProcessEngine(Configuration $config, LoggerInterface $logger = NULL)
 {
     $conn = $this->connectionManager->getConnection($config->getString('connection', 'default'));
     $transactional = $config->getBoolean('transactional', true);
     $dispatcher = $this->container->get(EventDispatcher::class);
     $engine = new ProcessEngine($conn, $dispatcher, $this->factory, $transactional);
     $engine->setDelegateTaskFactory($this->taskFactory);
     $engine->registerExecutionInterceptor(new ScopeExecutionInterceptor($this->scope));
     $engine->setLogger($logger);
     $executor = new JobExecutor($engine, $this->scheduler);
     $this->container->eachMarked(function (JobHandler $handler, BindingInterface $binding) use($executor) {
         $executor->registerJobHandler($this->container->getBound($binding));
     });
     $engine->setJobExecutor($executor);
     $dispatcher->connect(function (AbstractProcessEvent $event) {
         $this->scope->enterContext($event->execution);
     });
     $dispatcher->connect(function (TaskExecutedEvent $event) {
         $query = $event->engine->getRuntimeService()->createExecutionQuery();
         $query->executionId($event->execution->getExecutionId());
         $definition = $query->findOne()->getProcessDefinition();
         $processKey = $definition->getKey();
         $taskKey = $event->execution->getActivityId();
         $this->container->eachMarked(function (TaskHandler $handler, BindingInterface $binding) use($event, $taskKey, $processKey) {
             if ($taskKey == $handler->taskKey) {
                 if ($handler->processKey === NULL || $handler->processKey == $processKey) {
                     $task = $this->container->getBound($binding);
                     if (!$task instanceof TaskHandlerInterface) {
                         throw new \RuntimeException('Invalid task handler implementation: ' . get_class($task));
                     }
                     $task->executeTask($event->execution);
                 }
             }
         });
     });
     return $engine;
 }