Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public static function register($nameOfFormatterEvent)
 {
     $calledClass = get_called_class();
     Dispatcher::get()->addListener("vanity.generate.format.{$nameOfFormatterEvent}", function (EventStore $event) use($calledClass, $nameOfFormatterEvent) {
         $formatter = ConsoleUtil::formatters();
         $filesystem = new Filesystem();
         $template = new $calledClass(GenerateUtils::findTemplatesFor($calledClass), $nameOfFormatterEvent);
         echo $formatter->yellow->apply('COPYING STATIC ASSETS:') . PHP_EOL;
         // Copy the template's static assets.
         $staticAssets = new Finder();
         $staticAssets = $staticAssets->files()->in(GenerateUtils::findStaticAssetsFor($calledClass) . '/');
         $assets = 0;
         foreach ($staticAssets as $asset) {
             $filesystem->copy($asset->getRealPath(), GenerateUtils::getAbsoluteBasePath($nameOfFormatterEvent) . '/' . str_replace(GenerateUtils::findStaticAssetsFor($calledClass) . '/', '', $asset->getRealPath()));
             echo TAB . $formatter->green->apply('-> ') . $asset->getRealPath() . PHP_EOL;
             $assets++;
         }
         // Copy the project's static assets.
         if (file_exists(ConfigStore::get('vanity.config_dir') . '/static/')) {
             $staticProjectAssets = new Finder();
             $staticProjectAssets = $staticProjectAssets->files()->in(ConfigStore::get('vanity.config_dir') . '/static/');
             foreach ($staticProjectAssets as $asset) {
                 $filesystem->copy($asset->getRealPath(), GenerateUtils::getAbsoluteBasePath($nameOfFormatterEvent) . '/' . str_replace(ConfigStore::get('vanity.config_dir') . '/static/', '', $asset->getRealPath()));
                 echo TAB . $formatter->green->apply('-> ') . $asset->getRealPath() . PHP_EOL;
                 $assets++;
             }
         }
         echo PHP_EOL;
         echo 'Copied ' . $formatter->info->apply(" {$assets} ") . ' static ' . ConsoleUtil::pluralize($assets, 'file', 'files') . '.' . PHP_EOL;
         echo PHP_EOL;
         echo $formatter->yellow->apply('GENERATING: ' . strtoupper($nameOfFormatterEvent)) . PHP_EOL;
         // Keep track of the number of files written
         $count = 0;
         $files = $event->get('files');
         foreach ($files['absolute'] as $file) {
             foreach ($template->generateAPIReference($file) as $wrote) {
                 echo TAB . $formatter->green->apply('-> ') . str_replace(VANITY_PROJECT_WORKING_DIR . '/', '', $wrote) . PHP_EOL;
                 $count++;
             }
         }
         echo TAB . $formatter->green->apply('-> ') . self::writeTypeahead(self::$typeahead) . PHP_EOL;
         $count++;
         self::wroteFileCount($count);
     });
 }