Exemple #1
0
 /**
  * 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') . '.');
 }
Exemple #2
0
 /**
  * Executes all of the event handlers.
  *
  * @return void
  */
 public static function events()
 {
     $self = get_called_class();
     // vanity.command.complete event
     Dispatcher::get()->addListener('vanity.command.complete', function (Event $event) {
         $formatter = ConsoleUtil::formatters();
         $stop_time = Timer::stop();
         echo PHP_EOL;
         echo $formatter->pending->apply(' Completed in ' . ConsoleUtil::timeHMS(round($stop_time)) . ' (' . $stop_time . ') | Peak memory usage: ' . ConsoleUtil::formatSize(memory_get_peak_usage()) . ' (' . number_format(memory_get_peak_usage()) . ' bytes) ') . PHP_EOL;
     });
     // vanity.command.log_path event
     Dispatcher::get()->addListener('vanity.command.log_path', function (EventStore $event) {
         $finder = new Finder();
         $formatter = ConsoleUtil::formatters();
         $log_path = $event->get('log_path');
         $time = $event->get('time');
         echo PHP_EOL;
         echo $formatter->yellow->apply('LOG FILES FOR THIS RUN') . PHP_EOL;
         $files = $finder->files()->name("vanity-run-{$time}-*.log")->depth(0)->in($log_path);
         $count = 0;
         foreach ($files as $file) {
             $count++;
             echo TAB . $formatter->green->apply('-> ') . $file->getRealpath() . PHP_EOL;
         }
         // Count the classes
         echo PHP_EOL;
         echo 'Found ' . $formatter->info->apply(" {$count} ") . ' log ' . ConsoleUtil::pluralize($count, 'file', 'files') . '.' . PHP_EOL;
     });
     // vanity.command.parse.report.dependencies event
     Dispatcher::get()->addListener('vanity.command.parse.report.dependencies', function (Event $event) {
         // jsonify!
         $json = ConsoleUtil::json_encode(self::getDependencies());
         // Make sure the directory is created
         $filesystem = new Filesystem();
         $filesystem->mkdir(ConfigStore::get('vanity.reports'));
         file_put_contents(ConfigStore::get('vanity.reports') . '/dependencies.json', $json);
     });
     // vanity.command.parse.warn.dependencies event
     Dispatcher::get()->addListener('vanity.command.parse.warn.dependencies', function (Event $event) use(&$self) {
         $formatter = ConsoleUtil::formatters();
         $dependencies = $self::getDependencies();
         echo PHP_EOL;
         echo $formatter->yellow->apply('REPORT: DEPENDENCIES ON EXTENSIONS') . PHP_EOL;
         foreach ($dependencies as $dependency) {
             echo TAB . $formatter->green->apply('-> ') . $dependency . PHP_EOL;
         }
         // Count the classes
         echo PHP_EOL;
         $count = count($dependencies);
         echo 'Found ' . $formatter->info->apply(" {$count} ") . ' ' . ConsoleUtil::pluralize($count, 'dependency', 'dependencies') . '.' . PHP_EOL;
     });
     // vanity.command.parse.warn.inconsistencies event
     Dispatcher::get()->addListener('vanity.command.parse.warn.inconsistencies', function (Event $event) {
         $formatter = ConsoleUtil::formatters();
         $inconsistencies = DocumentationInconsistencyCollector::read();
         echo PHP_EOL;
         echo $formatter->yellow->apply('REPORT: DOCBLOCK INCONSISTENCIES') . PHP_EOL;
         // We really need \Array->apply(), don't we?
         echo 'Tags where type is inferred: ' . implode(', ', array_map(function ($w) use($formatter) {
             return $formatter->green->apply($w);
         }, explode(', ', '@param, @return, @returns, @see, @throw, @throws, @uses, @used-by, @type, @var'))) . '.' . PHP_EOL;
         foreach ($inconsistencies as $inconsistency) {
             echo TAB . $formatter->green->apply('-> ') . $inconsistency['message'] . PHP_EOL;
         }
         // Count the classes
         echo PHP_EOL;
         $count = count($inconsistencies);
         echo 'Found ' . $formatter->info->apply(" {$count} ") . ' ' . ConsoleUtil::pluralize($count, 'inconsistency', 'inconsistencies') . '.' . PHP_EOL;
     });
     // Handle default HTML template
     DesktopHTMLTemplate::register('default-html');
 }
Exemple #3
0
 /**
  * Triggers an event and logs it to the INFO log.
  *
  * @param  string $event       The string identifier for the event.
  * @param  Event  $eventObject An object that extends the {@see Symfony\Component\EventDispatcher\Event} object.
  * @return void
  */
 public function triggerEvent($event, Event $eventObject = null)
 {
     Logger::get()->{ConfigStore::get('log.events')}('Triggering event:', array($event));
     Dispatcher::get()->dispatch($event, $eventObject);
 }