From 86092bdf1eb68d6906ec7a76096d364352a6827e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois?= Date: Sun, 20 Mar 2016 12:18:22 +0100 Subject: [PATCH 1/4] plugin engine: added a way to executing analayzes from plugin and to customize reports --- .../Command/Job/QueueAnalyzeFactory.php | 91 +++++++++++++++++++ ...ueueFactory.php => QueueReportFactory.php} | 34 ++++--- .../Application/Command/RunMetricsCommand.php | 37 +++++++- src/Hal/Application/Config/ConfigFactory.php | 1 + src/Hal/Application/Config/Configuration.php | 23 +++++ .../Config/ExtensionsConfiguration.php | 52 +++++++++++ src/Hal/Application/Config/TreeBuilder.php | 5 +- src/Hal/Application/Extension/Extension.php | 43 +++++++++ .../Extension/ExtensionService.php | 54 +++++++++++ .../Extension/Reporter/Reporter.php | 19 ++++ .../Reporter/ReporterHtmlSummary.php | 29 ++++++ src/Hal/Application/Extension/Repository.php | 53 +++++++++++ src/Hal/Application/Formater/Details/Cli.php | 11 ++- src/Hal/Application/Formater/Details/Csv.php | 10 +- src/Hal/Application/Formater/Details/Json.php | 10 +- src/Hal/Application/Formater/Summary/Cli.php | 26 ++++-- src/Hal/Application/Formater/Summary/Html.php | 15 ++- src/Hal/Application/Formater/Summary/Xml.php | 10 +- .../Formater/Twig/FormatingExtension.php | 68 +++++++++++++- .../Application/Formater/Violations/Xml.php | 10 +- src/Hal/Component/Config/Hydrator.php | 2 + templates/html/summary/report.html.twig | 8 +- 22 files changed, 578 insertions(+), 33 deletions(-) create mode 100644 src/Hal/Application/Command/Job/QueueAnalyzeFactory.php rename src/Hal/Application/Command/Job/{QueueFactory.php => QueueReportFactory.php} (74%) create mode 100644 src/Hal/Application/Config/ExtensionsConfiguration.php create mode 100644 src/Hal/Application/Extension/Extension.php create mode 100644 src/Hal/Application/Extension/ExtensionService.php create mode 100644 src/Hal/Application/Extension/Reporter/Reporter.php create mode 100644 src/Hal/Application/Extension/Reporter/ReporterHtmlSummary.php create mode 100644 src/Hal/Application/Extension/Repository.php diff --git a/src/Hal/Application/Command/Job/QueueAnalyzeFactory.php b/src/Hal/Application/Command/Job/QueueAnalyzeFactory.php new file mode 100644 index 00000000..cae47436 --- /dev/null +++ b/src/Hal/Application/Command/Job/QueueAnalyzeFactory.php @@ -0,0 +1,91 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Command\Job; +use Hal\Application\Extension\ExtensionService; +use Hal\Application\Formater\Chart; +use Hal\Application\Formater\Details; +use Hal\Application\Formater\Summary; +use Hal\Application\Formater\Violations; +use Hal\Application\Score\Scoring; +use Hal\Component\Aggregator\DirectoryAggregatorFlat; +use Hal\Component\Bounds\BoundsInterface; +use Hal\Component\Config\ConfigurationInterface; +use Hal\Component\File\Finder; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * Queue factory + * + * @author Jean-François Lépine + */ +class QueueAnalyzeFactory +{ + + /** + * @var ConfigurationInterface + */ + private $config; + + /** + * @var OutputInterface + */ + private $output; + + /** + * @var InputInterface + */ + private $input; + + /** + * @var ExtensionService + */ + private $extensionsService; + + /** + * Constructor + * + * @param InputInterface $input + * @param OutputInterface $output + * @param ConfigurationInterface $config + * @param ExtensionService $extensionService + */ + public function __construct(InputInterface $input, OutputInterface $output, ConfigurationInterface $config, ExtensionService $extensionService) + { + $this->config = $config; + $this->input = $input; + $this->output = $output; + $this->extensionsService = $extensionService; + } + + /** + * Factory queue + * + * @param Finder $finder + * @param BoundsInterface $bounds + * @return Queue + */ + public function factory(Finder $finder, BoundsInterface $bounds) { + $rules = $this->config->getRuleSet(); + $validator = new \Hal\Application\Rule\Validator($rules); + + // jobs queue planning + $queue = new Queue; + $queue + ->push(new DoAnalyze($this->output, $finder, $this->config->getPath()->getBasePath(), !$this->input->getOption('without-oop'), $this->config->getIgnoreErrors())) + ->push(new SearchBounds($this->output, $bounds)) + ->push(new DoAggregatedAnalyze($this->output, new DirectoryAggregatorFlat($this->input->getOption('level')))) + ->push(new CalculateScore(new Scoring($bounds))) + ; + + return $queue; + } + +} diff --git a/src/Hal/Application/Command/Job/QueueFactory.php b/src/Hal/Application/Command/Job/QueueReportFactory.php similarity index 74% rename from src/Hal/Application/Command/Job/QueueFactory.php rename to src/Hal/Application/Command/Job/QueueReportFactory.php index b780b73d..a212dbee 100644 --- a/src/Hal/Application/Command/Job/QueueFactory.php +++ b/src/Hal/Application/Command/Job/QueueReportFactory.php @@ -8,6 +8,9 @@ */ namespace Hal\Application\Command\Job; +use Hal\Application\Extension\ExtensionService; +use Hal\Application\Extension\extensionsService; +use Hal\Application\Extension\Repository; use Hal\Application\Formater\Chart; use Hal\Application\Formater\Details; use Hal\Application\Formater\Summary; @@ -25,7 +28,7 @@ * * @author Jean-François Lépine */ -class QueueFactory +class QueueReportFactory { /** @@ -43,18 +46,25 @@ class QueueFactory */ private $input; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * * @param InputInterface $input * @param OutputInterface $output * @param ConfigurationInterface $config + * @param ExtensionService $extensionsService */ - public function __construct(InputInterface $input, OutputInterface $output, ConfigurationInterface $config) + public function __construct(InputInterface $input, OutputInterface $output, ConfigurationInterface $config, ExtensionService $extensionsService) { $this->config = $config; $this->input = $input; $this->output = $output; + $this->extensionsService = $extensionsService; } /** @@ -71,18 +81,14 @@ public function factory(Finder $finder, BoundsInterface $bounds) { // jobs queue planning $queue = new Queue; $queue - ->push(new DoAnalyze($this->output, $finder, $this->config->getPath()->getBasePath(), !$this->input->getOption('without-oop'), $this->config->getIgnoreErrors())) - ->push(new SearchBounds($this->output, $bounds)) - ->push(new DoAggregatedAnalyze($this->output, new DirectoryAggregatorFlat($this->input->getOption('level')))) - ->push(new CalculateScore(new Scoring($bounds))) - ->push(new ReportRenderer(true, $this->output, new Summary\Cli($validator, $bounds, $this->output))) - ->push(new ReportRenderer($this->config->getLogging()->getReport('cli'), $this->output, new Details\Cli($validator, $bounds))) - ->push(new ReportWriter($this->config->getLogging()->getReport('html'), $this->output, new Summary\Html($validator, $bounds, $this->config->getTemplate()))) - ->push(new ReportWriter($this->config->getLogging()->getReport('json'), $this->output, new Details\Json($validator, $bounds))) - ->push(new ReportWriter($this->config->getLogging()->getReport('xml'), $this->output, new Summary\Xml($validator, $bounds))) - ->push(new ReportWriter($this->config->getLogging()->getReport('csv'), $this->output, new Details\Csv())) - ->push(new ReportWriter($this->config->getLogging()->getViolation('xml'), $this->output, new Violations\Xml($validator, $bounds))) - ->push(new ReportWriter($this->config->getLogging()->getChart('bubbles'), $this->output, new Chart\Bubbles($validator, $bounds))); + ->push(new ReportRenderer(true, $this->output, new Summary\Cli($validator, $bounds, $this->output, $this->extensionsService))) + ->push(new ReportRenderer($this->config->getLogging()->getReport('cli'), $this->output, new Details\Cli($validator, $bounds, $this->extensionsService))) + ->push(new ReportWriter($this->config->getLogging()->getReport('html'), $this->output, new Summary\Html($validator, $bounds, $this->config->getTemplate(), $this->extensionsService))) + ->push(new ReportWriter($this->config->getLogging()->getReport('json'), $this->output, new Details\Json(true, $this->extensionsService))) + ->push(new ReportWriter($this->config->getLogging()->getReport('xml'), $this->output, new Summary\Xml($validator, $bounds, $this->extensionsService))) + ->push(new ReportWriter($this->config->getLogging()->getReport('csv'), $this->output, new Details\Csv($this->extensionsService))) + ->push(new ReportWriter($this->config->getLogging()->getViolation('xml'), $this->output, new Violations\Xml($validator, $bounds, $this->extensionsService))) + ->push(new ReportWriter($this->config->getLogging()->getChart('bubbles'), $this->output, new Chart\Bubbles($validator, $bounds, $this->extensionsService))); return $queue; } diff --git a/src/Hal/Application/Command/RunMetricsCommand.php b/src/Hal/Application/Command/RunMetricsCommand.php index b2623671..9df59dd6 100644 --- a/src/Hal/Application/Command/RunMetricsCommand.php +++ b/src/Hal/Application/Command/RunMetricsCommand.php @@ -8,8 +8,12 @@ */ namespace Hal\Application\Command; +use Hal\Application\Command\Job\QueueAnalyzeFactory; use Hal\Application\Command\Job\QueueFactory; +use Hal\Application\Command\Job\QueueReportFactory; use Hal\Application\Config\ConfigFactory; +use Hal\Application\Extension\ExtensionService; +use Hal\Application\Extension\Repository; use Hal\Component\Bounds\Bounds; use Hal\Component\Evaluation\Evaluator; use Hal\Component\File\Finder; @@ -88,6 +92,9 @@ protected function configure() ->addOption( 'offline', null, InputOption::VALUE_NONE, 'Include all JavaScript and CSS files in HTML. Generated report will be bigger' ) + ->addOption( + 'plugins', null, InputOption::VALUE_REQUIRED, 'Path of extensions to load, separated by comma (,)' + ) ; } @@ -116,19 +123,45 @@ protected function execute(InputInterface $input, OutputInterface $output) , $config->getPath()->isFollowSymlinks() ? Finder::FOLLOW_SYMLINKS : null ); + // prepare plugins + $repository = new Repository(); + foreach($config->getExtensions()->getExtensions() as $filename) { + if(!file_exists($filename) ||!is_readable($filename)) { + $output->writeln(sprintf('Plugin %s skipped: not found', $filename)); + continue; + } + $plugin = require_once($filename); + $repository->attach($plugin); + } + $extensionService = new ExtensionService($repository); + // prepare structures $bounds = new Bounds(); $collection = new \Hal\Component\Result\ResultCollection(); $aggregatedResults = new \Hal\Component\Result\ResultCollection(); // execute analyze - $queueFactory = new QueueFactory($input, $output, $config); + $queueFactory = new QueueAnalyzeFactory($input, $output, $config, $extensionService); $queue = $queueFactory->factory($finder, $bounds); gc_disable(); $queue->execute($collection, $aggregatedResults); gc_enable(); - $output->writeln('done'); + $output->writeln(''); + + // provide data to extensions + if(($n = sizeof($repository->all())) > 0) { + $output->writeln(sprintf('%d %s. Executing analyzis', $n, ($n > 1 ? 'plugins are enabled' : 'plugin is enabled') )); + $extensionService->receive($config, $collection, $aggregatedResults, $bounds); + } + + // generating reports + $output->writeln("Generating reports..."); + $queueFactory = new QueueReportFactory($input, $output, $config, $extensionService); + $queue = $queueFactory->factory($finder, $bounds); + $queue->execute($collection, $aggregatedResults); + + $output->writeln('Done'); // evaluation of success $rule = $config->getFailureCondition(); diff --git a/src/Hal/Application/Config/ConfigFactory.php b/src/Hal/Application/Config/ConfigFactory.php index d29368a7..0f72dae6 100644 --- a/src/Hal/Application/Config/ConfigFactory.php +++ b/src/Hal/Application/Config/ConfigFactory.php @@ -60,6 +60,7 @@ public function factory(InputInterface $input) { strlen($input->getOption('failure-condition')) > 0 && $config->setFailureCondition($input->getOption('failure-condition')); strlen($input->getOption('template-title')) > 0 && $config->getTemplate()->setTitle($input->getOption('template-title')); strlen($input->getOption('offline')) > 0 && $config->getTemplate()->setOffline($input->getOption('offline')); + strlen($input->getOption('plugins')) > 0 && $config->getExtensions()->setExtensions(explode(',', $input->getOption('plugins'))); strlen($input->getOption('ignore-errors')) > 0 && $config->setIgnoreErrors(true); return $config; diff --git a/src/Hal/Application/Config/Configuration.php b/src/Hal/Application/Config/Configuration.php index 44695d33..ec469b60 100644 --- a/src/Hal/Application/Config/Configuration.php +++ b/src/Hal/Application/Config/Configuration.php @@ -54,6 +54,11 @@ class Configuration implements ConfigurationInterface */ private $ignoreErrors = false; + /** + * @var array + */ + private $extensions = array(); + /** * Constructor */ @@ -63,6 +68,7 @@ public function __construct() { $this->path = new PathConfiguration(); $this->logging = new LoggingConfiguration(); $this->template = new TemplateConfiguration(); + $this->extensions = new ExtensionsConfiguration(); } /** @@ -173,5 +179,22 @@ public function setIgnoreErrors($ignoreErrors) return $this; } + /** + * @return array + */ + public function getExtensions() + { + return $this->extensions; + } + + /** + * @param array $extensions + * @return Configuration + */ + public function setExtensions($extensions) + { + $this->extensions = $extensions; + return $this; + } } \ No newline at end of file diff --git a/src/Hal/Application/Config/ExtensionsConfiguration.php b/src/Hal/Application/Config/ExtensionsConfiguration.php new file mode 100644 index 00000000..9d7c8d3d --- /dev/null +++ b/src/Hal/Application/Config/ExtensionsConfiguration.php @@ -0,0 +1,52 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Config; + +/** + * Extensions configuration + * + * @author Jean-François Lépine + */ +class ExtensionsConfiguration +{ + /** + * @var array + */ + private $extensions = array(); + + + /** + * Constructor + * + * @param array $datas + */ + public function __construct(array $datas = array()) + { + $this->extensions = $datas; + } + + /** + * @return array + */ + public function getExtensions() + { + return $this->extensions; + } + + /** + * @param array $extensions + * @return ExtensionsConfiguration + */ + public function setExtensions($extensions) + { + $this->extensions = $extensions; + return $this; + } +} \ No newline at end of file diff --git a/src/Hal/Application/Config/TreeBuilder.php b/src/Hal/Application/Config/TreeBuilder.php index d12606f6..416123ec 100644 --- a/src/Hal/Application/Config/TreeBuilder.php +++ b/src/Hal/Application/Config/TreeBuilder.php @@ -45,7 +45,7 @@ public function getTree() { ->addDefaultsIfNotSet() ->children() ->scalarNode('directory')->defaultValue(null)->end() - ->scalarNode('exclude')->defaultValue('Tests|tests|Features|features|\.svn|\.git|vendor')->end() + ->scalarNode('exclude')->defaultValue('Tests|tests|Features|features|\.svn|\.git|vendor|node_modules|cache')->end() ->scalarNode('extensions')->defaultValue('php|inc')->end() ->booleanNode('symlinks')->defaultValue(false)->end() ->end() @@ -82,6 +82,9 @@ public function getTree() { ->booleanNode('offline')->defaultValue(false)->end() ->end() ->end() + ->arrayNode('plugins') + ->prototype('scalar') + ->end() ->end() ; diff --git a/src/Hal/Application/Extension/Extension.php b/src/Hal/Application/Extension/Extension.php new file mode 100644 index 00000000..72cf0990 --- /dev/null +++ b/src/Hal/Application/Extension/Extension.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Extension; + + +use Hal\Application\Config\Configuration; +use Hal\Component\Bounds\Bounds; +use Hal\Component\Result\ResultCollection; + +interface Extension { + + /** + * @param Configuration $configuration + * @param ResultCollection $collection + * @param ResultCollection $aggregatedResults + * @param Bounds $bounds + * @return mixed + */ + public function receive(Configuration $configuration, ResultCollection $collection, ResultCollection $aggregatedResults, Bounds $bounds); + + /** + * @return string + */ + public function getName(); + + /** + * @return ReporterHtmlSummary + */ + public function getReporterHtmlSummary(); + + /** + * @return Reporter + */ + public function getReporterCliSummary(); + +} \ No newline at end of file diff --git a/src/Hal/Application/Extension/ExtensionService.php b/src/Hal/Application/Extension/ExtensionService.php new file mode 100644 index 00000000..edf5a6fa --- /dev/null +++ b/src/Hal/Application/Extension/ExtensionService.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Extension; + +use Hal\Application\Config\Configuration; +use Hal\Component\Bounds\Bounds; +use Hal\Component\Result\ResultCollection; + +class ExtensionService { + + /** + * @var Repository + */ + private $repository; + + /** + * ExtensionService constructor. + * @param Repository $repository + */ + public function __construct(Repository $repository) + { + $this->repository = $repository; + } + + /** + * @return Repository + */ + public function getRepository() + { + return $this->repository; + } + + /** + * @param Configuration $config + * @param ResultCollection $collection + * @param ResultCollection $aggregatedResults + * @param Bounds $bounds + * @return mixed + */ + public function receive(Configuration $config, ResultCollection $collection, ResultCollection $aggregatedResults, Bounds $bounds) + { + // search controller + foreach($this->repository->all() as $item) { + $item->receive($config, $collection, $aggregatedResults, $bounds); + } + } +} \ No newline at end of file diff --git a/src/Hal/Application/Extension/Reporter/Reporter.php b/src/Hal/Application/Extension/Reporter/Reporter.php new file mode 100644 index 00000000..17ec8507 --- /dev/null +++ b/src/Hal/Application/Extension/Reporter/Reporter.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Extension\Reporter; + +interface Reporter { + + /** + * @return string + */ + public function render(); + +} \ No newline at end of file diff --git a/src/Hal/Application/Extension/Reporter/ReporterHtmlSummary.php b/src/Hal/Application/Extension/Reporter/ReporterHtmlSummary.php new file mode 100644 index 00000000..e865e18c --- /dev/null +++ b/src/Hal/Application/Extension/Reporter/ReporterHtmlSummary.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Extension\Reporter; + +interface ReporterHtmlSummary { + + /** + * @return string + */ + public function renderJs(); + + /** + * @return string + */ + public function renderHtml(); + + /** + * @return array + */ + public function getMenus(); + +} \ No newline at end of file diff --git a/src/Hal/Application/Extension/Repository.php b/src/Hal/Application/Extension/Repository.php new file mode 100644 index 00000000..4de5e211 --- /dev/null +++ b/src/Hal/Application/Extension/Repository.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hal\Application\Extension; + +class Repository{ + + /** + * @var array + */ + private $extensions = array(); + + /** + * @param Extension $extension + * @return $this + */ + public function attach(Extension $extension) { + $this->extensions[$extension->getName()] = $extension; + return $this; + } + + /** + * @param Extension $extension + * @return $this + */ + public function detach(Extension $extension) { + unset($this->extensions[$extension->getName()]); + return $this; + } + + /** + * @param Extension $extension + * @return bool + */ + public function has(Extension $extension) + { + return isset($this->extensions[$extension->getName()]); + } + + /** + * @return Extension[] + */ + public function all() + { + return $this->extensions; + } +} \ No newline at end of file diff --git a/src/Hal/Application/Formater/Details/Cli.php b/src/Hal/Application/Formater/Details/Cli.php index cd588e1b..3adf8e8e 100644 --- a/src/Hal/Application/Formater/Details/Cli.php +++ b/src/Hal/Application/Formater/Details/Cli.php @@ -8,6 +8,7 @@ */ namespace Hal\Application\Formater\Details; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Application\Rule\Validator; use Hal\Component\Bounds\BoundsInterface; @@ -39,16 +40,24 @@ class Cli implements FormaterInterface { */ private $bound; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * * @param Validator $validator * @param BoundsInterface $bound + * @param ExtensionService $extensionService */ - public function __construct(Validator $validator, BoundsInterface $bound) + public function __construct(Validator $validator, BoundsInterface $bound, ExtensionService $extensionService) { $this->bound = $bound; $this->validator = $validator; + $this->extensionsService = $extensionService; + } /** diff --git a/src/Hal/Application/Formater/Details/Csv.php b/src/Hal/Application/Formater/Details/Csv.php index 9d30f037..1914d167 100644 --- a/src/Hal/Application/Formater/Details/Csv.php +++ b/src/Hal/Application/Formater/Details/Csv.php @@ -8,6 +8,7 @@ */ namespace Hal\Application\Formater\Details; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Component\Result\ResultCollection; @@ -19,11 +20,18 @@ */ class Csv implements FormaterInterface { + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor + * @param ExtensionService $extensionService */ - public function __construct() + public function __construct(ExtensionService $extensionService) { + $this->extensionsService = $extensionService; } /** diff --git a/src/Hal/Application/Formater/Details/Json.php b/src/Hal/Application/Formater/Details/Json.php index f08fa2d3..eba0a881 100644 --- a/src/Hal/Application/Formater/Details/Json.php +++ b/src/Hal/Application/Formater/Details/Json.php @@ -9,6 +9,7 @@ namespace Hal\Application\Formater\Details; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Component\Result\ResultCollection; @@ -25,14 +26,21 @@ class Json implements FormaterInterface { */ private $prettyPrint; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * * @param boolean $prettyPrint optional pretty printing for result json + * @param ExtensionService $extensionService */ - public function __construct($prettyPrint = false) + public function __construct($prettyPrint = false, ExtensionService $extensionService) { $this->prettyPrint = $prettyPrint; + $this->extensionsService = $extensionService; } /** diff --git a/src/Hal/Application/Formater/Summary/Cli.php b/src/Hal/Application/Formater/Summary/Cli.php index b06763e0..05456033 100644 --- a/src/Hal/Application/Formater/Summary/Cli.php +++ b/src/Hal/Application/Formater/Summary/Cli.php @@ -8,6 +8,7 @@ */ namespace Hal\Application\Formater\Summary; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Application\Rule\Validator; use Hal\Component\Bounds\BoundsInterface; @@ -43,18 +44,25 @@ class Cli implements FormaterInterface { */ private $output; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * * @param Validator $validator * @param BoundsInterface $bound * @param OutputInterface $output + * @param ExtensionService $extensionService */ - public function __construct(Validator $validator, BoundsInterface $bound, OutputInterface $output) + public function __construct(Validator $validator, BoundsInterface $bound, OutputInterface $output, ExtensionService $extensionService) { $this->bound = $bound; $this->validator = $validator; $this->output = $output; + $this->extensionsService = $extensionService; } /** @@ -67,13 +75,19 @@ public function terminate(ResultCollection $collection, ResultCollection $groupe // score $score = $collection->getScore(); -// if($score) { - foreach ($score->all() as $name => $value) { - $this->output->writeln(sprintf('%s %s', str_pad($name, 35, '.'), str_pad($value, 5, ' ', STR_PAD_LEFT). ' / ' . Scoring::MAX)); - } + foreach ($score->all() as $name => $value) { + $this->output->writeln(sprintf('%s %s', str_pad($name, 35, '.'), str_pad($value, 5, ' ', STR_PAD_LEFT). ' / ' . Scoring::MAX)); + } $this->output->writeln(''); -// } + // extensions + foreach($this->extensionsService->getRepository()->all() as $plugin) { + $helper = $plugin->getReporterCliSummary(); + if(!$helper) { + continue; + } + $this->output->write($helper->render()); + } } /** diff --git a/src/Hal/Application/Formater/Summary/Html.php b/src/Hal/Application/Formater/Summary/Html.php index afc678b4..25763c46 100644 --- a/src/Hal/Application/Formater/Summary/Html.php +++ b/src/Hal/Application/Formater/Summary/Html.php @@ -9,6 +9,7 @@ namespace Hal\Application\Formater\Summary; use Hal\Application\Config\TemplateConfiguration; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Application\Formater\Twig\FormatingExtension; use Hal\Application\Rule\Validator; @@ -44,18 +45,25 @@ class Html implements FormaterInterface { */ private $template; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * - * @param Validator $validator - * @param BoundsInterface $bound + * @param Validator $validator + * @param BoundsInterface $bound * @param TemplateConfiguration $template + * @param ExtensionService $extensionService */ - public function __construct(Validator $validator, BoundsInterface $bound, TemplateConfiguration $template) + public function __construct(Validator $validator, BoundsInterface $bound, TemplateConfiguration $template, ExtensionService $extensionService) { $this->bound = $bound; $this->validator = $validator; $this->template = $template; + $this->extensionsService = $extensionService; } /** @@ -80,6 +88,7 @@ public function terminate(ResultCollection $collection, ResultCollection $groupe , 'withOOP' => null !== $bound->getSum('instability') , 'title' => $this->template->getTitle() , 'offline' => $this->template->isOffline() + , 'extensions' => $this->extensionsService )); } diff --git a/src/Hal/Application/Formater/Summary/Xml.php b/src/Hal/Application/Formater/Summary/Xml.php index 87a4df70..e11de68c 100644 --- a/src/Hal/Application/Formater/Summary/Xml.php +++ b/src/Hal/Application/Formater/Summary/Xml.php @@ -8,6 +8,7 @@ */ namespace Hal\Application\Formater\Summary; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Application\Rule\Validator; use Hal\Component\Bounds\BoundsInterface; @@ -36,16 +37,23 @@ class Xml implements FormaterInterface { */ private $validator; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * * @param Validator $validator * @param BoundsInterface $bound + * @param ExtensionService $extensionService */ - public function __construct(Validator $validator, BoundsInterface $bound) + public function __construct(Validator $validator, BoundsInterface $bound, ExtensionService $extensionService) { $this->bound = $bound; $this->validator = $validator; + $this->extensionsService = $extensionService; } /** diff --git a/src/Hal/Application/Formater/Twig/FormatingExtension.php b/src/Hal/Application/Formater/Twig/FormatingExtension.php index f2625f91..16c6219f 100644 --- a/src/Hal/Application/Formater/Twig/FormatingExtension.php +++ b/src/Hal/Application/Formater/Twig/FormatingExtension.php @@ -1,6 +1,7 @@ array('html'))) + , new \Twig_SimpleFunction('extensions_js', array($this, 'extensionsJs'), array('is_safe' => array('html'))) + , new \Twig_SimpleFunction('extensions_content', array($this, 'extensionsContent'), array('is_safe' => array('html'))) + ); + } + /** * String as readable text * @@ -54,6 +67,59 @@ public function rule($v, $key) return $this->validator->validate($key, $v); } + /** + * @param ExtensionService $extensions + * @return string + */ + public function extensionsMenu(ExtensionService $extensions) + { + $html = ''; + foreach($extensions->getRepository()->all() as $extension) { + $helper = $extension->getReporterHtmlSummary(); + if(!$helper) { + continue; + } + foreach($helper->getMenus() as $name => $label) { + $html .= sprintf('', $name, $label); + } + } + return $html; + } + + /** + * @param ExtensionService $extensions + * @return string + */ + public function extensionsJs(ExtensionService $extensions) + { + $html = ''; + foreach($extensions->getRepository()->all() as $extension) { + $helper = $extension->getReporterHtmlSummary(); + if(!$helper) { + continue; + } + $html .= $helper->renderJs(); + } + return $html; + } + + /** + * @param ExtensionService $extensions + * @return string + */ + public function extensionsContent(ExtensionService $extensions) + { + $html = ''; + foreach($extensions->getRepository()->all() as $extension) { + $helper = $extension->getReporterHtmlSummary(); + if(!$helper) { + continue; + } + $html .= $helper->renderHtml(); + } + return $html; + } + /** * @inherit */ diff --git a/src/Hal/Application/Formater/Violations/Xml.php b/src/Hal/Application/Formater/Violations/Xml.php index 5cb5cac6..33ec947e 100644 --- a/src/Hal/Application/Formater/Violations/Xml.php +++ b/src/Hal/Application/Formater/Violations/Xml.php @@ -8,6 +8,7 @@ */ namespace Hal\Application\Formater\Violations; +use Hal\Application\Extension\ExtensionService; use Hal\Application\Formater\FormaterInterface; use Hal\Application\Rule\Validator; use Hal\Component\Bounds\BoundsInterface; @@ -35,16 +36,23 @@ class Xml implements FormaterInterface { */ private $validator; + /** + * @var ExtensionService + */ + private $extensionsService; + /** * Constructor * * @param Validator $validator * @param BoundsInterface $bound + * @param ExtensionService $extensionService */ - public function __construct(Validator $validator, BoundsInterface $bound) + public function __construct(Validator $validator, BoundsInterface $bound, ExtensionService $extensionService) { $this->bound = $bound; $this->validator = $validator; + $this->extensionsService = $extensionService; } /** diff --git a/src/Hal/Component/Config/Hydrator.php b/src/Hal/Component/Config/Hydrator.php index 6b704ede..1b150255 100644 --- a/src/Hal/Component/Config/Hydrator.php +++ b/src/Hal/Component/Config/Hydrator.php @@ -9,6 +9,7 @@ namespace Hal\Component\Config; use Hal\Application\Config\Configuration; +use Hal\Application\Config\ExtensionsConfiguration; use Hal\Application\Config\LoggingConfiguration; use Hal\Application\Config\PathConfiguration; use Hal\Application\Config\TemplateConfiguration; @@ -59,6 +60,7 @@ public function hydrates(Configuration $config, array $array) { ->setPath($path) ->setLogging(new LoggingConfiguration($array['logging'])) ->setTemplate(new TemplateConfiguration($array['template'])) + ->setExtensions(new ExtensionsConfiguration($array['plugins'])) ; return $config; } diff --git a/templates/html/summary/report.html.twig b/templates/html/summary/report.html.twig index e1c2d4df..65ab30fb 100644 --- a/templates/html/summary/report.html.twig +++ b/templates/html/summary/report.html.twig @@ -40,6 +40,7 @@ + {{ extensions_menu(extensions) }} @@ -329,6 +330,10 @@ + + {{ extensions_content(extensions) }} + + @@ -365,7 +370,6 @@ {% include "summary/report-relations.js.twig" %} -