[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10 namespace Joomla\CMS\Dispatcher; 11 12 use Joomla\CMS\Application\CMSApplicationInterface; 13 use Joomla\CMS\Helper\ModuleHelper; 14 use Joomla\Input\Input; 15 use Joomla\Registry\Registry; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Base class for a Joomla Module Dispatcher. 23 * 24 * @since 4.0.0 25 */ 26 abstract class AbstractModuleDispatcher extends Dispatcher 27 { 28 /** 29 * The module instance 30 * 31 * @var \stdClass 32 * @since 4.0.0 33 */ 34 protected $module; 35 36 /** 37 * Constructor for Dispatcher 38 * 39 * @param \stdClass $module The module 40 * @param CMSApplicationInterface $app The application instance 41 * @param Input $input The input instance 42 * 43 * @since 4.0.0 44 */ 45 public function __construct(\stdClass $module, CMSApplicationInterface $app, Input $input) 46 { 47 parent::__construct($app, $input); 48 49 $this->module = $module; 50 } 51 52 /** 53 * Runs the dispatcher. 54 * 55 * @return void 56 * 57 * @since 4.0.0 58 */ 59 public function dispatch() 60 { 61 $this->loadLanguage(); 62 63 $displayData = $this->getLayoutData(); 64 65 // Abort when display data is false 66 if ($displayData === false) { 67 return; 68 } 69 70 // Execute the layout without the module context 71 $loader = static function (array $displayData) { 72 // If $displayData doesn't exist in extracted data, unset the variable. 73 if (!\array_key_exists('displayData', $displayData)) { 74 extract($displayData); 75 unset($displayData); 76 } else { 77 extract($displayData); 78 } 79 80 /** 81 * Extracted variables 82 * ----------------- 83 * @var \stdClass $module 84 * @var Registry $params 85 */ 86 87 require ModuleHelper::getLayoutPath($module->module, $params->get('layout', 'default')); 88 }; 89 90 $loader($displayData); 91 } 92 93 /** 94 * Returns the layout data. This function can be overridden by subclasses to add more 95 * attributes for the layout. 96 * 97 * If false is returned, then it means that the dispatch process should be aborted. 98 * 99 * @return array|false 100 * 101 * @since 4.0.0 102 */ 103 protected function getLayoutData() 104 { 105 return [ 106 'module' => $this->module, 107 'app' => $this->app, 108 'input' => $this->input, 109 'params' => new Registry($this->module->params), 110 'template' => $this->app->getTemplate() 111 ]; 112 } 113 114 /** 115 * Load the language. 116 * 117 * @return void 118 * 119 * @since 4.0.0 120 */ 121 protected function loadLanguage() 122 { 123 $language = $this->app->getLanguage(); 124 125 $coreLanguageDirectory = JPATH_BASE; 126 $extensionLanguageDirectory = JPATH_BASE . '/modules/' . $this->module->module; 127 128 $langPaths = $language->getPaths(); 129 130 // Only load the module's language file if it hasn't been already 131 if (!$langPaths || (!isset($langPaths[$coreLanguageDirectory]) && !isset($langPaths[$extensionLanguageDirectory]))) { 132 // 1.5 or Core then 1.6 3PD 133 $language->load($this->module->module, $coreLanguageDirectory) || 134 $language->load($this->module->module, $extensionLanguageDirectory); 135 } 136 } 137 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |