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; }
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; } }
/** * 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')); }
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')); }