Skip to content

Commit

Permalink
Merge pull request #8167 from kenjis/fix-spark-routes-useSupportedLoc…
Browse files Browse the repository at this point in the history
…alesOnly

fix: `spark routes` outputs <unknown> only when {locale} with `useSupportedLocalesOnly(true)`
  • Loading branch information
kenjis authored Nov 8, 2023
2 parents 99ef79b + fe5db18 commit 4057489
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions system/Commands/Utilities/Routes/SampleURIGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use CodeIgniter\Config\Services;
use CodeIgniter\Router\RouteCollection;
use Config\App;

/**
* Generate a sample URI path from route key regex.
Expand Down Expand Up @@ -51,6 +52,14 @@ public function get(string $routeKey): string
{
$sampleUri = $routeKey;

if (strpos($routeKey, '{locale}') !== false) {
$sampleUri = str_replace(
'{locale}',
config(App::class)->defaultLocale,
$routeKey
);
}

foreach ($this->routes->getPlaceholders() as $placeholder => $regex) {
$sample = $this->samples[$placeholder] ?? '::unknown::';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public static function provideGet(): iterable
'placeholder num' => ['shop/product/([0-9]+)', 'shop/product/123'],
'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'],
'placeholder any' => ['shop/product/(.*)', 'shop/product/123/abc'],
'locale' => ['{locale}/home', 'en/home'],
'locale segment' => ['{locale}/product/([^/]+)', 'en/product/abc_123'],
'auto route' => ['home/index[/...]', 'home/index/1/2/3/4/5'],
];
}
Expand Down

0 comments on commit 4057489

Please sign in to comment.