protected function populateNeptuneConfig(InputInterface $input, OutputInterface $output, $path) { if (!$this->allowedToWrite($input, $output, $path)) { return; } //a list of neptune config values to set as a starter. Flatten //the config so the output messages are more meaningful. $values = ['logger.path' => 'storage/logs/logs.log', 'assets.url' => 'assets/']; $config = new Config(); foreach ($values as $key => $value) { $config->set($key, $value); if (!$output->isVerbose()) { continue; } if (is_string($value) && !empty($value)) { $msg = sprintf("Config: Setting <info>%s</info> to <info>%s</info>", $key, $value); } else { $msg = sprintf("Config: Setting <info>%s</info>", $key); } $output->writeln($msg); } $yaml = Yaml::dump($config->get(), 100, 2); file_put_contents($path, $yaml); $output->writeln(sprintf('Created <info>%s</info>', $path)); }
public function onPostMerge(Config $config) { try { foreach ($config as $key => $value) { // _options must be ignored, otherwise this // '_options' => [ // 'foo.bar.baz' => 'combine', // ] // will become // '_options' => [ // 'foo.bar.baz' => 'combine', // 'foo' => [ // 'bar' => [ // 'baz' => 'combine' // ] // ] // ] if (substr($key, 0, 9) === '_options.') { continue; } $config->set($key, $this->resolveValue($config, $value)); } } catch (ConfigKeyException $e) { throw new ConfigKeyException(sprintf('Error resolving references in configuration key "%s"', $key), 1, $e); } }
protected function newEnv(OutputInterface $output, $name, $overwrite = false) { $name = strtolower($name); $file = $this->getRootDirectory() . 'config/env/' . $name . '.yml'; if (file_exists($file) && !$overwrite) { throw new FileException("{$file} already exists"); } $values = ['routing.root_url' => 'myapp.dev/', 'database.main.driver' => 'pdo_mysql', 'database.main.dbname' => 'sandbox', 'database.main.user' => 'root', 'database.main.pass' => '', 'database.main.logger' => 'logger']; $config = new Config(); foreach ($values as $key => $value) { $config->set($key, $value); if (!$output->isVerbose()) { continue; } if (is_string($value) && !empty($value)) { $msg = sprintf("Config: Setting <info>%s</info> to <info>%s</info>", $key, $value); } else { $msg = sprintf("Config: Setting <info>%s</info>", $key); } $output->writeln($msg); } $yaml = Yaml::dump($config->get(), 100, 2); file_put_contents($file, $yaml); $output->writeln("Created <info>{$file}</info>"); }
public function testLoadSavedConfig() { $config = new Config(); $config->set('foo', 'bar'); $this->cache->save($config); $cached_config = $this->cache->getConfig(); $this->assertInstanceOf('Neptune\\Config\\Config', $config); $this->assertSame('bar', $config->get('foo')); }
public function onPreMerge(Config $config, array $incoming) { foreach ($this->options as $key => $option) { switch ($option) { case self::OPTION_OVERWRITE: if ($value = $this->resolveOverwrite($key, $incoming)) { $config->set($key, $value); } continue; case self::OPTION_COMBINE: if ($value = $this->resolveCombined($key, $incoming)) { $config->set($key, $value); } continue; default: continue; } } $config->set('_options', $this->options); }
public function testGetDeepNested() { $c = new Config(); $c->set('parent', array('child' => array(0 => array(1 => array(2 => array(3 => array(4 => 'value'))))))); $this->assertSame('value', $c->get('parent.child.0.1.2.3.4')); }
public function onPreMerge(Config $config, array $incoming) { $config->set('ROOT', $this->neptune->getRootDirectory()); $config->set('ENV', $this->neptune->getEnv()); }