- md5
- 48705dca014b7582b48e636ebf80fd63
- sha1
- b533a6880a3e79d3ef1d37bde656f882a5cc3e08
- sha256
- 4ccd18bd57fd7452b7c56c1b0318c94118bc84a8b874b3edca56a3c9b7d23f6f
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\Dispatcher;
defined('_JEXEC') or die;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryFactoryInterface;
use Joomla\Input\Input;
/**
* Base class for a Joomla Dispatcher
*
* Dispatchers are responsible for checking ACL of a component if appropriate and
* choosing an appropriate controller (and if necessary, a task) and executing it.
*
* @since 4.0.0
*/
class Dispatcher implements DispatcherInterface
{
/**
* The URL option for the component.
*
* @var string
* @since 4.0.0
*/
protected $option;
/**
* The application instance
*
* @var CMSApplication
* @since 4.0.0
*/
protected $app;
/**
* The input instance
*
* @var Input
* @since 4.0.0
*/
protected $input;
/**
* The MVC factory
*
* @var MVCFactoryFactoryInterface
*
* @since 4.0.0
*/
private $mvcFactoryFactory;
/**
* Constructor for Dispatcher
*
* @param CMSApplication $app The application instance
* @param Input $input The input instance
* @param MVCFactoryFactoryInterface $mvcFactoryFactory The MVC factory instance
*
* @since 4.0.0
*/
public function __construct(CMSApplication $app, Input $input, MVCFactoryFactoryInterface $mvcFactoryFactory)
{
$this->app = $app;
$this->input = $input;
$this->mvcFactoryFactory = $mvcFactoryFactory;
// If option is not provided, detect it from dispatcher class name, ie ContentDispatcher
if (empty($this->option))
{
$this->option = ComponentHelper::getComponentName(
$this,
str_replace('com_', '', $input->get('option'))
);
}
$this->loadLanguage();
}
/**
* Load the language
*
* @return void
*
* @since 4.0.0
*/
protected function loadLanguage()
{
// Load common and local language files.
$this->app->getLanguage()->load($this->option, JPATH_BASE, null, false, true) ||
$this->app->getLanguage()->load($this->option, JPATH_COMPONENT, null, false, true);
}
/**
* Method to check component access permission
*
* @return void
*
* @since 4.0.0
*/
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->option))
{
throw new NotAllowed($this->app->getLanguage()->_('JERROR_ALERTNOAUTHOR'), 403);
}
}
/**
* Dispatch a controller task. Redirecting the user if appropriate.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch()
{
// Check component access permission
$this->checkAccess();
$command = $this->input->getCmd('task', 'display');
// Check for a controller.task command.
if (strpos($command, '.') !== false)
{
// Explode the controller.task command.
list ($controller, $task) = explode('.', $command);
$this->input->set('controller', $controller);
$this->input->set('task', $task);
}
else
{
// Do we have a controller?
$controller = $this->input->get('controller', 'display');
$task = $command;
}
// Build controller config data
$config['option'] = $this->option;
// Set name of controller if it is passed in the request
if ($this->input->exists('controller'))
{
$config['name'] = strtolower($this->input->get('controller'));
}
// Execute the task for this component
$controller = $this->getController($controller, ucfirst($this->app->getName()), $config);
$controller->execute($task);
$controller->redirect();
}
/**
* The application the dispatcher is working with.
*
* @return CMSApplication
*
* @since 4.0.0
*/
protected function getApplication(): CMSApplication
{
return $this->app;
}
/**
* Get a controller from the component
*
* @param string $name Controller name
* @param string $client Optional client (like Administrator, Site etc.)
* @param array $config Optional controller config
*
* @return BaseController
*
* @since 4.0.0
*/
public function getController(string $name, string $client = '', array $config = array()): BaseController
{
// Set up the client
$client = $client ?: ucfirst($this->app->getName());
// Get the controller instance
$controller = $this->mvcFactoryFactory->createFactory($this->app)->createController(
$name,
$client,
$config,
$this->app,
$this->input
);
// Check if the controller could be created
if (!$controller)
{
throw new \InvalidArgumentException(\JText::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $name));
}
return $controller;
}
}
No other release has this exact content. See every version of this file.