From 468a5d33c4c4e491fd3334e907d124dd4ab87d31 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Tue, 26 Jul 2022 22:46:40 +0200 Subject: [PATCH] add custom url redirect for individual implementations --- .php-cs-fixer.php | 2 +- Application/Core/redirectControllerTrait.php | 30 +++++++++++++++---- .../ArticleListController_PRGredirect.php | 2 +- .../ContactController_PRGredirect.php | 2 +- ...ManufacturerListController_PRGredirect.php | 2 +- .../SearchController_PRGredirect.php | 2 +- .../VendorListController_PRGredirect.php | 2 +- composer.json | 1 + 8 files changed, 31 insertions(+), 12 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 244806f..e5e32a0 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -6,7 +6,7 @@ $finder = PhpCsFixer\Finder::create() $config = new PhpCsFixer\Config(); return $config->setRules([ - '@PHP70Migration' => true, + '@PHP71Migration' => true, '@PSR12' => true ]) ->setFinder($finder) diff --git a/Application/Core/redirectControllerTrait.php b/Application/Core/redirectControllerTrait.php index 68ca4de..eb07000 100644 --- a/Application/Core/redirectControllerTrait.php +++ b/Application/Core/redirectControllerTrait.php @@ -23,23 +23,41 @@ trait redirectControllerTrait /** * @return void */ - protected function d3DoPRGRedirect(): void + protected function d3DoPRGSelfRedirect(): void { - if ($this->d3ShouldDoPRGredirect()) { + if ($this->d3SelfRedirectIsConfigured()) { + $this->d3DoPRGCustomRedirect($this->generatePageNavigationUrl()); + } + } + + /** + * @param string $url + * @return void + */ + protected function d3DoPRGCustomRedirect(string $url): void + { + if ($this->d3IsPostRequest()) { /** @var Utils_PRGredirect $utils */ $utils = Registry::getUtils(); $this->setFncName(''); - $utils->d3PrgRedirect($this->generatePageNavigationUrl()); + $utils->d3PrgRedirect($url); } } /** * @return bool */ - protected function d3ShouldDoPRGredirect(): bool + protected function d3IsPostRequest(): bool { - return strtoupper($_SERVER['REQUEST_METHOD']) === 'POST' && - Registry::getConfig()->getConfigParam('d3PRGredirect_'.$this->getClassKey()) === true; + return strtoupper($_SERVER['REQUEST_METHOD']) === 'POST'; + } + + /** + * @return bool + */ + protected function d3SelfRedirectIsConfigured(): bool + { + return Registry::getConfig()->getConfigParam('d3PRGredirect_'.$this->getClassKey()) === true; } } diff --git a/Modules/Application/Controllers/ArticleListController_PRGredirect.php b/Modules/Application/Controllers/ArticleListController_PRGredirect.php index a8a5ef3..186ddd2 100644 --- a/Modules/Application/Controllers/ArticleListController_PRGredirect.php +++ b/Modules/Application/Controllers/ArticleListController_PRGredirect.php @@ -28,7 +28,7 @@ class ArticleListController_PRGredirect extends ArticleListController_PRGredirec { $template = parent::render(); - $this->d3DoPRGRedirect(); + $this->d3DoPRGSelfRedirect(); return $template; } diff --git a/Modules/Application/Controllers/ContactController_PRGredirect.php b/Modules/Application/Controllers/ContactController_PRGredirect.php index 4361785..31d1d16 100644 --- a/Modules/Application/Controllers/ContactController_PRGredirect.php +++ b/Modules/Application/Controllers/ContactController_PRGredirect.php @@ -41,7 +41,7 @@ class ContactController_PRGredirect extends ContactController_PRGredirect_parent $template = parent::render(); if ($this->success !== false) { - $this->d3DoPRGRedirect(); + $this->d3DoPRGSelfRedirect(); } return $template; diff --git a/Modules/Application/Controllers/ManufacturerListController_PRGredirect.php b/Modules/Application/Controllers/ManufacturerListController_PRGredirect.php index 5053691..94b5c43 100644 --- a/Modules/Application/Controllers/ManufacturerListController_PRGredirect.php +++ b/Modules/Application/Controllers/ManufacturerListController_PRGredirect.php @@ -28,7 +28,7 @@ class ManufacturerListController_PRGredirect extends ManufacturerListController_ { $template = parent::render(); - $this->d3DoPRGRedirect(); + $this->d3DoPRGSelfRedirect(); return $template; } diff --git a/Modules/Application/Controllers/SearchController_PRGredirect.php b/Modules/Application/Controllers/SearchController_PRGredirect.php index fab7956..4e29904 100644 --- a/Modules/Application/Controllers/SearchController_PRGredirect.php +++ b/Modules/Application/Controllers/SearchController_PRGredirect.php @@ -28,7 +28,7 @@ class SearchController_PRGredirect extends SearchController_PRGredirect_parent { $template = parent::render(); - $this->d3DoPRGRedirect(); + $this->d3DoPRGSelfRedirect(); return $template; } diff --git a/Modules/Application/Controllers/VendorListController_PRGredirect.php b/Modules/Application/Controllers/VendorListController_PRGredirect.php index 7b267c8..c236c50 100644 --- a/Modules/Application/Controllers/VendorListController_PRGredirect.php +++ b/Modules/Application/Controllers/VendorListController_PRGredirect.php @@ -28,7 +28,7 @@ class VendorListController_PRGredirect extends VendorListController_PRGredirect_ { $template = parent::render(); - $this->d3DoPRGRedirect(); + $this->d3DoPRGSelfRedirect(); return $template; } diff --git a/composer.json b/composer.json index bcea676..bac160c 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "GPL-3.0-or-later" ], "require": { + "php": ">=7.1", "oxid-esales/oxideshop-ce": "6.3 - 6.10" }, "require-dev": {