Example #1
0
 /**
  * @param AbstractEvent $event
  * @param bool          $progress
  */
 private function handleEvent(AbstractEvent $event, $progress = TRUE)
 {
     $eventType = $event->getType();
     if (isset($this->enrichers[$eventType])) {
         foreach ($this->enrichers[$eventType] as $enricher) {
             switch ($eventType) {
                 case 'phpdox.start':
                     $enricher->enrichStart($event);
                     break;
                 case 'class.start':
                     $enricher->enrichClass($event);
                     break;
                 case 'interface.start':
                     $enricher->enrichInterface($event);
                     break;
                 case 'trait.start':
                     $enricher->enrichTrait($event);
                     break;
                 case 'token.file.start':
                     $enricher->enrichTokenFile($event);
                     break;
                 case 'phpdox.end':
                     $enricher->enrichEnd($event);
                     break;
             }
         }
     }
     foreach ($this->handlerRegistry->getHandlersForEvent($event->getType()) as $callback) {
         call_user_func($callback, $event);
     }
     if ($progress) {
         $this->logger->progress('processed');
     }
 }
Example #2
0
 /**
  * @param FileInfo $file
  *
  * @throws CollectorException
  * @throws \TheSeer\phpDox\ProgressLoggerException
  *
  * @return bool
  */
 private function processFile(SourceFile $file)
 {
     try {
         if ($file->getSize() === 0) {
             $this->logger->progress('processed');
             return true;
         }
         $result = $this->backend->parse($file);
         if ($result->hasClasses()) {
             foreach ($result->getClasses() as $class) {
                 $this->project->addClass($class);
             }
         }
         if ($result->hasInterfaces()) {
             foreach ($result->getInterfaces() as $interface) {
                 $this->project->addInterface($interface);
             }
         }
         if ($result->hasTraits()) {
             foreach ($result->getTraits() as $trait) {
                 $this->project->addTrait($trait);
             }
         }
         $this->logger->progress('processed');
         return true;
     } catch (ParseErrorException $e) {
         $this->parseErrors[$file->getPathname()] = $e->getPrevious()->getMessage();
         $this->logger->progress('failed');
         return false;
     } catch (\Exception $e) {
         throw new CollectorException('Error while processing source file', CollectorException::ProcessingError, $e, $file);
     }
 }
Example #3
0
 private function setupDependencies()
 {
     $this->dependencyStack = array($this->project);
     foreach ($this->config->getDependencyDirectories() as $depDir) {
         $idxName = $depDir . '/index.xml';
         if (!file_exists($idxName)) {
             $this->logger->log("'{$idxName}' not found - skipping dependency");
             continue;
         }
         $dom = new fDOMDocument();
         $dom->load($idxName);
         $this->dependencyStack[] = new Dependency($dom, $this->project);
     }
 }
Example #4
0
 /**
  * Run Documentation generation process
  *
  * @param GeneratorConfig $config
  *
  * @throws ApplicationException
  * @return void
  */
 public function runGenerator(GeneratorConfig $config)
 {
     $this->logger->reset();
     $this->logger->log("Starting generator");
     $engineFactory = $this->factory->getEngineFactory();
     $enricherFactory = $this->factory->getEnricherFactory();
     $failed = array_diff($config->getRequiredEngines(), $engineFactory->getEngineList());
     if (count($failed)) {
         $list = join("', '", $failed);
         throw new ApplicationException("The engine(s) '{$list}' is/are not registered", ApplicationException::UnknownEngine);
     }
     $failed = array_diff($config->getRequiredEnrichers(), $enricherFactory->getEnricherList());
     if (count($failed)) {
         $list = join("', '", $failed);
         throw new ApplicationException("The enricher(s) '{$list}' is/are not registered", ApplicationException::UnknownEnricher);
     }
     $generator = $this->factory->getGenerator();
     foreach ($config->getActiveBuilds() as $buildCfg) {
         $generator->addEngine($engineFactory->getInstanceFor($buildCfg));
     }
     $this->logger->log('Loading enrichers');
     foreach ($config->getActiveEnrichSources() as $type => $enrichCfg) {
         try {
             $enricher = $enricherFactory->getInstanceFor($enrichCfg);
             $generator->addEnricher($enricher);
             $this->logger->log(sprintf('Enricher %s initialized successfully', $enricher->getName()));
         } catch (EnricherException $e) {
             $this->logger->log(sprintf("Exception while initializing enricher %s:\n\n    %s\n", $type, $e->getMessage()));
         }
     }
     $pconfig = $config->getProjectConfig();
     if (!file_exists($pconfig->getWorkDirectory() . '/index.xml')) {
         throw new ApplicationException('Workdirectory does not contain an index.xml file. Did you run the collector?', ApplicationException::IndexMissing);
     }
     if (!file_exists($pconfig->getWorkDirectory() . '/source.xml')) {
         throw new ApplicationException('Workdirectory does not contain an source.xml file. Did you run the collector?', ApplicationException::SourceMissing);
     }
     $srcDir = $pconfig->getSourceDirectory();
     if (!file_exists($srcDir) || !is_dir($srcDir)) {
         throw new ApplicationException(sprintf('Invalid src directory "%s" specified', $srcDir), ApplicationException::InvalidSrcDirectory);
     }
     $this->logger->log("Starting event loop.\n");
     $generator->run(new \TheSeer\phpDox\Generator\Project($srcDir, $pconfig->getWorkDirectory()));
     $this->logger->log("Generator process completed");
 }