From 2e38d64dfe2940a5b1e397251baed45a7d45c11c Mon Sep 17 00:00:00 2001 From: mattab <matthieu.aubry@gmail.com> Date: Wed, 1 Oct 2014 11:36:33 +1300 Subject: [PATCH] Refactor magic string FTW --- core/FrontController.php | 4 +++- core/Plugin/Report.php | 8 +++++++- plugins/Contents/Controller.php | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/core/FrontController.php b/core/FrontController.php index 4b5ee6f20b..ce39922a2e 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -57,6 +57,7 @@ use Piwik\Plugins\CoreHome\Controller as CoreHomeController; class FrontController extends Singleton { const DEFAULT_MODULE = 'CoreHome'; + /** * Set to false and the Front Controller will not dispatch the request * @@ -153,7 +154,8 @@ class FrontController extends Singleton return array(new CoreHomeController(), 'renderReportWidget'); } - if (!empty($action) && 'menu' === substr($action, 0, 4)) { + if (!empty($action) && Report::PREFIX_ACTION_IN_MENU === substr($action, 0, strlen(Report + ::PREFIX_ACTION_IN_MENU))) { $reportAction = lcfirst(substr($action, 4)); // menuGetPageUrls => getPageUrls $report = Report::factory($module, $reportAction); diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index 9037ce664c..c30e731d46 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -41,6 +41,12 @@ class Report */ const COMPONENT_SUBNAMESPACE = 'Reports'; + /** + * When added to the menu, a given report eg 'getCampaigns' + * will be routed as &action=menuGetCampaigns + */ + const PREFIX_ACTION_IN_MENU = 'menu'; + /** * The name of the module which is supposed to be equal to the name of the plugin. The module is detected * automatically. @@ -711,7 +717,7 @@ class Report private function getMenuControllerAction() { - return 'menu' . ucfirst($this->action); + return self::PREFIX_ACTION_IN_MENU . ucfirst($this->action); } private function getSubtableApiMethod() diff --git a/plugins/Contents/Controller.php b/plugins/Contents/Controller.php index daf319bb53..5785ba478c 100644 --- a/plugins/Contents/Controller.php +++ b/plugins/Contents/Controller.php @@ -27,7 +27,7 @@ class Controller extends \Piwik\Plugin\Controller $reportsView->addReport( $report->getCategory(), $report->getName(), - 'Contents.menu' . ucfirst($report->getAction()) + 'Contents.' . Report::PREFIX_ACTION_IN_MENU . ucfirst($report->getAction()) ); } -- GitLab