예제 #1
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $merger = new Merger();
     $apache = $input->getOption('apache');
     if ($apache) {
         $output->write($merger->merge($this->getTemplate('env/apache.conf'), ['directory' => basename(getcwd()), 'version' => Information::VERSION, 'date' => date('Y-m-d H:i:s')], false));
     }
 }
예제 #2
0
 public function testMergeFieldsCannotHaveAnythingButAplhaNumericCharacters()
 {
     $str = $this->merger->merge('the quick brown { animal1: true } jumped over the lazy {animal2$}', [], false);
     $this->assertEquals('the quick brown { animal1: true } jumped over the lazy {animal2$}', $str);
 }
예제 #3
0
 /**
  * loads and decodes a configuration files
  * @param string $path
  * @param array $mergedata
  * @return array
  */
 protected function loadFile($file, array $mergedata = [])
 {
     $merger = new Merger();
     // configuration file not found
     if (!is_readable($file)) {
         throw new Exception('Invalid file: ' . $file);
     }
     $str = file_get_contents($file);
     $str = $merger->merge($str, $mergedata, false);
     return $this->decode($str);
 }
예제 #4
0
 public function initialize()
 {
     $conf =& $this->conf;
     // yaml route shortcut
     // #resource Task (all actions)
     // #resource Task index
     // #resource Task index add edit (etc.)
     $conf->registerMacroPreParser('/#resource (.+)/', function ($matches, $raw) {
         $word = new Word();
         $merger = new Merger();
         $models = (array) array_pop($matches);
         $macros = (array) array_pop($matches);
         foreach ($models as $index => $resource) {
             $resource = preg_replace('/\\s+/', ' ', $resource);
             $parts = explode(' ', $resource);
             $resource = array_shift($parts);
             $actions = count($parts) ? $parts : static::$default_actions;
             $templates = [];
             $model = $word->pluralize($resource);
             $model = strtolower($model);
             $clazz = ucwords($model);
             foreach ($actions as $action) {
                 $templates[] = static::${"action_{$action}_template"};
             }
             $template = $merger->merge(implode(PHP_EOL . PHP_EOL, $templates), ['model' => $model, 'clazz' => $clazz, 'resource' => $resource], false);
             $raw = str_replace($macros[$index], $template, $raw);
         }
         return $raw;
     });
     // yaml import file comments
     $conf->registerMacroPreParser('/#import (.+)/', function ($matches, $raw) {
         $confs = [];
         foreach ($matches[0] as $index => $macro) {
             $import = explode(' ', $matches[1][$index], 2);
             if (count($import) > 1) {
                 $data = explode(',', $import[1]);
                 $import = $import[0];
                 foreach ($data as $index => $row) {
                     list($key, $val) = explode(':', $row);
                     $data[trim($key)] = trim($val);
                     unset($data[$index]);
                 }
             } else {
                 $import = $import[0];
                 $data = [];
             }
             $confs[$import] = $data;
             $raw = str_replace($macro, '', $raw);
         }
         return !count($confs) ? $raw : sprintf('~imports: %s%s%s', json_encode($confs), PHP_EOL, $raw);
     });
     // import extras
     $conf->registerMacroPostParser(function (&$obj) {
         if (isset($obj['~imports'])) {
             $imports = $obj['~imports'];
             unset($obj['~imports']);
             foreach ($imports as $import => $mergedata) {
                 $data = $this->load($import, $mergedata);
                 $obj = array_merge_recursive($obj, $data);
             }
         }
         return $obj;
     });
 }