From a54095b71480aa421b1ea0e13507ec94744007c5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 18 Oct 2023 13:50:50 +0900 Subject: [PATCH] refactor: use private methods --- system/Filters/Filters.php | 53 ++++++++------------------------------ 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index c2baa27cbbab..eadf3f2f8e90 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -302,55 +302,24 @@ public function runRequired(string $position = 'before') } } - foreach ($filtersClass[$position] as $className) { - $class = new $className(); - - if (! $class instanceof FilterInterface) { - throw FilterException::forIncorrectInterface(get_class($class)); - } - - if ($position === 'before') { - $result = $class->before( - $this->request, - $this->argumentsClass[$className] ?? null - ); - - if ($result instanceof RequestInterface) { - $this->request = $result; - - continue; - } - - // If the response object was sent back, - // then send it and quit. - if ($result instanceof ResponseInterface) { - // short circuit - bypass any other filters - return $result; - } - // Ignore an empty result - if (empty($result)) { - continue; - } + if ($position === 'before') { + $result = $this->runBefore($filtersClass); + // If the response object was sent back, + // then send it and quit. + if ($result instanceof ResponseInterface) { + // short circuit - bypass any other filters return $result; } - if ($position === 'after') { - $result = $class->after( - $this->request, - $this->response, - $this->argumentsClass[$className] ?? null - ); - - if ($result instanceof ResponseInterface) { - $this->response = $result; + return $result; + } - continue; - } - } + if ($position === 'after') { + $result = $this->runAfter($filtersClass); } - return $position === 'before' ? $this->request : $this->response; + return $result; } /**