|
13 | 13 |
|
14 | 14 | namespace CodeIgniter\Router;
|
15 | 15 |
|
| 16 | +use Closure; |
16 | 17 | use CodeIgniter\Config\Factories;
|
17 | 18 | use CodeIgniter\Config\Services;
|
18 | 19 | use CodeIgniter\Exceptions\PageNotFoundException;
|
@@ -69,6 +70,7 @@ private function createRouteCollection(?Routing $routingConfig = null): void
|
69 | 70 | 'posts/(:num)/edit' => 'Blog::edit/$1',
|
70 | 71 | 'books/(:num)/(:alpha)/(:num)' => 'Blog::show/$3/$1',
|
71 | 72 | 'closure/(:num)/(:alpha)' => static fn ($num, $str) => $num . '-' . $str,
|
| 73 | + 'closure-dash/(:num)/(:alpha)' => static fn ($num, $str) => $num . '-' . $str, |
72 | 74 | '{locale}/pages' => 'App\Pages::list_all',
|
73 | 75 | 'test/(:any)/lang/{locale}' => 'App\Pages::list_all',
|
74 | 76 | 'admin/admins' => 'App\Admin\Admins::list_all',
|
@@ -216,6 +218,22 @@ public function testClosures(): void
|
216 | 218 | $this->assertSame($expects, '123-alpha');
|
217 | 219 | }
|
218 | 220 |
|
| 221 | + public function testClosuresWithTranslateURIDashes(): void |
| 222 | + { |
| 223 | + $router = new Router($this->collection, $this->request); |
| 224 | + $router->setTranslateURIDashes(true); |
| 225 | + |
| 226 | + $router->handle('closure-dash/123/alpha'); |
| 227 | + $closure = $router->controllerName(); |
| 228 | + |
| 229 | + $this->assertInstanceOf(Closure::class, $closure); |
| 230 | + |
| 231 | + $expects = $closure(...$router->params()); |
| 232 | + |
| 233 | + $this->assertIsCallable($router->controllerName()); |
| 234 | + $this->assertSame($expects, '123-alpha'); |
| 235 | + } |
| 236 | + |
219 | 237 | public function testAutoRouteFindsDefaultControllerAndMethod(): void
|
220 | 238 | {
|
221 | 239 | $this->collection->setAutoRoute(true);
|
|
0 commit comments