Exemplo n.º 1
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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
<?php

require_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
$dataDir = dirname(__FILE__) . '/../../../data/config';
$applicationFile = $dataDir . '/application.config.yml';
$machineFile = $dataDir . '/machine.config.yml';
$configFile1 = $dataDir . '/parser1.config.yml';
$configFile2 = $dataDir . '/parser2.config.yml';
$t = new lime_test(16);
$configuration = new nbConfiguration();
$parser = new nbYamlConfigParser($configuration);
$t->comment('Test get');
$yaml = <<<EOF
key1: value
key2: %key1%
key3_subkey1: %key2%
EOF;
$t->comment('Test parse');
$parser->parse($yaml);
$t->is($configuration->get('key1'), 'value', '->parse() parse a yaml string and set configuration keys');
$t->is($configuration->get('key2'), '%key1%', '->parse() by default does not replace tokens');
$t->is($configuration->get('key3_subkey1'), '%key2%', '->parse() by default does not replace tokens');
$configuration->reset();
$parser->parse($yaml, 'myprefix');
$t->is($configuration->get('myprefix_key1'), 'value', '->parse() can accept a prefix for config keys');
$t->is($configuration->get('myprefix_key2'), '%key1%', '->parse() can accept a prefix for config keys');
$configuration->reset();
$parser->parse($yaml, '', true);
$t->is($configuration->get('key2'), $configuration->get('key1'), '->parse() can replace tokens');
$t->is($configuration->get('key2'), 'value', '->parse() can replace tokens');
$t->is($configuration->get('key3_subkey1'), $configuration->get('key1'), '->parse() can replace tokens');
Exemplo n.º 4
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');
Exemplo n.º 5
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;
 }