[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Dispatcher/ -> LegacyComponentDispatcher.php (source)

   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\CMSApplication;
  13  use Joomla\CMS\Language\Text;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('_JEXEC') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Base class for a legacy Joomla Dispatcher
  21   *
  22   * Executes the single entry file of a legacy component.
  23   *
  24   * @since  4.0.0
  25   */
  26  class LegacyComponentDispatcher implements DispatcherInterface
  27  {
  28      /**
  29       * The application instance
  30       *
  31       * @var    CMSApplication
  32       * @since  4.0.0
  33       */
  34      private $app;
  35  
  36      /**
  37       * Constructor for Dispatcher
  38       *
  39       * @param   CMSApplication  $app  The application instance
  40       *
  41       * @since   4.0.0
  42       */
  43      public function __construct(CMSApplication $app)
  44      {
  45          $this->app = $app;
  46      }
  47  
  48      /**
  49       * Dispatch a controller task. Redirecting the user if appropriate.
  50       *
  51       * @return  void
  52       *
  53       * @since   4.0.0
  54       */
  55      public function dispatch()
  56      {
  57          $path = JPATH_COMPONENT . '/' . substr($this->app->scope, 4) . '.php';
  58  
  59          // If component file doesn't exist throw error
  60          if (!is_file($path)) {
  61              throw new \Exception(Text::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'), 404);
  62          }
  63  
  64          $lang = $this->app->getLanguage();
  65  
  66          // Load common and local language files.
  67          $lang->load($this->app->scope, JPATH_BASE) || $lang->load($this->app->scope, JPATH_COMPONENT);
  68  
  69          // Execute the component
  70          $loader = static function ($path) {
  71              require_once $path;
  72          };
  73          $loader($path);
  74      }
  75  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer