Beispiel #1
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $listFile = $arguments['list-file'];
     $doit = isset($options['doit']);
     $configuration = new nbConfiguration();
     $configuration->add(nbConfig::getAll());
     $configuration->add(sfYaml::load($listFile), '', true);
     foreach ($configuration->get('filesystem_multi-change-mode') as $item) {
         $directory = $item['directory'];
         $dirMode = $item['dir-mode'];
         $fileMode = $item['file-mode'];
         $this->logLine(sprintf('Changing directory mode in %s for %s', $dirMode, $directory));
         $command = sprintf('find %s -type d -exec chmod %s {} \\;', $directory, $dirMode);
         $this->executeShellCommand($command, $doit);
         $this->logLine(sprintf('Changing file mode in %s for files in %s', $fileMode, $directory));
         $command = sprintf('find %s -type f -exec chmod %s {} \\;', $directory, $fileMode);
         $this->executeShellCommand($command, $doit);
     }
     $this->logLine('Mode changed successfully!');
     return true;
 }
Beispiel #2
0
 public function check($templateFile, nbConfiguration $configuration)
 {
     if (!file_exists($templateFile)) {
         throw new Exception(sprintf('Template %s does not exist', $templateFile));
     }
     $template = new nbConfiguration();
     $template->add(sfYaml::load($templateFile), '');
     //    $config = new nbConfiguration();
     //    $config->add($values, '', true);
     $this->errors = array();
     $this->doCheck('', $configuration->getAll(), $template->getAll());
     if ($this->hasErrors()) {
         $message = "Configuration has errors: \n";
         foreach ($this->errors as $key => $error) {
             $message .= sprintf("%s: %s\n", $key, $error);
         }
         throw new Exception($message);
     }
     return true;
 }
Beispiel #3
0
$configuration->add($key2);
$t->is($configuration->getAll(), array('foo' => 'fooValue', 'bar' => 'barVal', 'bar2' => 'barValue2'), '$configuration->add() old and new values');
$key1 = array('foo' => 'fooVal', 'foo2' => 'fooValue2');
$configuration->add($key1);
$t->is($configuration->getAll(), array('foo' => 'fooVal', 'foo2' => 'fooValue2', 'bar' => 'barVal', 'bar2' => 'barValue2'), '$configuration->add() old and new values');
$key2 = array('foo2' => 'fooVal2', 'bar' => 'barVal', 'bar2' => 'barValue2');
$configuration->add($key2);
$t->is($configuration->getAll(), array('foo' => 'fooVal', 'foo2' => 'fooVal2', 'bar' => 'barVal', 'bar2' => 'barValue2'), '$configuration->add() old and new values');
$t->comment('nbConfigTest - Test add with prefix');
$configuration = new nbConfiguration();
$key1 = array('foo' => 'fooValue');
$key2 = array('bar' => 'barValue');
$result = array('myprefix' => array('foo' => 'fooValue', 'bar' => 'barValue'));
$configuration->add($key1, 'myprefix');
$configuration->add($key2, 'myprefix');
$t->is($configuration->get('myprefix_foo'), 'fooValue', '$configuration->add() can set a prefix for 1st level keys');
$t->is($configuration->getAll(), $result, '$configuration->add() can set a prefix for 1st level keys');
$t->comment('nbConfigTest - Test add with replace tokens');
$configuration = new nbConfiguration();
$key1 = array('foo' => 'bar');
$key2 = array('baz' => '%foo%');
$key3 = array('blu' => array('%foo%', '%baz%'));
$key4 = array('bup' => '%flo%');
$configuration->add($key1, '');
$configuration->add($key2, '', true);
$configuration->add($key3, '', true);
$configuration->add($key4, '', true);
$t->is($configuration->get('baz'), $configuration->get('foo'), '->add() can replace tokens');
$t->is($configuration->get('baz'), 'bar', '->add() can replace child tokens');
$t->is($configuration->get('blu'), array('bar', 'bar'), '->add() can replace array tokens');
$t->is($configuration->get('bup'), '%flo%', '->add() will not replace a value if not set');
Beispiel #4
0
 public function checkConfiguration($configDir, $configFilename)
 {
     $configFile = $this->parser->checkDefaultConfigurationDirs($configFilename);
     if (!file_exists($configFile)) {
         throw new InvalidArgumentException(sprintf('Config file "%s" does not exist', $configFilename));
     }
     // Check configuration
     $checker = new nbConfigurationChecker(array('logger' => $this->getLogger(), 'verbose' => $this->isVerbose()));
     $configuration = new nbConfiguration();
     $configuration->add(nbConfig::getAll());
     $configuration->add(sfYaml::load($configFile), '', true);
     try {
         $checker->check($configDir . '/' . $this->getTemplateConfigFilename(), $configuration);
     } catch (Exception $e) {
         $this->logLine('Configuration file doesn\'t match the template', nbLogger::ERROR);
         $printer = new nbConfigurationPrinter();
         $printer->addConfiguration($configuration->getAll());
         //      $printer->addConfigurationFile($configFile);
         $printer->addConfigurationErrors($checker->getErrors());
         $this->logLine($printer->printAll());
         throw $e;
     }
     return $configFile;
 }