示例#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));
 }
示例#2
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>");
 }
示例#3
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;
 }
示例#4
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);
 }
示例#5
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'));
 }