/** * Does the work. Determines the appropriate path to write to, and executes * the class-specific reflector. * * @param OutputInterface $output The command-line output. * @return void */ public function process(OutputInterface $output) { $output->writeln($this->formatter->yellow->apply('WRITING CLASS DEFINITIONS')); // Resolve output path variables Dispatcher::get()->dispatch('parse.user.reflect.all.pre'); $this->path_pattern = str_replace('%STAGE%', ConsoleUtil::asciify(ConfigStore::get('vanity.stage')), $this->path_pattern); $this->path_pattern = str_replace('%VERSION%', ConsoleUtil::asciify(ConfigStore::get('vanity.version')), $this->path_pattern); $this->path_pattern = str_replace('%FORMAT%', 'json', $this->path_pattern); foreach ($this->classes as $class) { $reflect = new Reflect($class); $reflect->process(); $reflect->save($this->path_pattern, $output); } Dispatcher::get()->dispatch('parse.user.reflect.all.post'); // Count the classes echo PHP_EOL; $files = Find::files($this->path_pattern, '*.json'); $count = count($files['absolute']); $output->writeln('Wrote ' . $this->formatter->info->apply(" {$count} ") . ' class definition ' . ConsoleUtil::pluralize($count, 'file', 'files') . '.'); }
/** * {@inheritdoc} * * @event EventStore vanity.twig.environment.init */ public function __construct($template_path, $format_identifier) { $this->filesystem = new Filesystem(); self::$format_identifier = $format_identifier; $this->template_path = $template_path; $path = str_replace('%FORMAT%', self::$format_identifier, ConfigStore::get('generator.output')); $filesystem = new Filesystem(); $filesystem->mkdir($path); Twig_Autoloader::register(); $this->twig = new Twig_Environment(new Twig_Loader_Filesystem($this->template_path), array('autoescape' => ConfigStore::get('generator.twig.autoescape'), 'auto_reload' => ConfigStore::get('generator.twig.auto_reload'), 'base_template_class' => ConfigStore::get('generator.twig.base_template_class'), 'charset' => ConfigStore::get('generator.twig.charset'), 'debug' => ConfigStore::get('generator.twig.debug'), 'optimizations' => ConfigStore::get('generator.twig.optimizations'), 'strict_variables' => ConfigStore::get('generator.twig.strict_variables'), 'cache' => sys_get_temp_dir() . '/' . ConsoleUtil::asciify(ConfigStore::get('vanity.name')))); // Extensions $this->twig->addExtension(new Twig_Extension_Debug()); // $this->twig->addExtension(new MarkdownExtension(new MarkdownParser)); // Filters $this->twig->addFilter('description_as_html', new Twig_Filter_Function('Vanity\\Generate\\Utilities::descriptionAsHTML')); $this->twig->addFilter('namespace_as_path', new Twig_Filter_Function('Vanity\\Generate\\Utilities::namespaceAsPath')); $this->twig->addFilter('filter_by_native', new Twig_Filter_Function('Vanity\\Generate\\Utilities::getNativeFilteredList')); $this->twig->addFilter('filter_by_inherited', new Twig_Filter_Function('Vanity\\Generate\\Utilities::getInheritedFilteredList')); $this->twig->addFilter('filter_by_letter', new Twig_Filter_Function('Vanity\\Generate\\Utilities::getListByLetter')); $this->twig->addFilter('authors_as_links', new Twig_Filter_Function('Vanity\\Generate\\Utilities::authorsAsLinks')); $this->twig->addFilter('license_as_link', new Twig_Filter_Function('Vanity\\Generate\\Utilities::licenseAsLink')); $this->twig->addFilter('markdown', new Twig_Filter_Function('Vanity\\Generate\\Utilities::markdown')); $this->twig->addFilter('find_tag', new Twig_Filter_Function('Vanity\\Generate\\Utilities::findTag')); $this->twig->addFilter('names', new Twig_Filter_Function('Vanity\\Generate\\Utilities::getNames')); $this->triggerEvent('vanity.twig.environment.init', new EventStore(array('twig' => $this->twig))); }
/** * Execute the logic for the command. * * @event Event vanity.command.generate.files.pre * @event Event vanity.command.generate.files.post * @event Event vanity.command.complete * @param InputInterface $input The command-line input. * @param OutputInterface $output The command-line output. * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { echo PHP_EOL; // Resolve the configuration and display it $config = new ConfigResolve($input, __DIR__ . '/generate_configs.php'); $config->read(); $this->displayConfig($output); Logger::get()->{ConfigStore::get('log.commands')}('Running command:', array($this->getName())); if ($input->getOption('vanity.view_config')) { exit; } // Load the bootstrap, if any if (file_exists($bootstrap = ConfigStore::get('vanity.bootstrap'))) { include_once $bootstrap; } $output->writeln($this->formatter->yellow->apply('SOURCE DEFINITIONS TO DOCUMENT:')); // Parse the pattern to determine the files to match $path = pathinfo(ConfigStore::get('generator.input'), PATHINFO_DIRNAME); $pattern = pathinfo(ConfigStore::get('generator.input'), PATHINFO_BASENAME); $path = str_replace('%STAGE%', ConsoleUtil::asciify(ConfigStore::get('vanity.stage')), $path); $path = str_replace('%VERSION%', ConsoleUtil::asciify(ConfigStore::get('vanity.version')), $path); $files = Find::files($path, $pattern); $this->triggerEvent('vanity.command.generate.files.pre', new EventStore(array('files' => &$files))); // Display the list of matches foreach ($files['relative'] as $file) { $output->writeln(TAB . $this->formatter->green->apply('-> ') . $file); } // Count the matches echo PHP_EOL; $count = count($files['relative']); $output->writeln('Matched ' . $this->formatter->info->apply(" {$count} ") . ' ' . ConsoleUtil::pluralize($count, 'file', 'files') . '.'); echo PHP_EOL; // Trigger events $this->triggerEvent('vanity.command.generate.files.post', new EventStore(array('files' => &$files))); #--------------------------------------------------------------------------# foreach (ConfigStore::get('generator.formats') as $format) { $this->triggerEvent("vanity.generate.format.{$format}.pre", new EventStore(array('files' => &$files, 'input' => ConfigStore::get('generator.input'), 'output' => ConfigStore::get('generator.output')))); $this->triggerEvent("vanity.generate.format.{$format}", new EventStore(array('files' => &$files, 'input' => ConfigStore::get('generator.input'), 'output' => ConfigStore::get('generator.output')))); $this->triggerEvent("vanity.generate.format.{$format}.post", new EventStore(array('files' => &$files, 'input' => ConfigStore::get('generator.input'), 'output' => ConfigStore::get('generator.output')))); } #--------------------------------------------------------------------------# $this->triggerLogMessageEvent(); $this->triggerEvent('vanity.command.complete'); echo PHP_EOL; }