Skip to content

Commit

Permalink
Refactor magic string FTW
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Sep 30, 2014
1 parent 7e6ab62 commit 2e38d64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion core/FrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
class FrontController extends Singleton
{
const DEFAULT_MODULE = 'CoreHome';

/**
* Set to false and the Front Controller will not dispatch the request
*
Expand Down Expand Up @@ -153,7 +154,8 @@ protected function makeController($module, $action, &$parameters)
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);

Expand Down
8 changes: 7 additions & 1 deletion core/Plugin/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -711,7 +717,7 @@ private function getMetricTranslations($metricsToTranslate)

private function getMenuControllerAction()
{
return 'menu' . ucfirst($this->action);
return self::PREFIX_ACTION_IN_MENU . ucfirst($this->action);
}

private function getSubtableApiMethod()
Expand Down
2 changes: 1 addition & 1 deletion plugins/Contents/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function index()
$reportsView->addReport(
$report->getCategory(),
$report->getName(),
'Contents.menu' . ucfirst($report->getAction())
'Contents.' . Report::PREFIX_ACTION_IN_MENU . ucfirst($report->getAction())
);
}

Expand Down

0 comments on commit 2e38d64

Please sign in to comment.