From 9860dbcd2023b334915660d0a061c0091f7d480a Mon Sep 17 00:00:00 2001 From: Vedavith Date: Wed, 13 Jul 2022 12:10:55 +0530 Subject: [PATCH 1/3] Reversing Filter::after execution With current functionality, execution of multi filters are sequential. First it runs all the before and later afters. Consider this scenario, If we are walking through 2 doors, we go through door 1 and then door 2 and If we want to walk back, we come through door 2 first and then door 1 and this completely make sense. Similarly, with multiple filters. The last executed before should execute it's after first. --- system/Filters/Filters.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index d5d5e3aae42e..50dc73891a1a 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -161,6 +161,10 @@ public function setResponse(ResponseInterface $response) public function run(string $uri, string $position = 'before') { $this->initialize(strtolower($uri)); + //reversing after filters + if($position === 'after') { + $this->filtersClass[$position] = array_reverse($this->filtersClass[$position]); + } foreach ($this->filtersClass[$position] as $className) { $class = new $className(); @@ -230,7 +234,8 @@ public function initialize(?string $uri = null) $this->processGlobals($uri); $this->processMethods(); $this->processFilters($uri); - + //reversing after filters + $this->filters['after'] = array_reverse($this->filters['after']); // Set the toolbar filter to the last position to be executed if (in_array('toolbar', $this->filters['after'], true) && ($count = count($this->filters['after'])) > 1 From b2e691f96a3b245d512fe6cf3aa7f418a4a084d3 Mon Sep 17 00:00:00 2001 From: Vedavith Date: Wed, 13 Jul 2022 12:57:52 +0530 Subject: [PATCH 2/3] Updated Comments --- system/Filters/Filters.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 50dc73891a1a..49783f71d75c 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -161,7 +161,7 @@ public function setResponse(ResponseInterface $response) public function run(string $uri, string $position = 'before') { $this->initialize(strtolower($uri)); - //reversing after filters + // reversing after filters if($position === 'after') { $this->filtersClass[$position] = array_reverse($this->filtersClass[$position]); } @@ -234,8 +234,6 @@ public function initialize(?string $uri = null) $this->processGlobals($uri); $this->processMethods(); $this->processFilters($uri); - //reversing after filters - $this->filters['after'] = array_reverse($this->filters['after']); // Set the toolbar filter to the last position to be executed if (in_array('toolbar', $this->filters['after'], true) && ($count = count($this->filters['after'])) > 1 From a680c48e2db907206601e9a028bf2c960edbfb12 Mon Sep 17 00:00:00 2001 From: Vedavith Date: Wed, 13 Jul 2022 13:52:17 +0530 Subject: [PATCH 3/3] Fixing PSR issue --- system/Filters/Filters.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 49783f71d75c..6b7756aa9ec7 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -162,7 +162,7 @@ public function run(string $uri, string $position = 'before') { $this->initialize(strtolower($uri)); // reversing after filters - if($position === 'after') { + if ($position === 'after') { $this->filtersClass[$position] = array_reverse($this->filtersClass[$position]); }