Skip to content

Commit

Permalink
fix: Move code to routes command
Browse files Browse the repository at this point in the history
  • Loading branch information
neznaika0 committed Nov 8, 2023
1 parent 674d875 commit 231a748
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
18 changes: 17 additions & 1 deletion system/Commands/Utilities/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];

Expand Down
19 changes: 1 addition & 18 deletions system/Commands/Utilities/Routes/FilterFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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' => [],
Expand Down

0 comments on commit 231a748

Please sign in to comment.