/** * Export current report as follows: * * 1. Display messages on CLI * 2. Run all formatters and display their text results on CLI * * If no formatter has been specified a default writer will be used depending * on the file extension given. Without a file extension a plain text writer * will be used. */ public function run() { $output = $this->command->getOutput(); $output->writeln(''); $output->writeln('---------------------'); $output->writeln('-- Report follows: --'); $output->writeln('---------------------'); $output->writeln(''); $formatter = new ConsoleMessageFormatter(); $console_report_text = $formatter->format($this->report); $output->writeln($console_report_text); $output->writeln(''); $output->writeln('---------------------'); $output->writeln('-- Export follows: --'); $output->writeln('---------------------'); $output->writeln(''); $default_formatter = array('location' => self::DEFAULT_EXPORT_LOCATION); $formatter_definitions = $this->parameters->get('formatters', array($default_formatter)); foreach ($formatter_definitions as $formatter_definition) { $params = new Parameters($formatter_definition); $location = $params->get('location', self::DEFAULT_EXPORT_LOCATION); if ($params->has('__class')) { $formatter_class = $params->get('__class'); } else { $formatter_class = $this->getFormatterByExtension($location); } $formatter = new $formatter_class(); $formatter->setParameters($params); $output->writeln('Starting export via "' . $formatter_class . '".'); $export_text = $formatter->format($this->report); $output->writeln($export_text); } $output->writeln(''); }
/** * Defaults to "Environaut\Cache\Cache". * * @return string (namespaced) class name to use for writing cachable settings after report generation */ public function getCacheImplementor() { $cache = new Parameters($this->config->get('cache', array())); return $cache->get(self::PARAM_CLASS, 'Environaut\\Cache\\Cache'); }
/** * Returns a new check instance based on the given parameters (from config). * * @param array $parameters check definition parameters * * @return ICheck instance */ protected function getCheckInstance(array $parameters = array()) { $params = new Parameters($parameters); $check_implementor = $params->get(IConfig::PARAM_CLASS, self::DEFAULT_CHECK_IMPLEMENTOR); $check = new $check_implementor(); if (!$check instanceof ICheck) { throw new \InvalidArgumentException('The given check class "' . $check_implementor . '" does not implement ICheck.'); } $check->setCommand($this->command); $check->setCache($this->readonly_cache); $check->setName($params->get(IConfig::PARAM_NAME)); $check->setGroup($params->get(IConfig::PARAM_GROUP)); $check->setParameters($params); return $check; }