/** * 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); } }
/** * @param CLIOptions $options * * @return GlobalConfig * @throws ConfigLoaderException */ private function loadConfig(CLIOptions $options) { $cfgLoader = $this->factory->getConfigLoader(); $cfgFile = $options->configFile(); if ($cfgFile != '') { return $cfgLoader->load($cfgFile); } return $cfgLoader->autodetect(); }