Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] replace app property in SEF plugin #42926

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 9 additions & 17 deletions plugins/system/sef/src/Extension/Sef.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@
*/
final class Sef extends CMSPlugin implements SubscriberInterface
{
/**
* Application object.
*
* @var \Joomla\CMS\Application\CMSApplication
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* Returns an array of CMS events this plugin will listen to and the respective handlers.
*
Expand Down Expand Up @@ -69,7 +61,7 @@ public function onAfterInitialiseRouter(AfterInitialiseRouterEvent $event)
{
if (
is_a($event->getRouter(), SiteRouter::class)
&& $this->app->get('sef_rewrite')
&& $this->getApplication()->get('sef_rewrite')
&& $this->params->get('indexphp')
) {
// Enforce removing index.php with a redirect
Expand All @@ -78,8 +70,8 @@ public function onAfterInitialiseRouter(AfterInitialiseRouterEvent $event)

if (
is_a($event->getRouter(), SiteRouter::class)
&& $this->app->get('sef')
&& !$this->app->get('sef_suffix')
&& $this->getApplication()->get('sef')
&& !$this->getApplication()->get('sef_suffix')
&& $this->params->get('trailingslash')
) {
if ($this->params->get('trailingslash') == 1) {
Expand Down Expand Up @@ -270,7 +262,7 @@ function ($match) use ($base, $protocols) {
public function removeIndexphp(&$router, &$uri)
{
// We only want to redirect on GET requests
if ($this->app->getInput()->getMethod() !== 'GET') {
if ($this->getApplication()->getInput()->getMethod() !== 'GET') {
return;
}

Expand All @@ -279,13 +271,13 @@ public function removeIndexphp(&$router, &$uri)
if (substr($origUri->getPath(), -9) === 'index.php') {
// Remove trailing index.php
$origUri->setPath(substr($origUri->getPath(), 0, -9));
$this->app->redirect($origUri->toString(), 301);
$this->getApplication()->redirect($origUri->toString(), 301);
}

if (substr($origUri->getPath(), \strlen(Uri::base(true)), 11) === '/index.php/') {
// Remove leading index.php
$origUri->setPath(Uri::base(true) . substr($origUri->getPath(), \strlen(Uri::base(true)) + 10));
$this->app->redirect($origUri->toString(), 301);
$this->getApplication()->redirect($origUri->toString(), 301);
}
}

Expand Down Expand Up @@ -340,7 +332,7 @@ public function addTrailingSlash(&$router, &$uri)
public function enforceTrailingSlash(&$router, &$uri)
{
// We only want to redirect on GET requests
if ($this->app->getInput()->getMethod() != 'GET') {
if ($this->getApplication()->getInput()->getMethod() != 'GET') {
return;
}

Expand All @@ -349,11 +341,11 @@ public function enforceTrailingSlash(&$router, &$uri)
if ($this->params->get('trailingslash') == 1 && substr($originalUri->getPath(), -1) == '/' && $originalUri->toString() != Uri::root()) {
// Remove trailingslash
$originalUri->setPath(substr($originalUri->getPath(), 0, -1));
$this->app->redirect($originalUri->toString(), 301);
$this->getApplication()->redirect($originalUri->toString(), 301);
} elseif ($this->params->get('trailingslash') == 2 && substr($originalUri->getPath(), -1) != '/') {
// Add trailingslash
$originalUri->setPath($originalUri->getPath() . '/');
$this->app->redirect($originalUri->toString(), 301);
$this->getApplication()->redirect($originalUri->toString(), 301);
}
}

Expand Down