示例#1
0
 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);
     }
 }
示例#3
0
 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>");
 }
示例#4
0
 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'));
 }
示例#5
0
 /**
  * Save configuration to the cache.
  *
  * @param Config $config
  */
 public function save(Config $config, $message = null)
 {
     $cache = '<?php' . PHP_EOL;
     if ($message) {
         $cache .= '/*' . PHP_EOL;
         $cache .= $message . PHP_EOL;
         $cache .= '*/' . PHP_EOL;
     }
     $cache .= sprintf('return %s;', var_export($config->get(), true));
     $directory = dirname($this->cache_file);
     if (!file_exists($directory)) {
         mkdir($directory, 0777, true);
     }
     return file_put_contents($this->cache_file, $cache);
 }
示例#6
0
 protected function createFirewall(Neptune $neptune, Config $config, $name)
 {
     $driver_key = $config->get("neptune.security.firewalls.{$name}.driver");
     $driver = $neptune['security']->get($driver_key);
     $firewall = new Firewall($name, $driver);
     // register rules
     $rules = $config->get("neptune.security.firewalls.{$name}.rules", array());
     foreach ($rules as $rule => $permission) {
         $firewall->addRule(new RequestMatcher($rule), $permission);
     }
     // register exemptions
     $exemptions = $config->get("neptune.security.firewalls.{$name}.exemptions", array());
     foreach ($exemptions as $exemption => $permission) {
         $firewall->addExemption(new RequestMatcher($exemption), $permission);
     }
     return $firewall;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $dialog = $this->getHelper('dialog');
     $name = $input->getArgument('name');
     if (!$name) {
         $name = $dialog->ask($output, 'Name of module: ');
     }
     $name = strtolower($name);
     $namespace = $input->getArgument('namespace');
     if (!$namespace) {
         $namespace = $dialog->ask($output, 'Namespace for this module: ', S::upperCamelize($name));
     }
     $this->createDirectories($output, $this->createModuleDirectory($namespace));
     $file = $this->createModuleDirectory($namespace) . 'config.php';
     $config = new Config($name);
     $config->save($file);
     $output->writeln("Created <info>{$file}</info>");
     //create module class
 }
示例#8
0
 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);
 }
示例#9
0
 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());
 }