protected function setupDatabase(InputInterface $input, OutputInterface $output)
 {
     if ($this->manager === NULL) {
         $questionHelper = $this->getHelper('question');
         $file = Filesystem::normalizePath($this->configFile);
         if (!is_file($file)) {
             $output->writeln(sprintf('Missing config file: <info>%s</info>', $this->configFile));
             $question = new ConfirmationQuestion('Do you want to generate the config file? [n] ', false);
             if ($questionHelper->ask($input, $output, $question)) {
                 $tpl = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'ConfigTemplate.txt');
                 $replacements = [];
                 $question = new Question('Database DSN (PDO): ', '');
                 $dsn = $questionHelper->ask($input, $output, $question);
                 $question = new Question('DB username: '******'');
                 $username = $questionHelper->ask($input, $output, $question);
                 $question = new Question('DB password: '******'');
                 $password = $questionHelper->ask($input, $output, $question);
                 $replacements['###DSN###'] = var_export((string) $dsn, true);
                 $replacements['###USERNAME###'] = var_export(trim($username) === '' ? NULL : $username, true);
                 $replacements['###PASSWORD###'] = var_export(trim($password) === '' ? NULL : $password, true);
                 $code = strtr($tpl, $replacements);
                 Filesystem::writeFile($file, $code);
                 $output->writeln(sprintf('Generated <info>%s</file> with this contents:', $file));
                 $output->writeln('');
                 $output->writeln($code);
             }
             return false;
         }
         $config = new Configuration($this->processConfigData(require $file));
         $this->manager = new ConnectionManager($config->getConfig('ConnectionManager'));
         $this->migrationDirectories = $config->getConfig('Migration.MigrationManager.directories')->toArray();
     }
     return true;
 }
 /**
  * Creates a connection manager from a <code>.kkdb.php</code> config file.
  * 
  * @param string $file
  * @return ConnectionManager
  * 
  * @throws \RuntimeException When the config file could not be found.
  */
 public static function fromConfigFile($file)
 {
     if (!is_file($file)) {
         throw new \RuntimeException(sprintf('Config file "%s" does not exist', $file));
     }
     $config = new Configuration(static::processConfigFileData(require $file));
     return new ConnectionManager($config->getConfig('ConnectionManager'));
 }
Exemple #3
0
 public function __construct(Configuration $config)
 {
     foreach ($config->getConfig('handlers') as $name => $cfg) {
         $name = (string) $name;
         $this->handlers[$name] = $cfg;
         $this->matchers[$name] = [];
         foreach ($cfg->getConfig('channels') as $channel) {
             $this->matchers[$name][] = "'^" . strtr($channel, ['.' => '\\.', '*' => '.+']) . "\$'i";
         }
     }
     foreach ($config->getConfig('formatters') as $name => $cfg) {
         $this->formatters[(string) $name] = $cfg;
     }
 }
 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;
 }
 protected function createPipeline($namespace, $name, Configuration $config)
 {
     $pipeline = new Pipeline($namespace, $name, new MediaType($config->getString('type')));
     $processor = new CssUrlProcessor(['css']);
     $processor->setResourcePublisher($this->publisher);
     $pipeline->addProcessor($processor);
     if ($config->has('encoding')) {
         $pipeline->setEncoding($config->getString('encoding'));
     }
     if ($config->has('ttl')) {
         $pipeline->setTtl($config->getInteger('ttl'));
     }
     return $this->populateSources($pipeline, $config->getConfig('sources'));
 }
 public function createSendFileFilter(Configuration $config)
 {
     switch ($config->getString('transport', NULL)) {
         case 'apache':
         case 'lighttpd':
             $transport = SendFileFilter::TRANSPORT_SEND_FILE;
             break;
         case 'nginx':
             $transport = SendFileFilter::TRANSPORT_ACCEL_REDIRECT;
             break;
         case 'lighttpd':
             $transport = SendFileFilter::TRANSPORT_LIGHTTPD;
             break;
         default:
             $transport = SendFileFilter::TRANSPORT_NONE;
     }
     return new SendFileFilter($transport);
 }