From 5f2a1f8eceecac3aaedac899b86cf0afba90c04a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kopacz?= Date: Tue, 1 Dec 2015 15:39:46 +0100 Subject: [PATCH 01/10] filters by check --- .../Controller/DiagnosticsController.php | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/ZFTool/Controller/DiagnosticsController.php b/src/ZFTool/Controller/DiagnosticsController.php index c0d0bc6..8b28bbf 100644 --- a/src/ZFTool/Controller/DiagnosticsController.php +++ b/src/ZFTool/Controller/DiagnosticsController.php @@ -51,6 +51,7 @@ public function runAction() $quiet = !$verbose && !$debug && $this->params()->fromRoute('quiet', false); $breakOnFailure = $this->params()->fromRoute('break', false); $checkGroupName = $this->params()->fromRoute('filter', false); + $checkLabelName = $this->params()->fromRoute('label', false); // Get basic diag configuration $config = isset($config['diagnostics']) ? $config['diagnostics'] : array(); @@ -77,31 +78,29 @@ public function runAction() $config = array_intersect_ukey($config, array($checkGroupName => 1), 'strcasecmp'); if (empty($config)) { - $m = new ConsoleModel(); - $m->setResult($console->colorize(sprintf( + throw new RuntimeException(sprintf( "Unable to find a group of diagnostic checks called \"%s\". Try to use module name (i.e. \"%s\").\n", $checkGroupName, 'Application' - ), ColorInterface::YELLOW)); - $m->setErrorLevel(1); + )); + } - return $m; + if ($checkLabelName) { + $config[$checkGroupName] = array_diff_ukey($config[$checkGroupName], array($checkLabelName => 1), 'strcasecmp'); } + } // Check if there are any diagnostic checks defined if (empty($config)) { - $m = new ConsoleModel(); - $m->setResult( - $console->colorize( + if (empty($config)) { + throw new RuntimeException( "There are no diagnostic checks currently enabled for this application - please add one or more " . "entries into config \"diagnostics\" array or add getDiagnostics() method to your Module class. " . "\n\nMore info: https://github.com/zendframework/ZFTool/blob/master/docs/" . - "DIAGNOSTICS.md#adding-checks-to-your-module\n", ColorInterface::YELLOW) - ); - $m->setErrorLevel(1); - - return $m; + "DIAGNOSTICS.md#adding-checks-to-your-module\n" + ); + } } // Analyze check definitions and construct check instances @@ -137,6 +136,12 @@ public function runAction() if ($checkLabel && is_callable(array($check, 'setLabel'))) { $check->setLabel($checkGroupName . ': ' . $checkLabel); } + + + if ($checkLabelName && $check->getLabel() !== $checkLabelName) { + continue; + } + $checkCollection[] = $check; continue; } @@ -208,6 +213,10 @@ public function runAction() $check->setLabel($checkGroupName . ': ' . $checkLabel); } + if ($checkLabelName && $check->getLabel() !== $checkLabelName) { + continue; + } + $checkCollection[] = $check; } } From 7f4112d264de4d6567ad12fdfe115e1f454f58aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kopacz?= Date: Tue, 1 Dec 2015 15:48:51 +0100 Subject: [PATCH 02/10] add label filter to config --- config/module.config.php | 2 +- config/zftool.global.php.dist | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/module.config.php b/config/module.config.php index edb7565..c1653e5 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -128,7 +128,7 @@ ), 'zftool-diagnostics' => array( 'options' => array( - 'route' => '(diagnostics|diag) [-v|--verbose]:verbose [--debug] [-q|--quiet]:quiet [-b|--break]:break []', + 'route' => '(diagnostics|diag) [-v|--verbose]:verbose [--debug] [-q|--quiet]:quiet [-b|--break]:break [] [