[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Dispatcher/ -> ModuleDispatcherFactory.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\CMSApplicationInterface;
  13  use Joomla\Input\Input;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('_JEXEC') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Namespace based implementation of the ModuleDispatcherFactoryInterface
  21   *
  22   * @since  4.0.0
  23   */
  24  class ModuleDispatcherFactory implements ModuleDispatcherFactoryInterface
  25  {
  26      /**
  27       * The extension namespace
  28       *
  29       * @var  string
  30       *
  31       * @since   4.0.0
  32       */
  33      private $namespace;
  34  
  35      /**
  36       * ModuleDispatcherFactory constructor.
  37       *
  38       * @param   string  $namespace  The namespace
  39       *
  40       * @since   4.0.0
  41       */
  42      public function __construct(string $namespace)
  43      {
  44          $this->namespace = $namespace;
  45      }
  46  
  47      /**
  48       * Creates a dispatcher.
  49       *
  50       * @param   \stdClass                $module       The module
  51       * @param   CMSApplicationInterface  $application  The application
  52       * @param   Input                    $input        The input object, defaults to the one in the application
  53       *
  54       * @return  DispatcherInterface
  55       *
  56       * @since   4.0.0
  57       */
  58      public function createDispatcher(\stdClass $module, CMSApplicationInterface $application, Input $input = null): DispatcherInterface
  59      {
  60          $name = 'Site';
  61  
  62          if ($application->isClient('administrator')) {
  63              $name = 'Administrator';
  64          }
  65  
  66          $className = '\\' . trim($this->namespace, '\\') . '\\' . $name . '\\Dispatcher\\Dispatcher';
  67  
  68          if (!class_exists($className)) {
  69              $className = ModuleDispatcher::class;
  70          }
  71  
  72          return new $className($module, $application, $input ?: $application->input);
  73      }
  74  }


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