public function getInstanceFor($type) { switch ($type) { case 'parser': return new PHPParser($this->master->getDocblockParser(), $this->master->getErrorHandler()); default: throw new FactoryException("'{$type}' is not a known backend."); } }
/** * @covers TheSeer\phpDox\Factory::getDocblockParser * @uses TheSeer\phpDox\DocBlock\Parser */ public function testgetDoclockParser() { $docBlock = $this->factory->getDocblockParser(); // lazy initialization included $this->assertInstanceOf('TheSeer\\phpDox\\DocBlock\\Parser', $docBlock); $this->assertSame($docBlock, $this->factory->getDocblockParser()); }
/** * @param string $configFile * @throws \RuntimeException */ private function runPhpDoxCollector($configFile) { $exitCode = $this->factory->getCLI()->run(new CLIOptions(['--file', $configFile, '--collector'])); if ($exitCode !== CLI::ExitOK) { throw new \RuntimeException("Impossible to collect units metadata"); } }
/** * @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(); }
/** * 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"); }
/** * 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); } }
public function getGenericInstance($class, array $params) { return parent::getGenericInstance($class, $params); }
/** * 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); } }