Beispiel #1
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->getInstanceFor('EngineFactory');
     $enricherFactory = $this->factory->getInstanceFor('EnricherFactory');
     $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->getInstanceFor('Generator');
     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");
 }
Beispiel #2
0
 /**
  * @covers TheSeer\phpDox\Factory::getInstanceFor
  * @uses TheSeer\phpDox\ProgressLogger
  */
 public function testGetInstanceForMethod()
 {
     $factory = new Factory();
     $this->assertInstanceOf('TheSeer\\phpDox\\ProgressLogger', $factory->getInstanceFor('Logger', 'silent'));
 }
Beispiel #3
0
 /**
  * Main executor for CLI process.
  */
 public function run()
 {
     $errorHandler = $this->factory->getInstanceFor('ErrorHandler');
     $errorHandler->register();
     try {
         $this->preBootstrap();
         $options = $this->processOptions();
         if ($options->getValue('version') === TRUE) {
             $this->showVersion();
             exit(0);
         }
         if ($options->getValue('skel') === TRUE) {
             $this->showSkeletonConfig($options->getValue('strip'));
             exit(0);
         }
         if ($options->getValue('help') === TRUE) {
             $this->showVersion();
             $this->showUsage();
             exit(0);
         }
         $cfgLoader = $this->factory->getInstanceFor('ConfigLoader');
         $cfgFile = $options->getValue('file');
         if ($cfgFile) {
             $config = $cfgLoader->load($cfgFile);
         } else {
             $config = $cfgLoader->autodetect();
         }
         /** @var $config GlobalConfig */
         if ($config->isSilentMode()) {
             $this->factory->setLoggerType('silent');
         } else {
             $this->showVersion();
             $this->factory->setLoggerType('shell');
         }
         $logger = $this->factory->getInstanceFor('Logger');
         $logger->log("Using config file '" . $config->getConfigFile()->getPathname() . "'");
         /** @var Application $app */
         $app = $this->factory->getInstanceFor('Application');
         $bootstrap = $app->runBootstrap(array(new FileInfo(__DIR__ . '/../bootstrap/backends.php'), new FileInfo(__DIR__ . '/../bootstrap/enrichers.php'), new FileInfo(__DIR__ . '/../bootstrap/engines.php')));
         $bootstrap->load($config->getBootstrapFiles(), false);
         if ($options->getValue('engines')) {
             $this->showVersion();
             $this->showList('engines', $bootstrap->getEngines());
             exit(0);
         }
         if ($options->getValue('enrichers')) {
             $this->showVersion();
             $this->showList('enrichers', $bootstrap->getEnrichers());
             exit(0);
         }
         if ($options->getValue('backends')) {
             $this->showVersion();
             $this->showList('backends', $bootstrap->getBackends());
             exit(0);
         }
         foreach ($config->getAvailableProjects() as $project) {
             $logger->log("Starting to process project '{$project}'");
             $pcfg = $config->getProjectConfig($project);
             $index = new FileInfo($pcfg->getWorkDirectory() . '/index.xml');
             if ($index->exists() && $index->getMTime() < $config->getConfigFile()->getMTime()) {
                 $logger->log("Configuration change detected - cleaning cache");
                 $cleaner = new DirectoryCleaner();
                 $cleaner->process(new FileInfo($pcfg->getWorkDirectory()));
             }
             if (!$options->getValue('generator')) {
                 $app->runCollector($pcfg->getCollectorConfig());
             }
             if (!$options->getValue('collector')) {
                 $app->runGenerator($pcfg->getGeneratorConfig());
             }
             $logger->log("Processing project '{$project}' completed.");
         }
         $logger->buildSummary();
     } catch (CLIEnvironmentException $e) {
         $this->showVersion();
         fwrite(STDERR, 'Sorry, but your PHP environment is currently not able to run phpDox due to');
         fwrite(STDERR, "\nthe following issue(s):\n\n" . $e->getMessage() . "\n\n");
         fwrite(STDERR, "Please adjust your PHP configuration and try again.\n\n");
         exit(3);
     } catch (CLIOptionsException $e) {
         $this->showVersion();
         fwrite(STDERR, "\n" . $e->getMessage() . "\n\n");
         $this->showUsage();
         exit(3);
     } catch (ConfigLoaderException $e) {
         $this->showVersion();
         fwrite(STDERR, "\nAn error occured while trying to load the configuration file:\n\t" . $e->getMessage() . "\n\nUsing --skel might get you started.\n\n");
         exit(3);
     } catch (ConfigException $e) {
         fwrite(STDERR, "\nYour configuration seems to be corrupted:\n\n\t" . $e->getMessage() . "\n\nPlease verify your configuration xml file.\n\n");
         exit(3);
     } catch (ApplicationException $e) {
         fwrite(STDERR, "\nAn application error occured while processing:\n\n\t" . $e->getMessage() . "\n\nPlease verify your configuration.\n\n");
         exit(1);
     } catch (\Exception $e) {
         if ($e instanceof fDOMException) {
             $e->toggleFullMessage(TRUE);
         }
         $this->showVersion();
         $errorHandler->handleException($e);
     }
 }