Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4d24d2b
Deprecate getting the router by the app and introduce a service
laoneo Jan 14, 2022
0a16752
also api
laoneo Jan 14, 2022
cfbe216
cs
laoneo Jan 14, 2022
686a060
Update libraries/src/Application/SiteApplication.php
laoneo Jan 15, 2022
f869288
Update libraries/src/Router/Router.php
laoneo Jan 15, 2022
65a5508
Update libraries/src/Service/Provider/Router.php
laoneo Jan 15, 2022
3f07da2
Update components/com_finder/src/View/Search/HtmlView.php
laoneo Jan 15, 2022
57c66aa
Update libraries/src/Application/ConsoleApplication.php
laoneo Jan 15, 2022
f136660
Update libraries/src/Application/CMSApplication.php
laoneo Jan 15, 2022
bcdbd57
Update libraries/src/Application/CMSWebApplicationInterface.php
laoneo Jan 15, 2022
6f1c027
injection
laoneo Jan 15, 2022
c83bff8
comments
laoneo Jan 15, 2022
20f51aa
Update libraries/src/Router/SiteRouterAwareTrait.php
laoneo Jan 16, 2022
f423e36
Update libraries/src/Application/SiteApplication.php
laoneo Jan 16, 2022
ca15b4a
fallback to app router
laoneo Jan 19, 2022
b67cc3f
Merge branch 'j4/router/deprecate-app' of github.com:Digital-Peak/joo…
laoneo Jan 19, 2022
73c336a
Merge remote-tracking branch 'upstream/4.0-dev' into j4/router/deprec…
laoneo Jan 22, 2022
90ecacf
cs
laoneo Jan 22, 2022
141c762
Merge remote-tracking branch 'upstream/4.0-dev' into j4/router/deprec…
laoneo Jan 24, 2022
7e26664
Merge remote-tracking branch 'upstream/4.2-dev' into j4/router/deprec…
laoneo Jan 25, 2022
3897168
revert
laoneo Jan 25, 2022
4cc3a88
revert
laoneo Jan 25, 2022
63797c6
Merge branch '4.2-dev' into j4/router/deprecate-app
laoneo Feb 4, 2022
82d10dd
Merge branch '4.2-dev' into j4/router/deprecate-app
laoneo Feb 9, 2022
169f768
Merge branch '4.2-dev' into j4/router/deprecate-app
laoneo Feb 23, 2022
60bc771
Merge branch '4.2-dev' into j4/router/deprecate-app
laoneo Feb 25, 2022
51cfca4
Merge branch '4.2-dev' into j4/router/deprecate-app
laoneo Mar 7, 2022
7acfdb8
Merge branch '4.2-dev' into j4/router/deprecate-app
laoneo Mar 10, 2022
f6908c0
catch router not found in installation process
laoneo Mar 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions components/com_finder/src/View/Search/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Profiler\Profiler;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Router\SiteRouterAwareInterface;
use Joomla\CMS\Router\SiteRouterAwareTrait;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Finder\Administrator\Indexer\Query;
use Joomla\Component\Finder\Site\Helper\FinderHelper;
Expand All @@ -30,8 +32,10 @@
*
* @since 2.5
*/
class HtmlView extends BaseHtmlView
class HtmlView extends BaseHtmlView implements SiteRouterAwareInterface
{
use SiteRouterAwareTrait;

/**
* The query indexer object
*
Expand Down Expand Up @@ -159,8 +163,7 @@ public function display($tpl = null)
// Check for a double quote in the query string.
if (strpos($this->query->input, '"'))
{
// Get the application router.
$router = $app->getRouter();
$router = $this->getSiteRouter();

// Fix the q variable in the URL.
if ($router->getVar('q') !== $this->query->input)
Expand Down
3 changes: 2 additions & 1 deletion libraries/src/Application/AdministratorApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ protected function doExecute()
*
* @return Router
*
* @since 3.2
* @since 3.2
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public static function getRouter($name = 'administrator', array $options = array())
{
Expand Down
7 changes: 4 additions & 3 deletions libraries/src/Application/ApiApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function getTemplate($params = false)
*/
protected function route()
{
$router = $this->getApiRouter();
$router = $this->getContainer()->get(ApiRouter::class);

// Trigger the onBeforeApiRoute event.
PluginHelper::importPlugin('webservices');
Expand Down Expand Up @@ -387,11 +387,12 @@ function ($carry, $route) {
*
* @return ApiRouter
*
* @since 4.0.0
* @since 4.0.0
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public function getApiRouter()
{
return $this->getContainer()->get('ApiRouter');
return $this->getContainer()->get(ApiRouter::class);
}

/**
Expand Down
10 changes: 7 additions & 3 deletions libraries/src/Application/CMSApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,9 @@ public function getPathway()
*
* @return Router
*
* @since 3.2
* @since 3.2
*
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public static function getRouter($name = null, array $options = array())
{
Expand Down Expand Up @@ -1056,9 +1058,11 @@ protected function render()
* are then set in the request object to be processed when the application is being
* dispatched.
*
* @return void
* @return void
*
* @since 3.2
* @since 3.2
*
* @deprecated 5.0 Implement the route functionality in the extending class, this here will be removed without replacement
*/
protected function route()
{
Expand Down
4 changes: 3 additions & 1 deletion libraries/src/Application/CMSWebApplicationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public function getMenu($name = null, $options = array());
*
* @return Router
*
* @since 4.0.0
* @since 4.0.0
*
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public static function getRouter($name = null, array $options = array());

Expand Down
7 changes: 5 additions & 2 deletions libraries/src/Application/ConsoleApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,11 @@ public function setName(string $name): void
*
* @return Router
*
* @since 4.0.6
* @throws \InvalidArgumentException
* @since 4.0.6
*
* @throws \InvalidArgumentException
*
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public static function getRouter($name = null, array $options = array())
{
Expand Down
66 changes: 63 additions & 3 deletions libraries/src/Application/SiteApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
use Joomla\CMS\Pathway\Pathway;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Router\SiteRouter;
use Joomla\CMS\Uri\Uri;
use Joomla\DI\Container;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;

/**
* Joomla! Site Application class
Expand Down Expand Up @@ -376,7 +378,9 @@ public function getPathway($name = 'site', $options = array())
*
* @return \Joomla\CMS\Router\Router
*
* @since 3.2
* @since 3.2
*
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public static function getRouter($name = 'site', array $options = array())
{
Expand Down Expand Up @@ -816,8 +820,64 @@ protected function render()
*/
protected function route()
{
// Execute the parent method
parent::route();
// Get the full request URI.
$uri = clone Uri::getInstance();

// It is not possible to inject the SiteRouter as it requires a SiteApplication
// and we would end in an infinite loop
$result = $this->getContainer()->get(SiteRouter::class)->parse($uri, true);

$active = $this->getMenu()->getActive();

if ($active !== null
&& $active->type === 'alias'
&& $active->getParams()->get('alias_redirect')
&& \in_array($this->input->getMethod(), ['GET', 'HEAD'], true))
{
$item = $this->getMenu()->getItem($active->getParams()->get('aliasoptions'));

if ($item !== null)
{
$oldUri = clone Uri::getInstance();

if ($oldUri->getVar('Itemid') == $active->id)
{
$oldUri->setVar('Itemid', $item->id);
}

$base = Uri::base(true);
$oldPath = StringHelper::strtolower(substr($oldUri->getPath(), \strlen($base) + 1));
$activePathPrefix = StringHelper::strtolower($active->route);

$position = strpos($oldPath, $activePathPrefix);

if ($position !== false)
{
$oldUri->setPath($base . '/' . substr_replace($oldPath, $item->route, $position, \strlen($activePathPrefix)));

$this->setHeader('Expires', 'Wed, 17 Aug 2005 00:00:00 GMT', true);
$this->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
$this->setHeader('Cache-Control', 'no-store, no-cache, must-revalidate', false);
$this->sendHeaders();

$this->redirect((string) $oldUri, 301);
}
}
}

foreach ($result as $key => $value)
{
$this->input->def($key, $value);
}

if ($this->isTwoFactorAuthenticationRequired())
{
$this->redirectIfTwoFactorAuthenticationRequired();
}

// Trigger the onAfterRoute event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterRoute');

$Itemid = $this->input->getInt('Itemid', null);
$this->authorise($Itemid);
Expand Down
2 changes: 2 additions & 0 deletions libraries/src/Extension/Service/Provider/MVCFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Form\FormFactoryInterface;
use Joomla\CMS\MVC\Factory\ApiMVCFactory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\SiteRouter;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
Expand Down Expand Up @@ -71,6 +72,7 @@ function (Container $container)

$factory->setFormFactory($container->get(FormFactoryInterface::class));
$factory->setDispatcher($container->get(DispatcherInterface::class));
$factory->setSiteRouter($container->get(SiteRouter::class));

return $factory;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ protected static function createContainer(): Container
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Session)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Toolbar)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\WebAssetRegistry)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\ApiRouter)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\Router)
->registerServiceProvider(new \Joomla\CMS\Service\Provider\User);

return $container;
Expand Down
37 changes: 34 additions & 3 deletions libraries/src/MVC/Factory/MVCFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Joomla\CMS\Form\FormFactoryAwareInterface;
use Joomla\CMS\Form\FormFactoryAwareTrait;
use Joomla\CMS\MVC\Model\ModelInterface;
use Joomla\CMS\Router\SiteRouterAwareInterface;
use Joomla\CMS\Router\SiteRouterAwareTrait;
use Joomla\Event\DispatcherAwareInterface;
use Joomla\Event\DispatcherAwareTrait;
use Joomla\Input\Input;
Expand All @@ -24,9 +26,9 @@
*
* @since 3.10.0
*/
class MVCFactory implements MVCFactoryInterface, FormFactoryAwareInterface, DispatcherAwareInterface
class MVCFactory implements MVCFactoryInterface, FormFactoryAwareInterface, SiteRouterAwareInterface
{
use FormFactoryAwareTrait, DispatcherAwareTrait;
use FormFactoryAwareTrait, DispatcherAwareTrait, SiteRouterAwareTrait;

/**
* The namespace to create the objects from.
Expand Down Expand Up @@ -79,6 +81,7 @@ public function createController($name, $prefix, array $config, CMSApplicationIn
$controller = new $className($config, $this, $app, $input);
$this->setFormFactoryOnObject($controller);
$this->setDispatcherOnObject($controller);
$this->setRouterOnObject($controller);

return $controller;
}
Expand Down Expand Up @@ -124,6 +127,7 @@ public function createModel($name, $prefix = '', array $config = [])
$model = new $className($config, $this);
$this->setFormFactoryOnObject($model);
$this->setDispatcherOnObject($model);
$this->setRouterOnObject($model);

return $model;
}
Expand Down Expand Up @@ -171,6 +175,7 @@ public function createView($name, $prefix = '', $type = '', array $config = [])
$view = new $className($config);
$this->setFormFactoryOnObject($view);
$this->setDispatcherOnObject($view);
$this->setRouterOnObject($view);

return $view;
}
Expand Down Expand Up @@ -286,7 +291,7 @@ private function setFormFactoryOnObject($object)
*
* @return void
*
* @since 4.1.0
* @since __DEPLOY_VERSION__
*/
private function setDispatcherOnObject($object)
{
Expand All @@ -304,4 +309,30 @@ private function setDispatcherOnObject($object)
// Ignore it
}
}

/**
* Sets the internal router on the given object.
*
* @param object $object The object
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
private function setRouterOnObject($object): void
{
if (!$object instanceof SiteRouterAwareInterface)
{
return;
}

try
{
$object->setSiteRouter($this->getSiteRouter());
}
catch (\UnexpectedValueException $e)
{
// Ignore it
}
}
}
12 changes: 9 additions & 3 deletions libraries/src/Router/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\DI\Exception\KeyNotFoundException;

/**
* Route handling class
Expand Down Expand Up @@ -128,9 +129,14 @@ public static function link($client, $url, $xhtml = true, $tls = self::TLS_IGNOR
// Get the router instance, only attempt when a client name is given.
if ($client && !isset(self::$_router[$client]))
{
$app = Factory::getApplication();

self::$_router[$client] = $app->getRouter($client);
try
{
self::$_router[$client] = Factory::getContainer()->get(ucfirst($client) . 'Router') ?: Factory::getApplication()::getRouter($client);
}
catch (KeyNotFoundException $e)
{
self::$_router[$client] = Factory::getApplication()::getRouter($client);
}
}

// Make sure that we have our router
Expand Down
7 changes: 5 additions & 2 deletions libraries/src/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ class Router
*
* @return Router A Router object.
*
* @since 1.5
* @throws \RuntimeException
* @since 1.5
*
* @throws \RuntimeException
*
* @deprecated 5.0 Inject the router or load it from the dependency injection container
*/
public static function getInstance($client, $options = array())
{
Expand Down
30 changes: 30 additions & 0 deletions libraries/src/Router/SiteRouterAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2022 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Router;

\defined('_JEXEC') or die;

/**
* Interface for site router aware classes.
*
* @since __DEPLOY_VERSION__
*/
interface SiteRouterAwareInterface
{
/**
* Set the router to use.
*
* @param SiteRouter $router The router to use.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function setSiteRouter(SiteRouter $router): void;
}
Loading