예제 #1
0
파일: Parse.php 프로젝트: vanity/vanity
 /**
  * Execute the logic for the command.
  *
  * @event  EventStore      vanity.command.parse.files.pre
  * @event  EventStore      vanity.command.parse.files.post
  * @event  EventStore      vanity.command.parse.classlist.pre
  * @event  EventStore      vanity.command.parse.classlist.post
  * @event  EventStore      vanity.command.parse.reflection.pre
  * @event  EventStore      vanity.command.parse.reflection.post
  * @event  Event           vanity.command.parse.warn.dependencies
  * @event  Event           vanity.command.parse.warn.inconsistencies
  * @event  Event           vanity.command.parse.report.dependencies
  * @event  Event           vanity.command.parse.report.inconsistencies
  * @event  Event           vanity.command.log_path
  * @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__ . '/parse_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('MATCHED FILES:'));
     // Parse the pattern to determine the files to match
     $path = pathinfo(ConfigStore::get('source.input'), PATHINFO_DIRNAME);
     $pattern = pathinfo(ConfigStore::get('source.input'), PATHINFO_BASENAME);
     $files = Find::files($path, $pattern);
     $this->triggerEvent('vanity.command.parse.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.parse.files.post', new EventStore(array('files' => &$files)));
     #--------------------------------------------------------------------------#
     // Find the classes
     $output->writeln($this->formatter->yellow->apply('MATCHED CLASSES:'));
     $classes = array_filter(Find::classes($files['absolute']), function ($class) {
         if ($regex = ConfigStore::get('source.exclude.classes')) {
             return !preg_match($regex, $class);
         }
         return true;
     });
     $this->triggerEvent('vanity.command.parse.classlist.pre', new EventStore(array('classes' => &$classes)));
     // Display the classes
     foreach ($classes as $class) {
         $output->writeln(TAB . $this->formatter->green->apply('-> ') . $class);
     }
     // Count the classes
     echo PHP_EOL;
     $count = count($classes);
     $output->writeln('Found ' . $this->formatter->info->apply(" {$count} ") . ' ' . ConsoleUtil::pluralize($count, 'class', 'classes') . ' to document.');
     echo PHP_EOL;
     $this->triggerEvent('vanity.command.parse.classlist.post', new EventStore(array('classes' => &$classes)));
     #--------------------------------------------------------------------------#
     $reflector = new ReflectAll($classes, ConfigStore::get('source.output'));
     $this->triggerEvent('vanity.command.parse.reflection.pre', new EventStore(array('reflector' => &$reflector)));
     $reflector->process($output);
     $this->triggerEvent('vanity.command.parse.reflection.post', new EventStore(array('reflector' => &$reflector)));
     #--------------------------------------------------------------------------#
     // Warnings
     if (ConfigStore::get('warn.dependencies')) {
         $this->triggerEvent('vanity.command.parse.warn.dependencies');
     }
     if (ConfigStore::get('warn.inconsistencies')) {
         $this->triggerEvent('vanity.command.parse.warn.inconsistencies');
     }
     // Reports
     if (ConfigStore::get('report.dependencies')) {
         $this->triggerEvent('vanity.command.parse.report.dependencies');
     }
     if (ConfigStore::get('report.inconsistencies')) {
         $this->triggerEvent('vanity.command.parse.report.inconsistencies');
     }
     $this->triggerLogMessageEvent();
     $this->triggerEvent('vanity.command.complete');
     echo PHP_EOL;
 }
예제 #2
0
파일: Fetch.php 프로젝트: vanity/vanity
 /**
  * Execute the logic for the command.
  *
  * @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__ . '/fetch_configs.php');
     $config->read();
     $this->displayConfig($output);
     Logger::get()->{ConfigStore::get('log.commands')}('Running command:', array($this->getName()));
     echo PHP_EOL;
     // Instantiate
     $filesystem = new Filesystem();
     // Handle a fresh checkout
     if (!$filesystem->exists(VANITY_CACHE_DIR)) {
         Logger::get()->{ConfigStore::get('log.info')}('Cache directory does not exist.');
         Logger::get()->{ConfigStore::get('log.info')}('Attempting to create:', array(VANITY_CACHE_DIR));
         try {
             $filesystem->mkdir(VANITY_CACHE_DIR, 0777);
             $this->triggerEvent('vanity.command.php.fetch.checkout.pre', new EventStore(array('cache_dir' => VANITY_CACHE_DIR, 'type' => 'checkout')));
             $output->writeln($this->formatter->yellow->apply('PHP DOCUMENTATION CHECKOUT'));
             $output->writeln('Downloading the PHP documentation for the first time. This may take a few minutes.');
             echo PHP_EOL;
             foreach ($this->repositories as $write_to => $repository) {
                 $url = $repository[0];
                 $append = isset($repository[1]) ? $repository[1] : '';
                 $output->writeln($this->formatter->green->apply($url));
                 $svn = "svn co {$url} {$write_to}{$append}";
                 Logger::get()->{ConfigStore::get('log.commands')}($svn);
                 $process = new Process($svn);
                 $process->run(function ($type, $buffer) use($output) {
                     if ($type === 'err') {
                         $output->writeln('ERR > ' . $buffer);
                     } else {
                         $output->writeln(TAB . trim($buffer));
                     }
                 });
                 unset($process);
                 echo PHP_EOL;
             }
             $this->triggerEvent('vanity.command.php.fetch.checkout.post', new EventStore(array('cache_dir' => VANITY_CACHE_DIR, 'type' => 'update')));
         } catch (IOException $e) {
             Logger::get()->{ConfigStore::get('log.error')}('Failed to create user cache directory. Halting.', array(VANITY_CACHE_DIR));
             throw new IOException('Vanity was unable to create the user cache directory at ' . VANITY_CACHE_DIR . ', or was unable to set the permissions to 0777.');
         }
     } else {
         Logger::get()->{ConfigStore::get('log.info')}('Cache directory already exists.', array(VANITY_CACHE_DIR));
         $this->triggerEvent('vanity.command.php.fetch.update.pre', new EventStore(array('cache_dir' => VANITY_CACHE_DIR, 'type' => 'update')));
         $output->writeln($this->formatter->yellow->apply('PHP DOCUMENTATION UPDATE'));
         $output->writeln('Updating the PHP documentation.');
         echo PHP_EOL;
         foreach ($this->repositories as $write_to => $repository) {
             $url = $repository[0];
             $append = isset($repository[1]) ? $repository[1] : '';
             $output->writeln($this->formatter->green->apply($url));
             $svn = "svn up {$write_to}{$append}";
             Logger::get()->{ConfigStore::get('log.commands')}($svn);
             $process = new Process($svn);
             $process->run(function ($type, $buffer) use($output) {
                 if ($type === 'err') {
                     $output->writeln('ERR > ' . $buffer);
                 } else {
                     $output->writeln(TAB . trim($buffer));
                 }
             });
             unset($process);
             echo PHP_EOL;
         }
         $this->triggerEvent('vanity.command.php.fetch.update.post', new EventStore(array('cache_dir' => VANITY_CACHE_DIR, 'type' => 'update')));
     }
     $this->triggerLogMessageEvent();
     $this->triggerEvent('vanity.command.complete');
     echo PHP_EOL;
 }
예제 #3
0
파일: Generate.php 프로젝트: vanity/vanity
 /**
  * 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;
 }