protected function execute(array $arguments = array(), array $options = array())
 {
     $filename = isset($options['filename']) ? $options['filename'] : null;
     $printer = new nbConfigurationPrinter();
     $printer->addConfiguration(nbConfig::getAll());
     if ($filename) {
         $this->logLine(sprintf('bee configuration (file: %s)', $filename), nbLogger::COMMENT);
         $printer->addConfigurationFile($filename);
     } else {
         $dirs = array('./', nbConfig::get('nb_config_dir'));
         $this->logLine(sprintf('bee configuration (dirs: %s)', implode(', ', $dirs)), nbLogger::COMMENT);
         $finder = nbFileFinder::create('file')->add('*.yml')->maxdepth(0);
         foreach ($dirs as $dir) {
             $files = $finder->in($dir);
             foreach ($files as $file) {
                 $this->logLine('Adding ' . $file, nbLogger::COMMENT);
                 $printer->addConfigurationFile($file);
             }
         }
     }
     $this->logLine($printer->printAll());
     return true;
 }
Example #2
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;
 }
Example #3
0
} catch (Exception $e) {
    $t->pass('No config file to print exists');
}
$text = '
app_required_child_field: value
app_required_field: text
app_param1: value4
app_dir1: test/data/system
app_file1: test/data/system/Class.java
app_array: 
  0: 
    key1: value4
  1: 
    key2: field2';
$t->is(removeCarriageReturn($printer->printAll()), removeCarriageReturn($text), 'Printed text is formatted correctly');
$printer = new nbConfigurationPrinter();
$printer->addConfigurationFile($configFileNoChild);
$text = '
app_required_child_field: <error>required</error>
app_required_field: value
app_param3: value3
app_dir1: <error>dir_exists</error>
app_file1: <error>file_exists</error>';
$errors = array('app_required_child_field' => 'required', 'app_dir1' => 'dir_exists', 'app_file1' => 'file_exists');
$printer->addConfigurationErrors($errors);
$t->is(removeCarriageReturn($printer->printAll()), removeCarriageReturn($text), 'Printed text is formatted correctly with errors');
function removeCarriageReturn($text)
{
    $text = str_replace("\r", '', $text);
    $text = str_replace("\n", '|', $text);
    return $text;