[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Component/Router/ -> RouterFactory.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.txt
   8   */
   9  
  10  namespace Joomla\CMS\Component\Router;
  11  
  12  use Joomla\CMS\Application\CMSApplicationInterface;
  13  use Joomla\CMS\Categories\CategoryFactoryInterface;
  14  use Joomla\CMS\Menu\AbstractMenu;
  15  use Joomla\Database\DatabaseInterface;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Default router factory.
  23   *
  24   * @since  4.0.0
  25   */
  26  class RouterFactory implements RouterFactoryInterface
  27  {
  28      /**
  29       * The namespace to create the categories from.
  30       *
  31       * @var    string
  32       * @since  4.0.0
  33       */
  34      private $namespace;
  35  
  36      /**
  37       * The category factory
  38       *
  39       * @var CategoryFactoryInterface
  40       *
  41       * @since  4.0.0
  42       */
  43      private $categoryFactory;
  44  
  45      /**
  46       * The db
  47       *
  48       * @var DatabaseInterface
  49       *
  50       * @since  4.0.0
  51       */
  52      private $db;
  53  
  54      /**
  55       * The namespace must be like:
  56       * Joomla\Component\Content
  57       *
  58       * @param   string                    $namespace        The namespace
  59       * @param   CategoryFactoryInterface  $categoryFactory  The category object
  60       * @param   DatabaseInterface         $db               The database object
  61       *
  62       * @since   4.0.0
  63       */
  64      public function __construct($namespace, CategoryFactoryInterface $categoryFactory = null, DatabaseInterface $db = null)
  65      {
  66          $this->namespace       = $namespace;
  67          $this->categoryFactory = $categoryFactory;
  68          $this->db              = $db;
  69      }
  70  
  71      /**
  72       * Creates a router.
  73       *
  74       * @param   CMSApplicationInterface  $application  The application
  75       * @param   AbstractMenu             $menu         The menu object to work with
  76       *
  77       * @return  RouterInterface
  78       *
  79       * @since   4.0.0
  80       */
  81      public function createRouter(CMSApplicationInterface $application, AbstractMenu $menu): RouterInterface
  82      {
  83          $className = trim($this->namespace, '\\') . '\\' . ucfirst($application->getName()) . '\\Service\\Router';
  84  
  85          if (!class_exists($className)) {
  86              throw new \RuntimeException('No router available for this application.');
  87          }
  88  
  89          return new $className($application, $menu, $this->categoryFactory, $this->db);
  90      }
  91  }


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