示例#1
0
 protected function clearDirectory($path)
 {
     $cleaner = new DirectoryCleaner();
     $cleaner->process(new FileInfo($path));
 }
示例#2
0
文件: CLI.php 项目: sakshika/ATM
 /**
  * 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);
     }
 }