Skip to content

Commit b4eb00a

Browse files
joomdonationlaoneo
andauthored
Improve System - Sef plugin code (#44830)
Co-authored-by: Allon Moritz <[email protected]>
1 parent b2cae37 commit b4eb00a

File tree

1 file changed

+26
-12
lines changed
  • plugins/system/sef/src/Extension

1 file changed

+26
-12
lines changed

plugins/system/sef/src/Extension/Sef.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
namespace Joomla\Plugin\System\Sef\Extension;
1212

13+
use Joomla\CMS\Event\Application\AfterDispatchEvent;
14+
use Joomla\CMS\Event\Application\AfterInitialiseEvent;
15+
use Joomla\CMS\Event\Application\AfterRenderEvent;
16+
use Joomla\CMS\Event\Application\AfterRouteEvent;
1317
use Joomla\CMS\Plugin\CMSPlugin;
1418
use Joomla\CMS\Router\Route;
1519
use Joomla\CMS\Router\Router;
@@ -56,14 +60,16 @@ public static function getSubscribedEvents(): array
5660
/**
5761
* After initialise.
5862
*
63+
* @param AfterInitialiseEvent $event The event instance.
64+
*
5965
* @return void
6066
*
6167
* @since 5.1.0
6268
*/
63-
public function onAfterInitialise()
69+
public function onAfterInitialise(AfterInitialiseEvent $event)
6470
{
6571
$router = $this->getSiteRouter();
66-
$app = $this->getApplication();
72+
$app = $event->getApplication();
6773

6874
if (
6975
$app->get('sef')
@@ -83,13 +89,15 @@ public function onAfterInitialise()
8389
/**
8490
* OnAfterRoute listener
8591
*
92+
* @param AfterRouteEvent $event The event instance.
93+
*
8694
* @return void
8795
*
8896
* @since 5.1.0
8997
*/
90-
public function onAfterRoute()
98+
public function onAfterRoute(AfterRouteEvent $event)
9199
{
92-
$app = $this->getApplication();
100+
$app = $event->getApplication();
93101

94102
// Following code only for Site application, GET requests and HTML documents
95103
if (
@@ -148,15 +156,18 @@ public function onAfterRoute()
148156
/**
149157
* Add the canonical uri to the head.
150158
*
159+
* @param AfterDispatchEvent $event The event instance.
160+
*
151161
* @return void
152162
*
153163
* @since 3.5
154164
*/
155-
public function onAfterDispatch()
165+
public function onAfterDispatch(AfterDispatchEvent $event)
156166
{
157-
$doc = $this->getApplication()->getDocument();
167+
$app = $event->getApplication();
168+
$doc = $app->getDocument();
158169

159-
if (!$this->getApplication()->isClient('site') || $doc->getType() !== 'html') {
170+
if (!$app->isClient('site') || $doc->getType() !== 'html') {
160171
return;
161172
}
162173

@@ -196,20 +207,23 @@ public function onAfterDispatch()
196207
/**
197208
* Convert the site URL to fit to the HTTP request.
198209
*
210+
* @param AfterRenderEvent $event The event instance.
211+
*
199212
* @return void
200213
*/
201-
public function onAfterRender()
214+
public function onAfterRender(AfterRenderEvent $event)
202215
{
203-
if (!$this->getApplication()->isClient('site')) {
216+
$app = $event->getApplication();
217+
if (!$app->isClient('site')) {
204218
return;
205219
}
206220

207221
// Replace src links.
208222
$base = Uri::base(true) . '/';
209-
$buffer = $this->getApplication()->getBody();
223+
$buffer = $app->getBody();
210224

211225
// For feeds we need to search for the URL with domain.
212-
$prefix = $this->getApplication()->getDocument()->getType() === 'feed' ? Uri::root() : '';
226+
$prefix = $app->getDocument()->getType() === 'feed' ? Uri::root() : '';
213227

214228
// Replace index.php URI by SEF URI.
215229
if (strpos($buffer, 'href="' . $prefix . 'index.php?') !== false) {
@@ -305,7 +319,7 @@ function ($match) use ($base, $protocols) {
305319
}
306320

307321
// Use the replaced HTML body.
308-
$this->getApplication()->setBody($buffer);
322+
$app->setBody($buffer);
309323
}
310324

311325
/**

0 commit comments

Comments
 (0)