Beispiel #1
0
 /**
  * Main executor for CLI process.
  */
 public function run(CLIOptions $options)
 {
     $errorHandler = $this->factory->getErrorHandler();
     $errorHandler->register();
     try {
         $this->environment->ensureFitness();
         if ($options->showHelp() === TRUE) {
             $this->showVersion();
             echo $options->getHelpScreen();
             exit(0);
         }
         if ($options->showVersion() === TRUE) {
             $this->showVersion();
             exit(0);
         }
         if ($options->generateSkel() === TRUE) {
             $this->showSkeletonConfig($options->generateStrippedSkel());
             exit(0);
         }
         $cfgLoader = $this->factory->getConfigLoader();
         $cfgFile = $options->configFile();
         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->getLogger();
         $logger->log("Using config file '" . $config->getConfigFile()->getPathname() . "'");
         /** @var Application $app */
         $app = $this->factory->getApplication();
         $defBootstrapFiles = new FileInfoCollection();
         $defBootstrapFiles->add(new FileInfo(__DIR__ . '/../bootstrap/backends.php'));
         $defBootstrapFiles->add(new FileInfo(__DIR__ . '/../bootstrap/enrichers.php'));
         $defBootstrapFiles->add(new FileInfo(__DIR__ . '/../bootstrap/engines.php'));
         $bootstrap = $app->runBootstrap($defBootstrapFiles);
         $bootstrap->load($config->getCustomBootstrapFiles(), false);
         if ($options->listEngines()) {
             $this->showVersion();
             $this->showList('engines', $bootstrap->getEngines());
         }
         if ($options->listEnrichers()) {
             $this->showVersion();
             $this->showList('enrichers', $bootstrap->getEnrichers());
         }
         if ($options->listBackends()) {
             $this->showVersion();
             $this->showList('backends', $bootstrap->getBackends());
         }
         if ($options->listBackends() || $options->listEngines() || $options->listEnrichers()) {
             exit(0);
         }
         foreach ($config->getProjects() as $projectName => $projectConfig) {
             /** @var ProjectConfig $projectConfig */
             $logger->log("Starting to process project '{$projectName}'");
             $app->runConfigChangeDetection($projectConfig->getWorkDirectory(), $config->getConfigFile());
             if (!$options->generatorOnly()) {
                 $app->runCollector($projectConfig->getCollectorConfig());
             }
             if (!$options->collectorOnly()) {
                 $app->runGenerator($projectConfig->getGeneratorConfig());
             }
             $logger->log("Processing project '{$projectName}' completed.");
         }
         $logger->buildSummary();
     } catch (EnvironmentException $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, $e->getMessage() . "\n\n");
         fwrite(STDERR, $options->getHelpScreen());
         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);
     }
 }
Beispiel #2
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);
     }
 }