From 64d69658745f2f52893250a8316065f9efc99f50 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 19 Nov 2023 11:11:56 +0900 Subject: [PATCH] feat: to work even if Config\Filters is not updated --- system/Filters/Filters.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 63aa86e16b70..420de1834c8f 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -262,26 +262,36 @@ private function runAfter(array $filterClasses): ResponseInterface */ public function runRequired(string $position = 'before') { - if (! isset($this->config->required[$position]) || $this->config->required[$position] === []) { - return $position === 'before' ? $this->request : $this->response; + // For backward compatibility. For users who do not update Config\Filters. + if (! isset($this->config->required[$position])) { + $baseConfig = config(BaseFiltersConfig::class); + $filters = $baseConfig->required[$position]; + $aliases = $baseConfig->aliases; + } else { + $filters = $this->config->required[$position]; + $aliases = $this->config->aliases; } + if ($filters === []) { + return $position === 'before' ? $this->request : $this->response; } - // Set the toolbar filter to the last position to be executed - $this->config->required['after'] = $this->setToolbarToLast($this->config->required['after']); + if ($position === 'after') { + // Set the toolbar filter to the last position to be executed + $filters = $this->setToolbarToLast($filters); + } $filterClasses = []; - foreach ($this->config->required[$position] as $alias) { - if (! array_key_exists($alias, $this->config->aliases)) { + foreach ($filters as $alias) { + if (! array_key_exists($alias, $aliases)) { throw FilterException::forNoAlias($alias); } - if (is_array($this->config->aliases[$alias])) { - $filterClasses[$position] = array_merge($filterClasses[$position], $this->config->aliases[$alias]); + if (is_array($aliases[$alias])) { + $filterClasses[$position] = array_merge($filterClasses[$position], $aliases[$alias]); } else { - $filterClasses[$position][] = $this->config->aliases[$alias]; + $filterClasses[$position][] = $aliases[$alias]; } }