CoreFiles by mySites.guru
RouterFactory.php89 lines, 2,130 bytes, from Joomla_4.0.4-Stable-Full_Package.zip
Raw History Compare with 4.0.3
md5
e8ada7699fcaa0194573c323fed819a2
sha1
6a4b36d4005b6d484f432e736255326a312f2893
sha256
09240a05d11aa7e51833ec0e64339c326ffad64a1145bb7f9236a35419b30fa9
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Component\Router;

\defined('_JEXEC') or die;

use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Categories\CategoryFactoryInterface;
use Joomla\CMS\Menu\AbstractMenu;
use Joomla\Database\DatabaseInterface;

/**
 * Default router factory.
 *
 * @since  4.0.0
 */
class RouterFactory implements RouterFactoryInterface
{
	/**
	 * The namespace to create the categories from.
	 *
	 * @var    string
	 * @since  4.0.0
	 */
	private $namespace;

	/**
	 * The category factory
	 *
	 * @var CategoryFactoryInterface
	 *
	 * @since  4.0.0
	 */
	private $categoryFactory;

	/**
	 * The db
	 *
	 * @var DatabaseInterface
	 *
	 * @since  4.0.0
	 */
	private $db;

	/**
	 * The namespace must be like:
	 * Joomla\Component\Content
	 *
	 * @param   string                    $namespace        The namespace
	 * @param   CategoryFactoryInterface  $categoryFactory  The category object
	 * @param   DatabaseInterface         $db               The database object
	 *
	 * @since   4.0.0
	 */
	public function __construct($namespace, CategoryFactoryInterface $categoryFactory = null, DatabaseInterface $db = null)
	{
		$this->namespace       = $namespace;
		$this->categoryFactory = $categoryFactory;
		$this->db              = $db;
	}

	/**
	 * Creates a router.
	 *
	 * @param   CMSApplicationInterface  $application  The application
	 * @param   AbstractMenu             $menu         The menu object to work with
	 *
	 * @return  RouterInterface
	 *
	 * @since   4.0.0
	 */
	public function createRouter(CMSApplicationInterface $application, AbstractMenu $menu): RouterInterface
	{
		$className = trim($this->namespace, '\\') . '\\' . ucfirst($application->getName()) . '\\Service\\Router';

		if (!class_exists($className))
		{
			throw new \RuntimeException('No router available for this application.');
		}

		return new $className($application, $menu, $this->categoryFactory, $this->db);
	}
}

The same content is in 51 releases, Joomla 4.0.0-beta6 to 4.2.0-beta2. See them all, or every version of this file.