public function startup() { $this->template = $this->getTemplate(); $this->template->setFile(dirname(__FILE__) . '/Classgen.latte'); $this->template->phpTag = "<?php"; $neon = new NeonAdapter(); $this->data = $neon->load(dirname(__FILE__) . '/config.neon'); }
public function loadConfiguration() { $builder = $this->getContainerBuilder(); $config = $this->validateConfig($this->defaults); // Add themes $params = []; $neon = new NeonAdapter(); foreach (Finder::findFiles('theme.neon')->limitDepth(2)->from($config['themes']) as $file => $splfile) { // Parse config $expandConfig = ['themeDir' => dirname($splfile->getRealPath())]; $themeConfig = Helpers::expand($neon->load($file), $expandConfig, TRUE); // Validate theme configs $this->validateConfig($this->themeDefaults, $themeConfig, 'themes'); $this->validateConfig($this->themeDefaults['theme'], $themeConfig['theme'], 'theme'); // Parse theme name $themeName = strtolower($themeConfig['theme']['name']); // Check duplicity if (array_key_exists($themeName, $params)) { throw new InvalidStateException('Theme "' . $themeName . '" is already defined.'); } // Add to array $params[$themeName] = $themeConfig; } // Check if selected template is not null Validators::assertField($params, $config['theme'], NULL, 'template "%s"'); $theme = $params[$config['theme']]; // Add parameters to global parameters $builder->parameters['themes'] = []; $builder->parameters['themes']['theme'] = $theme['theme']; $builder->parameters['themes']['vars'] = $config['template']; $builder->parameters['themes']['output'] = $config['output']; // Add template model to container Compiler::parseServices($builder, ['services' => $theme['model']], $this->prefix('model')); // Add command manager (fake presenter) $builder->addDefinition($this->prefix('ui.manager'))->setClass('Generator\\UI\\CommandManager'); // Add template factory $builder->addDefinition($this->prefix('latte.templateFactory'))->setClass('Generator\\Latte\\TemplateFactory')->setAutowired(); // Add commands $builder->addDefinition($this->prefix('commands.info'))->setClass('Generator\\Commands\\InfoCommand')->setInject(); $builder->addDefinition($this->prefix('commands.generate'))->setClass('Generator\\Commands\\GenerateCommand', [$builder->parameters['themes']])->setInject(); $builder->addDefinition($this->prefix('commands.deploy'))->setClass('Generator\\Commands\\DeployCommand')->setInject(); $builder->addDefinition($this->prefix('commands.error'))->setClass('Generator\\Commands\\ErrorCommand')->setInject(); }
/** * @param array $files * @throws InvalidStateException * @return array */ protected function parsePosts($files) { $posts = []; $postsIds = []; $decoder = new NeonAdapter(); foreach ($files as $file) { // Decode file $config = $decoder->load($file); // Merge $post = Config\Helpers::merge($config, $this->scheme); // Check unique post id if (in_array($post['id'], $postsIds)) { throw new InvalidStateException('Duplicate post.id "' . $post['id'] . '"'); } // Expand post scheme $post = Helpers::expand($post, ['file' => dirname($file)], TRUE); // Unify $post['post'] = realpath($post['post']); $posts[] = $post; $postsIds[] = $post['id']; } return $posts; }
public function saveConfig() { $this->save(); $values = $this->data; $this->loadConfig(); $data =& $this->data; foreach ($this->root as $item) { $data =& $data[$item]; } $data = $data ?: array(); $data = Arrays::mergeTree($values, $data); file_put_contents($this->fileName, $this->adapter->dump($this->data)); if (function_exists('opcache_reset')) { opcache_reset(); } }
/** * @return Neon\Entity * @internal */ public static function statementToEntity(Statement $val) { array_walk_recursive($val->arguments, function (&$val) { if ($val instanceof Statement) { $val = NeonAdapter::statementToEntity($val); } }); if (is_array($val->entity) && $val->entity[0] instanceof Statement) { return new Neon\Entity(Neon\Neon::CHAIN, array(self::statementToEntity($val->entity[0]), new Neon\Entity('::' . $val->entity[1], $val->arguments))); } else { return new Neon\Entity($val->entity, $val->arguments); } }
public function save() { file_put_contents($this->fileName, $this->adapter->dump((array) $this->data)); $this->load(); }