- md5
- 0725065ccc4098bbdedb7f16679dede1
- sha1
- 094d25ac9cd4c4763af69f1c911607c91b901a2e
- sha256
- 1791fd48d2a6a64fbb62f9d3cd4348a97740b47c7f553d23953d6ef259115d25
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2019 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\Application\CMSApplicationInterface;
use Joomla\CMS\Helper\ModuleHelper;
use Joomla\Input\Input;
use Joomla\Registry\Registry;
/**
* 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();
// Abort when display data is false
if ($displayData === false)
{
return;
}
// Execute the layout without the module context
$loader = static function(array $displayData)
{
extract($displayData);
require ModuleHelper::getLayoutPath($displayData['module']->module, $displayData['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 aborted.
*
* @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, null, false, true) ||
$language->load($this->module->module, $extensionLanguageDirectory, null, false, true);
}
}
}
The same content is in 4 releases, Joomla 4.0.0-alpha7 to 4.0.0-alpha10. See them all, or every version of this file.