Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions libraries/src/Event/Router/AfterInitialiseRouterEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Router;

// phpcs:disable PSR1.Files.SideEffects

\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Event class for AfterInitialiseRouter event
*
* @since __DEPLOY_VERSION__
*/
class AfterInitialiseRouterEvent extends RouterEvent
{
}
70 changes: 70 additions & 0 deletions libraries/src/Event/Router/RouterEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2024 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

namespace Joomla\CMS\Event\Router;

use Joomla\CMS\Event\AbstractImmutableEvent;
use Joomla\CMS\Router\Router;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Class for Application's Router events
*
* @since __DEPLOY_VERSION__
*/
abstract class RouterEvent extends AbstractImmutableEvent
{
/**
* Constructor.
*
* @param string $name The event name.
* @param array $arguments The event arguments.
*
* @throws \BadMethodCallException
*
* @since __DEPLOY_VERSION__
*/
public function __construct($name, array $arguments = [])
{
if (!\array_key_exists('router', $arguments)) {
throw new \BadMethodCallException("Argument 'router' of event {$name} is required but has not been provided");
}

parent::__construct($name, $arguments);
}

/**
* Setter for the router argument.
*
* @param Router $value The value to set
*
* @return Router
*
* @since __DEPLOY_VERSION__
*/
protected function onSetRouter(Router $value): Router
{
return $value;
}

/**
* Get the event's router object
*
* @return Router
*
* @since __DEPLOY_VERSION__
*/
public function getRouter(): Router
{
return $this->arguments['router'];
}
}
9 changes: 8 additions & 1 deletion libraries/src/Service/Provider/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

use Joomla\CMS\Application\ApiApplication;
use Joomla\CMS\Application\SiteApplication;
use Joomla\CMS\Event\Router\AfterInitialiseRouterEvent;
use Joomla\CMS\Router\AdministratorRouter;
use Joomla\CMS\Router\ApiRouter;
use Joomla\CMS\Router\SiteRouter;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -44,7 +46,12 @@ public function register(Container $container)
->share(
SiteRouter::class,
function (Container $container) {
return new SiteRouter($container->get(SiteApplication::class));
$router = new SiteRouter($container->get(SiteApplication::class));
$container->get(DispatcherInterface::class)->dispatch(
'onAfterInitialiseRouter',
new AfterInitialiseRouterEvent('onAfterInitialiseRouter', ['router' => $router])
);
return $router;
},
true
);
Expand Down
2 changes: 0 additions & 2 deletions plugins/system/languagefilter/services/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Joomla\CMS\Factory;
use Joomla\CMS\Language\LanguageFactoryInterface;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\SiteRouter;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
Expand All @@ -41,7 +40,6 @@ function (Container $container) {
Factory::getApplication(),
$container->get(LanguageFactoryInterface::class)
);
$plugin->setSiteRouter($container->get(SiteRouter::class));

return $plugin;
}
Expand Down
44 changes: 39 additions & 5 deletions plugins/system/languagefilter/src/Extension/LanguageFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Joomla\CMS\Application\CMSApplicationInterface;
use Joomla\CMS\Association\AssociationServiceInterface;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Router\AfterInitialiseRouterEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Language\Associations;
Expand All @@ -23,10 +24,12 @@
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Router\Router;
use Joomla\CMS\Router\SiteRouter;
use Joomla\CMS\Router\SiteRouterAwareTrait;
use Joomla\CMS\Uri\Uri;
use Joomla\Component\Menus\Administrator\Helper\MenusHelper;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\SubscriberInterface;
use Joomla\Filesystem\Path;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
Expand All @@ -40,7 +43,7 @@
*
* @since 1.6
*/
final class LanguageFilter extends CMSPlugin
final class LanguageFilter extends CMSPlugin implements SubscriberInterface
{
use SiteRouterAwareTrait;

Expand Down Expand Up @@ -158,15 +161,44 @@ public function __construct(
}

/**
* After initialise.
* Returns an array of CMS events this plugin will listen to and the respective handlers.
*
* @return array
*
* @since __DEPLOY_VERSION__
*/
public static function getSubscribedEvents(): array
{
/**
* Note that onAfterInitialise must be the first handlers to run for this
* plugin to operate as expected. These handlers load compatibility code which
* might be needed by other plugins
*/
return [
'onAfterInitialiseRouter' => 'onAfterInitialiseRouter',
'onAfterDispatch' => 'onAfterDispatch',
'onAfterRoute' => 'onAfterRoute',
'onPrivacyCollectAdminCapabilities' => 'onPrivacyCollectAdminCapabilities',
'onUserAfterSave' => 'onUserAfterSave',
'onUserBeforeSave' => 'onUserBeforeSave',
'onUserLogin' => 'onUserLogin',
];
}

/**
* After initialise router.
*
* @return void
*
* @since 1.6
* @since __DEPLOY_VERSION__
*/
public function onAfterInitialise()
public function onAfterInitialiseRouter(AfterInitialiseRouterEvent $event)
{
$router = $this->getSiteRouter();
$router = $event->getRouter();

if (!is_a($router, SiteRouter::class)) {
return;
}

// Attach build rules for language SEF.
$router->attachBuildRule([$this, 'preprocessBuildRule'], Router::PROCESS_BEFORE);
Expand All @@ -180,6 +212,8 @@ public function onAfterInitialise()

// Attach parse rule.
$router->attachParseRule([$this, 'parseRule'], Router::PROCESS_BEFORE);

$this->setSiteRouter($router);
}

/**
Expand Down