diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index b3399bb3d37b..63aa86e16b70 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -266,25 +266,10 @@ public function runRequired(string $position = 'before') return $position === 'before' ? $this->request : $this->response; } - // Set the toolbar filter to the last position to be executed - $afters = []; - $found = false; - - foreach ($this->config->required['after'] as $alias) { - if ($alias === 'toolbar') { - $found = true; - - continue; - } - - $afters[] = $alias; - } - - if ($found) { - $afters[] = 'toolbar'; } - $this->config->required['after'] = $afters; + // Set the toolbar filter to the last position to be executed + $this->config->required['after'] = $this->setToolbarToLast($this->config->required['after']); $filterClasses = []; @@ -308,6 +293,33 @@ public function runRequired(string $position = 'before') return $this->runAfter($filterClasses[$position]); } + /** + * Set the toolbar filter to the last position to be executed. + * + * @param list $filters `after` filter array + */ + private function setToolbarToLast(array $filters): array + { + $afters = []; + $found = false; + + foreach ($filters as $alias) { + if ($alias === 'toolbar') { + $found = true; + + continue; + } + + $afters[] = $alias; + } + + if ($found) { + $afters[] = 'toolbar'; + } + + return $afters; + } + /** * Runs through our list of filters provided by the configuration * object to get them ready for use, including getting uri masks @@ -342,13 +354,7 @@ public function initialize(?string $uri = null) } // 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 - && $this->filters['after'][$count - 1] !== 'toolbar' - ) { - array_splice($this->filters['after'], array_search('toolbar', $this->filters['after'], true), 1); - $this->filters['after'][] = 'toolbar'; - } + $this->filters['after'] = $this->setToolbarToLast($this->filters['after']); $this->processAliasesToClass('before'); $this->processAliasesToClass('after');