コード例 #1
0
ファイル: Bootstrap.php プロジェクト: vanity/vanity
 public function __construct($template_path, $format_identifier)
 {
     // Pass parameters to the parent constructor.
     parent::__construct($template_path, $format_identifier);
     // Set the extension that files produced by this template should use.
     $this->setFileExtension('html');
     // If we've set a web root...
     if (ConfigStore::get('generator.template.web_root')) {
         // Make sure that a sitemap.xml file is produced.
         $this->writeSitemap();
     }
 }
コード例 #2
0
ファイル: ReflectAll.php プロジェクト: vanity/vanity
 /**
  * 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') . '.');
 }
コード例 #3
0
ファイル: RegisterGlobal.php プロジェクト: vanity/vanity
 /**
  * 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');
 }
コード例 #4
0
ファイル: Tag.php プロジェクト: vanity/vanity
 /**
  * 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);
 }
コード例 #5
0
ファイル: InheritdocHandler.php プロジェクト: vanity/vanity
 public static function resolve($reflected)
 {
     $is_method = false;
     $is_property = false;
     // Are we working with a property or a method?
     if ($reflected instanceof ReflectionMethod) {
         $is_method = true;
     } elseif ($reflected instanceof ReflectionProperty) {
         $is_property = true;
     } else {
         throw new Exception('Only methods and properties can be reflected with ' . get_called_class());
     }
     // Parse the docblock
     $docblock = new DocBlock($reflected->getDocComment());
     $found_description = false;
     $return = $reflected;
     // Save these for messaging
     $__class = $reflected->getDeclaringClass()->getName();
     $__kind = $reflected->getName();
     // Can we just do a straight-up inherit?
     // @todo: Do a better job of handling {@inheritdoc} according to the spec.
     try {
         while (!$found_description && strpos($docblock->getShortDescription(), '{@inheritdoc}') !== false) {
             // Start over...
             $found_description = false;
             // Log that we're starting...
             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Starting resolution:', array(sprintf("{$__class}%s{$__kind}%s", $is_method ? '::' : '::$', $is_method ? '()' : '')));
             // Grab a reference to the class containing the entity with the {@inheritdoc} tag
             $klass = $reflected->getDeclaringClass();
             // Is this an Interface?
             if ($klass->isInterface()) {
                 throw new InheritdocInInterfaceException('The {@inheritdoc} tag is not resolvable from within Interfaces. Methods and properties should ' . 'be fully-documented.');
             } elseif (SystemStore::get('_.php54') && $klass->isTrait()) {
                 throw new InheritdocInTraitException('The {@inheritdoc} tag is not resolvable from within Traits. Methods and properties should ' . 'be fully-documented.');
             }
             // Are we using Interfaces?
             if (!$found_description && ($interface_count = count($klass->getInterfaces())) > 0) {
                 $count = 1;
                 foreach ($klass->getInterfaces() as $rinterface) {
                     Logger::get()->{ConfigStore::get('log.info')}("{@inheritdoc} Checking Interface {$count}/{$interface_count}:", array($rinterface->getName()));
                     try {
                         $return = $rinterface->getMethod($reflected->getName());
                         Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Match!', array($rinterface->getName(), $reflected->getName(), 'Method'));
                         $found_description = true;
                         break 2;
                     } catch (Exception $e) {
                         try {
                             $return = $rinterface->getProperty($reflected->getName());
                             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Match!', array($rinterface->getName(), $reflected->getName(), 'Property'));
                             $found_description = true;
                             break 2;
                         } catch (Exception $e) {
                             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} No match. Will keep looking...', array($rinterface->getName(), $reflected->getName()));
                         }
                     }
                     $count++;
                 }
             }
             // Are we using Traits?
             if (!$found_description && SystemStore::get('_.php54') && ($trait_count = count($klass->getTraits())) > 0) {
                 $count = 1;
                 foreach ($klass->getTraits() as $rtrait) {
                     Logger::get()->{ConfigStore::get('log.info')}("{@inheritdoc} Checking Trait {$count}/{$trait_count}:", array($rtrait->getName()));
                     try {
                         $return = $rtrait->getMethod($reflected->getName());
                         Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Match!', array($rtrait->getName(), $reflected->getName(), 'Method'));
                         $found_description = true;
                         break 2;
                     } catch (Exception $e) {
                         try {
                             $return = $rtrait->getProperty($reflected->getName());
                             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Match!', array($rtrait->getName(), $reflected->getName(), 'Property'));
                             $found_description = true;
                             break 2;
                         } catch (Exception $e) {
                             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} No match. Will keep looking...', array($rtrait->getName(), $reflected->getName()));
                         }
                     }
                     $count++;
                 }
             }
             // Are we extending a class?
             if ($klass->getParentClass()) {
                 // Continue climbing up the ancestry as necessary
                 while (!$found_description && $klass->getParentClass()) {
                     // Rewrite the reference to $klass
                     $klass = $klass->getParentClass();
                     Logger::get()->{ConfigStore::get('log.info')}("{@inheritdoc} Checking the parent class:", array($klass->getName()));
                     try {
                         $return = $klass->getMethod($reflected->getName());
                         Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Match!', array($klass->getName(), $reflected->getName(), 'Method'));
                         $found_description = true;
                         break 2;
                     } catch (Exception $e) {
                         try {
                             $return = $klass->getProperty($reflected->getName());
                             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} Match!', array($klass->getName(), $reflected->getName(), 'Property'));
                             $found_description = true;
                             break 2;
                         } catch (Exception $e) {
                             Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} No match. Will keep looking...', array($klass->getName(), $reflected->getName()));
                         }
                     }
                 }
             }
             // We couldn't find anything
             throw new CouldNotResolveInheritdocException('Leaving as-is. The tag will be viewable in the ' . 'resulting documentation.');
         }
     } catch (InheritdocInInterfaceException $e) {
         $message = sprintf("{$__class}%s{$__kind}%s", $is_method ? '::' : '::$', $is_method ? '()' : '');
         // Log that we're starting...
         Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} ' . $e->getMessage(), array($message));
         $formatter = ConsoleUtil::formatters();
         Inconsistency::add($message . $formatter->gold->apply(' => Could not resolve {@inheritdoc}. ' . $e->getMessage()));
     } catch (InheritdocInTraitException $e) {
         $message = sprintf("{$__class}%s{$__kind}%s", $is_method ? '::' : '::$', $is_method ? '()' : '');
         // Log that we're starting...
         Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} ' . $e->getMessage(), array($message));
         $formatter = ConsoleUtil::formatters();
         Inconsistency::add($message . $formatter->gold->apply(' => Could not resolve {@inheritdoc}. ' . $e->getMessage()));
     } catch (CouldNotResolveInheritdocException $e) {
         $message = sprintf("{$__class}%s{$__kind}%s", $is_method ? '::' : '::$', $is_method ? '()' : '');
         // Log that we're starting...
         Logger::get()->{ConfigStore::get('log.info')}('{@inheritdoc} ' . $e->getMessage(), array($message));
         $formatter = ConsoleUtil::formatters();
         Inconsistency::add($message . $formatter->gold->apply(' => Could not resolve {@inheritdoc}. ' . $e->getMessage()));
     } catch (VanityException $e) {
     } catch (Exception $e) {
     }
     return $return;
 }
コード例 #6
0
ファイル: Utilities.php プロジェクト: rmccue/vanity
 /**
  * Return the absolute path for the root of the output.
  *
  * @param  string $format_identifier The identifier for the format. Used as the folder name the output is saved to.
  * @return string                    The absolute path for the root of the output.
  */
 public static function getAbsoluteBasePath($format_identifier)
 {
     return str_replace('%FORMAT%', $format_identifier, ConfigStore::get('generator.output'));
 }
コード例 #7
0
ファイル: AncestryHandler.php プロジェクト: vanity/vanity
 /**
  * Resolves a namespace alias into a fully-qualified namespace.
  *
  * @param  string $short A shortened namespace alias.
  * @return string        The fully-qualified namespace, if available.
  */
 public function resolveNamespace($short)
 {
     if (isset($this->aliases[$short])) {
         Logger::get()->{ConfigStore::get('log.aliases')}('Aliases: Matched in the list of known aliases.', array($short, $this->aliases[$short]));
         return $this->aliases[$short];
     } else {
         // Handle implicit aliases in the same namespace.
         try {
             $namespace = $this->class->getNamespaceName() . '\\' . $short;
             new ReflectionClass($namespace);
             Logger::get()->{ConfigStore::get('log.aliases')}('Aliases: Matched in the current namespace.', array($short, $namespace));
             // If we didn't throw an exception, we're good.
             return $namespace;
         } catch (ReflectionException $e) {
             // Handle implicit namespaces in an extended/implemented namespace.
             try {
                 foreach ($this->namespaces as $ns) {
                     try {
                         $namespace = $ns . '\\' . $short;
                         new ReflectionClass($namespace);
                         Logger::get()->{ConfigStore::get('log.aliases')}('Aliases: Matched in an extended/implemented namespace.', array($short, $namespace));
                         // If we didn't throw an exception, we're good.
                         return $namespace;
                     } catch (ReflectionException $e) {
                     }
                 }
                 throw new ReflectionException();
             } catch (ReflectionException $e) {
                 // Try removing the beginning '\' to see if we find a match.
                 try {
                     $class = preg_replace('/^\\\\/', '', $short);
                     new ReflectionClass($class);
                     Logger::get()->{ConfigStore::get('log.aliases')}('Aliases: Matched by stripping the \\ prefix.', array($short, $class));
                     // If we didn't throw an exception, we're good.
                     return $class;
                 } catch (ReflectionException $e) {
                     $formatter = ConsoleUtil::formatters();
                     Inconsistency::add($class . $formatter->gold->apply(' => No match found for ' . $short . ' (' . SystemStore::get('_.current') . ')'));
                     Logger::get()->{ConfigStore::get('log.aliases')}('Aliases: No match found.', array($short));
                     // No match. Return it as-is (without any starting backslash).
                     return $class;
                 }
             }
         }
     }
 }
コード例 #8
0
ファイル: Template.php プロジェクト: vanity/vanity
 /**
  * Write the sitemap.xml file used by Google and other search engines.
  *
  * @return boolean Whether or not the file was written successfully. A value of `true` means that the file was
  *                 written successfully. A value of `false` means that the file was NOT written successfully.
  */
 public function writeSitemap()
 {
     $path = str_replace('%FORMAT%', self::$format_identifier, ConfigStore::get('generator.output'));
     $sitemap = simplexml_load_string('<?xml version="1.0"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"/>');
     $current_date = gmdate(DATE_W3C);
     $files = new Finder();
     $files = $files->files()->name('*.html')->in($path);
     foreach ($files as $file) {
         $xurl = $sitemap->addChild('url');
         $xurl->addChild('loc', ConfigStore::get('generator.template.web_root') . $file->getRelativePath() . '/' . $file->getFilename());
         $xurl->addChild('lastmod', $current_date);
         $xurl->addChild('changefreq', 'weekly');
     }
     $this->filesystem->mkdir($path);
     return file_put_contents($path . '/sitemap.xml', $sitemap->asXML());
 }
コード例 #9
0
ファイル: MethodHandler.php プロジェクト: vanity/vanity
 /**
  * Retrieve the properties for the class.
  *
  * @return array A list of properties.
  */
 public function getMethods()
 {
     $rclass_methods = $this->class->getMethods();
     // Add methods and parameters
     $rclass_methods = array_values(array_filter($rclass_methods, function ($rmethod) {
         if ($exclusions = ConfigStore::get('source.exclude.methods')) {
             return !preg_match($exclusions, $rmethod->getName());
         }
         return true;
     }));
     foreach ($rclass_methods as $rmethod) {
         $documentThis = true;
         if (!isset($this->methods['count'])) {
             $this->methods['count'] = count($rclass_methods);
         }
         if (!isset($this->methods['method'])) {
             $this->methods['method'] = array();
         }
         $rmethod = InheritdocHandler::resolve($rmethod);
         $_tags = new TagHandler($rmethod->getDocComment(), $this->ancestry);
         $method_docblock = new DocBlock($rmethod->getDocComment());
         $entry = array();
         $entry['name'] = $rmethod->getName();
         $entry['visibility'] = $this->methodAccess($rmethod);
         if ($extension = $rmethod->getExtensionName()) {
             $entry['extension'] = $extension;
             DependencyCollector::add($extension);
         }
         if ($rmethod->getFileName()) {
             $entry['path'] = str_replace(array(VANITY_SYSTEM . '/', VANITY_PROJECT_WORKING_DIR . '/'), '', $rmethod->getFileName());
             $entry['lines'] = array('start' => $rmethod->getStartLine(), 'end' => $rmethod->getEndLine());
             if ($viewsource = ConfigStore::get('source.viewsource')) {
                 $entry['viewsource'] = str_replace(array('%PATH%', '%LINE%'), array($entry['path'], $entry['lines']['start']), $viewsource);
             }
         }
         if ($description = $_tags->getDescription()) {
             $entry['description'] = $description;
         }
         // Method inheritance
         if (($declaring_class = $rmethod->getDeclaringClass()->getName()) !== $this->class->getName()) {
             if (!isset($entry['inheritance'])) {
                 $entry['inheritance'] = array();
             }
             if (!isset($entry['inheritance']['class'])) {
                 $entry['inheritance']['class'] = array();
             }
             $declaring_class = new ReflectionClass($declaring_class);
             $subentry = array();
             $subentry['name'] = $declaring_class->getName();
             if ($declaring_class->getFileName()) {
                 $subentry['path'] = str_replace(VANITY_PROJECT_WORKING_DIR . '/', '', $declaring_class->getFileName());
             }
             $entry['inheritance']['class'][] = $subentry;
         }
         // Method tags
         if (count($method_docblock->getTags())) {
             if (!isset($entry['metadata'])) {
                 $entry['metadata'] = array();
             }
             if (!isset($entry['metadata']['tag'])) {
                 $entry['metadata']['tag'] = array();
             }
             foreach ($method_docblock->getTags() as $rtag) {
                 $dtag = new Tag($rtag, $this->ancestry);
                 $tagData = $dtag->determine()->process(ConfigStore::get('source.resolve_aliases'));
                 if ($tagData['name'] === 'alias') {
                     SystemStore::add('alias.' . $tagData['entity'], $this->class->getName() . '::' . $rmethod->getName());
                     $documentThis = false;
                 }
                 $entry['metadata']['tag'][] = $tagData;
             }
         }
         // Method parameters
         if ($count = count($rmethod->getParameters())) {
             if (!isset($entry['parameters'])) {
                 $entry['parameters'] = array();
             }
             if (!isset($entry['parameters']['count'])) {
                 $entry['parameters']['count'] = $count;
             }
             if (!isset($entry['parameters']['parameter'])) {
                 $entry['parameters']['parameter'] = array();
             }
             foreach ($rmethod->getParameters() as $rparameter) {
                 $tag_finder = new TagFinder($entry);
                 $param = array();
                 $param['name'] = $rparameter->getName();
                 $param['required'] = !$rparameter->isOptional();
                 $param['passed_by_reference'] = $rparameter->isPassedByReference();
                 if ($rparameter->isDefaultValueAvailable()) {
                     $param['default'] = $rparameter->getDefaultValue();
                 }
                 // Pull-in from @tags
                 if ($_description = $tag_finder->find('description', $param['name'])) {
                     $param['description'] = $_description;
                 }
                 if ($_type = $tag_finder->find('type', $param['name'])) {
                     $param['type'] = $this->ancestry->resolveNamespace($_type);
                 }
                 if ($_types = $tag_finder->find('types', $param['name'])) {
                     $param['types'] = $_types;
                 }
                 // Clean-up parameter metadata tags
                 if (isset($entry['metadata']) && isset($entry['metadata']['tag'])) {
                     foreach ($entry['metadata']['tag'] as $index => $tag) {
                         if ($tag['name'] === 'param' && $tag['variable'] === $param['name']) {
                             unset($entry['metadata']['tag'][$index]);
                         }
                     }
                 }
                 // Type hinting trumps docblock
                 if ($rparameter->getClass()) {
                     if (isset($param['type']) && $param['type'] !== $rparameter->getClass()->getName()) {
                         // @todo: Resolve namespace of declaring class.
                         Inconsistency::add($this->class->getName() . '::' . $rmethod->getName() . '($' . $rparameter->getName() . ') [' . $param['type'] . ' => ' . $rparameter->getClass()->getName() . ']');
                     }
                     $param['type'] = $rparameter->getClass()->getName();
                     if (isset($param['types'])) {
                         unset($param['types']);
                     }
                 }
                 $entry['parameters']['parameter'][] = $param;
             }
         }
         // Return value
         $entry['return'] = array('type' => 'void');
         if (isset($entry['metadata']) && isset($entry['metadata']['tag'])) {
             foreach ($entry['metadata']['tag'] as $index => $tag) {
                 if ($tag['name'] === 'return') {
                     $entry['return'] = $tag;
                     unset($entry['return']['name']);
                     // Clean-up return metadata tags
                     unset($entry['metadata']['tag'][$index]);
                 }
             }
         }
         if ($documentThis) {
             $this->methods['method'][] = $entry;
         }
     }
     return $this->methods;
 }
コード例 #10
0
ファイル: Base.php プロジェクト: vanity/vanity
 /**
  * Display the configuration to the Console.
  *
  * @param  OutputInterface $output The command-line output.
  * @return void
  */
 public function displayConfig(OutputInterface $output)
 {
     // Title and formatting
     $output->writeln($this->formatter->yellow->apply('ACTIVE CONFIGURATION OPTIONS:'));
     $padding = ConsoleUtil::tablify(ConfigStore::get());
     $self = $this;
     // Write the tablified listing to the buffer
     $output->writeln(ConsoleUtil::indent(YAML::dump(ConfigStore::get(), 1), $this->formatter->green->apply('-> '), function ($line) use($self, $padding) {
         $pieces = explode(': ', $line);
         $pieces[0] = str_pad($pieces[0], $padding, ' ', STR_PAD_RIGHT);
         $pieces[1] = $self->formatter->gold->apply($pieces[1]);
         return implode(' : ', $pieces);
     }));
     // Write any stored messages to the buffer
     if (count(ConfigStore::$messages) > 0) {
         foreach (ConfigStore::$messages as $message) {
             $output->writeln($message);
         }
     }
     echo PHP_EOL;
 }
コード例 #11
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;
 }
コード例 #12
0
ファイル: TagHandler.php プロジェクト: vanity/vanity
 /**
  * Retrieve the tags for the class.
  *
  * @return array A list of tags.
  */
 public function getTags()
 {
     $metadata = array();
     $tags = $this->docblock->getTags();
     if (count($tags)) {
         if (!isset($metadata['tag'])) {
             $metadata['tag'] = array();
         }
         foreach ($tags as $rtag) {
             $dtag = new Tag($rtag, $this->ancestry);
             $metadata['tag'][] = $dtag->determine()->process(ConfigStore::get('source.resolve_aliases'));
         }
     }
     return $metadata;
 }
コード例 #13
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;
 }
コード例 #14
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;
 }
コード例 #15
0
ファイル: Resolve.php プロジェクト: vanity/vanity
 /**
  * Return the config values passed to the CLI.
  *
  * @param  boolean $returnConfigDir Whether or not to return the configuration directory directly.
  * @return array                    The config values passed to the CLI.
  */
 private function cliValues($returnConfigDir = false)
 {
     $available_configs = (include $this->config_path);
     $available_configs = array_keys(ConfigStore::convert($available_configs));
     $config = array();
     foreach ($available_configs as $option) {
         $config[$option] = $this->input->getOption($option);
     }
     $config = array_filter($config);
     if ($returnConfigDir) {
         return isset($config['vanity.config_dir']) && file_exists($config['vanity.config_dir']) ? realpath($config['vanity.config_dir']) : null;
     }
     if (count($config) > 0) {
         ConfigStore::$messages[] = 'Merged configuration options from the console.';
     }
     return $config;
 }