diff --git a/administrator/components/com_postinstall/dispatcher.php b/administrator/components/com_postinstall/dispatcher.php index f73a0f03fa763..31faa4a7d3e20 100644 --- a/administrator/components/com_postinstall/dispatcher.php +++ b/administrator/components/com_postinstall/dispatcher.php @@ -9,9 +9,7 @@ defined('_JEXEC') or die; -use Joomla\CMS\Application\CMSApplication; use Joomla\CMS\Dispatcher\Dispatcher; -use Joomla\CMS\Mvc\Factory\MvcFactoryInterface; /** * Dispatcher class for com_postinstall diff --git a/libraries/src/CMS/Application/CMSApplication.php b/libraries/src/CMS/Application/CMSApplication.php index ab2e791308e68..4d700a83af663 100644 --- a/libraries/src/CMS/Application/CMSApplication.php +++ b/libraries/src/CMS/Application/CMSApplication.php @@ -29,7 +29,7 @@ * * @since 3.2 */ -abstract class CmsApplication extends WebApplication implements ContainerAwareInterface +abstract class CMSApplication extends WebApplication implements ContainerAwareInterface { use ContainerAwareTrait; diff --git a/libraries/src/CMS/Component/ComponentHelper.php b/libraries/src/CMS/Component/ComponentHelper.php index eeb8d5566c505..08685145cb413 100644 --- a/libraries/src/CMS/Component/ComponentHelper.php +++ b/libraries/src/CMS/Component/ComponentHelper.php @@ -376,8 +376,6 @@ public static function renderComponent($option, $params = array()) throw new \LogicException(\JText::sprintf('JLIB_APPLICATION_ERROR_APPLICATION_LOAD', $option), 500); } - $namespace = self::getComponent($option)->namespace; - // Dispatch the component. $contents = static::dispatchComponent(new $class($app, $app->input)); } diff --git a/libraries/src/CMS/Dispatcher/Dispatcher.php b/libraries/src/CMS/Dispatcher/Dispatcher.php index a65f95aa9354e..6c799e6a990a6 100644 --- a/libraries/src/CMS/Dispatcher/Dispatcher.php +++ b/libraries/src/CMS/Dispatcher/Dispatcher.php @@ -25,6 +25,14 @@ */ abstract class Dispatcher implements DispatcherInterface { + /** + * The URL option for the component. + * + * @var string + * @since 1.6 + */ + protected $option; + /** * The extension namespace * @@ -68,7 +76,19 @@ public function __construct(CMSApplication $app, \JInput $input = null) } $this->app = $app; - $this->input = $input ? $input : $app->input; + $this->input = $input ?: $app->input; + + // 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->loadLanguage(); } @@ -83,8 +103,8 @@ public function __construct(CMSApplication $app, \JInput $input = null) protected function loadLanguage() { // Load common and local language files. - $this->app->getLanguage()->load($this->app->scope, JPATH_BASE, null, false, true) || - $this->app->getLanguage()->load($this->app->scope, JPATH_COMPONENT, null, false, true); + $this->app->getLanguage()->load($this->option, JPATH_BASE, null, false, true) || + $this->app->getLanguage()->load($this->option, JPATH_COMPONENT, null, false, true); } /** @@ -97,7 +117,7 @@ protected function loadLanguage() protected function checkAccess() { // Check the user has permission to access this component if in the backend - if ($this->app->isClient('administrator') && !$this->app->getIdentity()->authorise('core.manage', $this->app->scope)) + if ($this->app->isClient('administrator') && !$this->app->getIdentity()->authorise('core.manage', $this->option)) { throw new Notallowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403); } @@ -134,7 +154,7 @@ public function dispatch() } // Build controller config data - $config['option'] = $this->app->scope; + $config['option'] = $this->option; // Set name of controller if it is passed in the request if ($this->input->exists('controller'))