From 11db0afccefe5e2dbff409ffbb8c21660484638a Mon Sep 17 00:00:00 2001 From: Allon Moritz Date: Fri, 2 Mar 2018 09:48:53 +0100 Subject: [PATCH] Simplify dispatcher code and load language files when needed --- libraries/src/Dispatcher/Dispatcher.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libraries/src/Dispatcher/Dispatcher.php b/libraries/src/Dispatcher/Dispatcher.php index 0f108922f4730..177991ff4306a 100644 --- a/libraries/src/Dispatcher/Dispatcher.php +++ b/libraries/src/Dispatcher/Dispatcher.php @@ -12,6 +12,7 @@ use Joomla\CMS\Access\Exception\NotAllowed; use Joomla\CMS\Application\CMSApplication; +use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Form\FormFactoryAwareInterface; use Joomla\CMS\MVC\Controller\BaseController; use Joomla\Input\Input; @@ -82,16 +83,11 @@ public function __construct(CMSApplication $app, Input $input = null) // If option is not provided, detect it from dispatcher class name, ie ContentDispatcher if (empty($this->option)) { - $className = get_class($this); - $pos = strpos($className, 'Dispatcher'); - - if ($pos !== false) - { - $this->option = 'com_' . strtolower(substr($className, 0, $pos)); - } + $this->option = ComponentHelper::getComponentName( + $this, + strtolower(str_replace('Dispatcher', '', get_class($this))) + ); } - - $this->loadLanguage(); } /** @@ -133,6 +129,8 @@ protected function checkAccess() */ public function dispatch() { + $this->loadLanguage(); + // Check component access permission $this->checkAccess();