| Current Path : /home/opticamezl/www/newok/ |
| Current File : /home/opticamezl/www/newok/Dispatcher.tar |
Dispatcher.php 0000644 00000002630 15165333017 0007350 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\Input\Input;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base class for a Joomla Dispatcher
*
* @since 4.0.0
*/
abstract class Dispatcher implements DispatcherInterface
{
/**
* The application instance
*
* @var CMSApplicationInterface
* @since 4.0.0
*/
protected $app;
/**
* The input instance
*
* @var Input
* @since 4.0.0
*/
protected $input;
/**
* Constructor for Dispatcher
*
* @param CMSApplicationInterface $app The application instance
* @param Input $input The input instance
*
* @since 4.0.0
*/
public function __construct(CMSApplicationInterface $app, Input $input)
{
$this->app = $app;
$this->input = $input;
}
/**
* The application the dispatcher is working with.
*
* @return CMSApplicationInterface
*
* @since 4.0.0
*/
protected function getApplication(): CMSApplicationInterface
{
return $this->app;
}
}
ComponentDispatcherFactoryInterface.php 0000644 00000001714 15172625773 0014421 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\Input\Input;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Component dispatcher factory interface
*
* @since 4.0.0
*/
interface ComponentDispatcherFactoryInterface
{
/**
* Creates a dispatcher.
*
* @param CMSApplicationInterface $application The application
* @param Input $input The input object, defaults to the one in the application
*
* @return DispatcherInterface
*
* @since 4.0.0
*/
public function createDispatcher(CMSApplicationInterface $application, Input $input = null): DispatcherInterface;
}
ComponentDispatcher.php 0000644 00000012127 15172625773 0011250 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Access\Exception\NotAllowed;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Input\Input;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base class for a Joomla Component 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 ComponentDispatcher extends Dispatcher
{
/**
* The URL option for the component.
*
* @var string
* @since 4.0.0
*/
protected $option;
/**
* The MVC factory
*
* @var MVCFactoryInterface
*
* @since 4.0.0
*/
protected $mvcFactory;
/**
* Constructor for ComponentDispatcher
*
* @param CMSApplicationInterface $app The application instance
* @param Input $input The input instance
* @param MVCFactoryInterface $mvcFactory The MVC factory instance
*
* @since 4.0.0
*/
public function __construct(CMSApplicationInterface $app, Input $input, MVCFactoryInterface $mvcFactory)
{
parent::__construct($app, $input);
$this->mvcFactory = $mvcFactory;
// 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) ||
$this->app->getLanguage()->load($this->option, JPATH_COMPONENT);
}
/**
* 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();
}
/**
* 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 = []): BaseController
{
// Set up the client
$client = $client ?: ucfirst($this->app->getName());
// Get the controller instance
$controller = $this->mvcFactory->createController(
$name,
$client,
$config,
$this->app,
$this->input
);
// Check if the controller could be created
if (!$controller) {
throw new \InvalidArgumentException(Text::sprintf('JLIB_APPLICATION_ERROR_INVALID_CONTROLLER_CLASS', $name));
}
return $controller;
}
}
AbstractModuleDispatcher.php 0000644 00000007176 15172625773 0012227 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Input\Input;
use Joomla\Registry\Registry;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base class for a Joomla Module Dispatcher.
*
* @since 4.0.0
*/
abstract class AbstractModuleDispatcher extends Dispatcher
{
/**
* The module instance
*
* @var \stdClass
* @since 4.0.0
*/
protected $module;
/**
* Constructor for Dispatcher
*
* @param \stdClass $module The module
* @param CMSApplicationInterface $app The application instance
* @param Input $input The input instance
*
* @since 4.0.0
*/
public function __construct(\stdClass $module, CMSApplicationInterface $app, Input $input)
{
parent::__construct($app, $input);
$this->module = $module;
}
/**
* Runs the dispatcher.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch()
{
$this->loadLanguage();
$displayData = $this->getLayoutData();
// Stop when display data is false
if ($displayData === false) {
return;
}
// Execute the layout without the module context
$loader = static function (array $displayData) {
// If $displayData doesn't exist in extracted data, unset the variable.
if (!\array_key_exists('displayData', $displayData)) {
extract($displayData);
unset($displayData);
} else {
extract($displayData);
}
/**
* Extracted variables
* -----------------
* @var \stdClass $module
* @var Registry $params
*/
require ModuleHelper::getLayoutPath($module->module, $params->get('layout', 'default'));
};
$loader($displayData);
}
/**
* Returns the layout data. This function can be overridden by subclasses to add more
* attributes for the layout.
*
* If false is returned, then it means that the dispatch process should be stopped.
*
* @return array|false
*
* @since 4.0.0
*/
protected function getLayoutData()
{
return [
'module' => $this->module,
'app' => $this->app,
'input' => $this->input,
'params' => new Registry($this->module->params),
'template' => $this->app->getTemplate(),
];
}
/**
* Load the language.
*
* @return void
*
* @since 4.0.0
*/
protected function loadLanguage()
{
$language = $this->app->getLanguage();
$coreLanguageDirectory = JPATH_BASE;
$extensionLanguageDirectory = JPATH_BASE . '/modules/' . $this->module->module;
$langPaths = $language->getPaths();
// Only load the module's language file if it hasn't been already
if (!$langPaths || (!isset($langPaths[$coreLanguageDirectory]) && !isset($langPaths[$extensionLanguageDirectory]))) {
// 1.5 or Core then 1.6 3PD
$language->load($this->module->module, $coreLanguageDirectory) ||
$language->load($this->module->module, $extensionLanguageDirectory);
}
}
}
ModuleDispatcher.php 0000644 00000002561 15172625773 0010534 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base class for a Joomla Module Dispatcher
*
* Executes the single entry file of a module.
*
* @since 4.0.0
*/
class ModuleDispatcher extends AbstractModuleDispatcher
{
/**
* Dispatches the dispatcher.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch()
{
$path = JPATH_BASE . '/modules/' . $this->module->module . '/' . $this->module->module . '.php';
if (!is_file($path)) {
return;
}
$this->loadLanguage();
// Execute the layout without the module context
$loader = static function ($path, array $displayData) {
// If $displayData doesn't exist in extracted data, unset the variable.
if (!\array_key_exists('displayData', $displayData)) {
extract($displayData);
unset($displayData);
} else {
extract($displayData);
}
include $path;
};
$loader($path, $this->getLayoutData());
}
}
ModuleDispatcherFactoryInterface.php 0000644 00000002033 15172625773 0013677 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\Input\Input;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Module dispatcher factory interface
*
* @since 4.0.0
*/
interface ModuleDispatcherFactoryInterface
{
/**
* Creates a dispatcher.
*
* @param \stdClass $module The module
* @param CMSApplicationInterface $application The application
* @param Input $input The input object, defaults to the one in the application
*
* @return DispatcherInterface
*
* @since 4.0.0
*/
public function createDispatcher(\stdClass $module, CMSApplicationInterface $application, Input $input = null): DispatcherInterface;
}
ModuleDispatcherFactory.php 0000644 00000003610 15172625773 0012060 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\Input\Input;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Namespace based implementation of the ModuleDispatcherFactoryInterface
*
* @since 4.0.0
*/
class ModuleDispatcherFactory implements ModuleDispatcherFactoryInterface
{
/**
* The extension namespace
*
* @var string
*
* @since 4.0.0
*/
private $namespace;
/**
* ModuleDispatcherFactory constructor.
*
* @param string $namespace The namespace
*
* @since 4.0.0
*/
public function __construct(string $namespace)
{
$this->namespace = $namespace;
}
/**
* Creates a dispatcher.
*
* @param \stdClass $module The module
* @param CMSApplicationInterface $application The application
* @param Input $input The input object, defaults to the one in the application
*
* @return DispatcherInterface
*
* @since 4.0.0
*/
public function createDispatcher(\stdClass $module, CMSApplicationInterface $application, Input $input = null): DispatcherInterface
{
$name = 'Site';
if ($application->isClient('administrator')) {
$name = 'Administrator';
}
$className = '\\' . trim($this->namespace, '\\') . '\\' . $name . '\\Dispatcher\\Dispatcher';
if (!class_exists($className)) {
$className = ModuleDispatcher::class;
}
return new $className($module, $application, $input ?: $application->getInput());
}
}
LegacyComponentDispatcher.php 0000644 00000003377 15172625773 0012404 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base class for a legacy Joomla Dispatcher
*
* Executes the single entry file of a legacy component.
*
* @since 4.0.0
*/
class LegacyComponentDispatcher implements DispatcherInterface
{
/**
* The application instance
*
* @var CMSApplication
* @since 4.0.0
*/
private $app;
/**
* Constructor for Dispatcher
*
* @param CMSApplication $app The application instance
*
* @since 4.0.0
*/
public function __construct(CMSApplication $app)
{
$this->app = $app;
}
/**
* Dispatch a controller task. Redirecting the user if appropriate.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch()
{
$path = JPATH_COMPONENT . '/' . substr($this->app->scope, 4) . '.php';
// If component file doesn't exist throw error
if (!is_file($path)) {
throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'), 404);
}
$lang = $this->app->getLanguage();
// Load common and local language files.
$lang->load($this->app->scope, JPATH_BASE) || $lang->load($this->app->scope, JPATH_COMPONENT);
// Execute the component
$loader = static function ($path) {
require_once $path;
};
$loader($path);
}
}
ComponentDispatcherFactory.php 0000644 00000004335 15172625773 0012602 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\Input\Input;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Namespace based implementation of the ComponentDispatcherFactoryInterface
*
* @since 4.0.0
*/
class ComponentDispatcherFactory implements ComponentDispatcherFactoryInterface
{
/**
* The extension namespace
*
* @var string
*
* @since 4.0.0
*/
protected $namespace;
/**
* The MVC factory
*
* @var MVCFactoryInterface
*
* @since 4.0.0
*/
private $mvcFactory;
/**
* ComponentDispatcherFactory constructor.
*
* @param string $namespace The namespace
* @param MVCFactoryInterface $mvcFactory The MVC factory
*
* @since 4.0.0
*/
public function __construct(string $namespace, MVCFactoryInterface $mvcFactory)
{
$this->namespace = $namespace;
$this->mvcFactory = $mvcFactory;
}
/**
* Creates a dispatcher.
*
* @param CMSApplicationInterface $application The application
* @param Input $input The input object, defaults to the one in the application
*
* @return DispatcherInterface
*
* @since 4.0.0
*/
public function createDispatcher(CMSApplicationInterface $application, Input $input = null): DispatcherInterface
{
$name = ucfirst($application->getName());
$className = '\\' . trim($this->namespace, '\\') . '\\' . $name . '\\Dispatcher\\Dispatcher';
if (!class_exists($className)) {
if ($application->isClient('api')) {
$className = ApiDispatcher::class;
} else {
$className = ComponentDispatcher::class;
}
}
return new $className($application, $input ?: $application->getInput(), $this->mvcFactory);
}
}
DispatcherInterface.php 0000644 00000001117 15172625773 0011203 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2005 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Joomla Platform CMS Dispatcher Interface
*
* @since 4.0.0
*/
interface DispatcherInterface
{
/**
* Runs the dispatcher.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch();
}
ApiDispatcher.php 0000644 00000003464 15172625773 0010023 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Dispatcher;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* API Implementation for our dispatcher. It loads a component's administrator language files, and calls the API
* Controller so that components that haven't implemented web services can add their own handling.
*
* @since 4.0.0
*/
final class ApiDispatcher extends ComponentDispatcher
{
/**
* Load the component's administrator language
*
* @since 4.0.0
*
* @return void
*/
protected function loadLanguage()
{
// Load common and local language files.
$this->app->getLanguage()->load($this->option, JPATH_BASE) ||
$this->app->getLanguage()->load($this->option, JPATH_ADMINISTRATOR) ||
$this->app->getLanguage()->load($this->option, JPATH_COMPONENT_ADMINISTRATOR);
}
/**
* Dispatch a controller task. API Overrides to ensure there is no redirects.
*
* @return void
*
* @since 4.0.0
*/
public function dispatch()
{
$task = $this->input->getCmd('task', 'display');
// 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'));
}
$controller = $this->input->get('controller');
$controller = $this->getController($controller, ucfirst($this->app->getName()), $config);
$controller->execute($task);
}
}