Skip to content

Commit 9860dbc

Browse files
authored
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.
1 parent eb83ec8 commit 9860dbc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎system/Filters/Filters.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ public function setResponse(ResponseInterface $response)
161161
public function run(string $uri, string $position = 'before')
162162
{
163163
$this->initialize(strtolower($uri));
164+
//reversing after filters
165+
if($position === 'after') {
166+
$this->filtersClass[$position] = array_reverse($this->filtersClass[$position]);
167+
}
164168

165169
foreach ($this->filtersClass[$position] as $className) {
166170
$class = new $className();
@@ -230,7 +234,8 @@ public function initialize(?string $uri = null)
230234
$this->processGlobals($uri);
231235
$this->processMethods();
232236
$this->processFilters($uri);
233-
237+
//reversing after filters
238+
$this->filters['after'] = array_reverse($this->filters['after']);
234239
// Set the toolbar filter to the last position to be executed
235240
if (in_array('toolbar', $this->filters['after'], true)
236241
&& ($count = count($this->filters['after'])) > 1

0 commit comments

Comments
 (0)