From 8a84099800910d65ef376cedfb53d0940719824d Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Mon, 6 Nov 2023 15:28:14 +0300 Subject: [PATCH] fix: Move code to `routes` command --- system/Commands/Utilities/Routes.php | 18 +++++++++++++++++- .../Utilities/Routes/FilterFinder.php | 19 +------------------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/system/Commands/Utilities/Routes.php b/system/Commands/Utilities/Routes.php index 5d20da07d514..a78b6adaf425 100644 --- a/system/Commands/Utilities/Routes.php +++ b/system/Commands/Utilities/Routes.php @@ -18,6 +18,7 @@ use CodeIgniter\Commands\Utilities\Routes\FilterCollector; use CodeIgniter\Commands\Utilities\Routes\SampleURIGenerator; use CodeIgniter\Router\DefinedRouteCollector; +use Config\App; use Config\Feature; use Config\Routing; use Config\Services; @@ -119,7 +120,22 @@ public function run(array $params) foreach ($definedRouteCollector->collect() as $route) { $sampleUri = $uriGenerator->get($route['route']); - $filters = $filterCollector->get($route['method'], $sampleUri); + + // Fix for the search filters command + $isSupportedLocaleOnly = false; + + if (strpos($sampleUri, '{locale}') !== false && Services::routes()->shouldUseSupportedLocalesOnly()) { + $isSupportedLocaleOnly = true; + + $sampleUri = str_replace('{locale}', config(App::class)->defaultLocale, $sampleUri); + } + + $filters = $filterCollector->get($route['method'], $sampleUri); + + if ($isSupportedLocaleOnly) { + $filters['before'] = array_map(static fn ($filter) => '!' . $filter, $filters['before']); + $filters['after'] = array_map(static fn ($filter) => '!' . $filter, $filters['after']); + } $routeName = ($route['route'] === $route['name']) ? 'ยป' : $route['name']; diff --git a/system/Commands/Utilities/Routes/FilterFinder.php b/system/Commands/Utilities/Routes/FilterFinder.php index 7abd0d0d7c7d..cc1f6d2b05f4 100644 --- a/system/Commands/Utilities/Routes/FilterFinder.php +++ b/system/Commands/Utilities/Routes/FilterFinder.php @@ -15,7 +15,6 @@ use CodeIgniter\Filters\Filters; use CodeIgniter\HTTP\Exceptions\RedirectException; use CodeIgniter\Router\Router; -use Config\App; use Config\Feature; use Config\Services; @@ -51,15 +50,6 @@ public function find(string $uri): array { $this->filters->reset(); - // Fix for the search filters command - $isSupportedLocaleOnly = false; - - if (strpos($uri, '{locale}') !== false && Services::routes()->shouldUseSupportedLocalesOnly()) { - $isSupportedLocaleOnly = true; - - $uri = str_replace('{locale}', config(App::class)->defaultLocale, $uri); - } - // Add route filters try { $routeFilters = $this->getRouteFilters($uri); @@ -74,14 +64,7 @@ public function find(string $uri): array $this->filters->initialize($uri); - $filters = $this->filters->getFilters(); - - if ($isSupportedLocaleOnly) { - $filters['before'] = array_map(static fn ($filter) => '!' . $filter, $filters['before']); - $filters['after'] = array_map(static fn ($filter) => '!' . $filter, $filters['after']); - } - - return $filters; + return $this->filters->getFilters(); } catch (RedirectException $e) { return [ 'before' => [],