@@ -302,20 +302,18 @@ other loaders that work the same way:
302
302
* :class: `Symfony\\ Component\\ Routing\\ Loader\\ PhpFileLoader `
303
303
304
304
If you use the :class: `Symfony\\ Component\\ Routing\\ Loader\\ PhpFileLoader ` you
305
- have to provide the name of a PHP file which returns a :class: `Symfony\\ Component\\ Routing\\ RouteCollection `::
305
+ have to provide the name of a PHP file which returns a callable handling a :class: `Symfony\\ Component\\ Routing\\ Loader\\ Configurator\\ RoutingConfigurator `.
306
+ This class allows to chain imports, collections or simple route definition calls::
306
307
307
308
// RouteProvider.php
308
- use Symfony\Component\Routing\RouteCollection;
309
- use Symfony\Component\Routing\Route;
310
-
311
- $routes = new RouteCollection();
312
- $routes->add(
313
- 'route_name',
314
- new Route('/foo', ['_controller' => 'ExampleController'])
315
- );
316
- // ...
309
+ namespace Symfony\Component\Routing\Loader\Configurator;
317
310
318
- return $routes;
311
+ return function (RoutingConfigurator $routes) {
312
+ $routes->add('route_name', '/foo')
313
+ ->controller('ExampleController')
314
+ // ...
315
+ ;
316
+ };
319
317
320
318
Routes as Closures
321
319
..................
@@ -410,7 +408,7 @@ routes with UTF-8 characters:
410
408
411
409
route1 :
412
410
path : /category/{name}
413
- defaults : { _controller: ' App\Controller\DefaultController::category' }
411
+ controller : App\Controller\DefaultController::category
414
412
options :
415
413
utf8 : true
416
414
@@ -422,31 +420,26 @@ routes with UTF-8 characters:
422
420
xsi : schemaLocation =" http://symfony.com/schema/routing
423
421
http://symfony.com/schema/routing/routing-1.0.xsd" >
424
422
425
- <route id =" route1" path =" /category/{name}" >
426
- <default key =" _controller" >App\Controller\DefaultController::category</default >
423
+ <route id =" route1" path =" /category/{name}" controller =" App\Controller\DefaultController::category" >
427
424
<option key =" utf8" >true</option >
428
425
</route >
429
426
</routes >
430
427
431
428
.. code-block :: php
432
429
433
- use Symfony\Component\Routing\RouteCollection;
434
- use Symfony\Component\Routing\Route;
435
-
436
- $routes = new RouteCollection();
437
- $routes->add('route1', new Route('/category/{name}',
438
- [
439
- '_controller' => 'App\Controller\DefaultController::category',
440
- ],
441
- [],
442
- [
443
- 'utf8' => true,
444
- ]
445
- ));
430
+ // config/routes.php
431
+ namespace Symfony\Component\Routing\Loader\Configurator;
446
432
447
- // ...
433
+ use App\Controller\DefaultController;
448
434
449
- return $routes;
435
+ return function (RoutingConfigurator $routes) {
436
+ $routes->add('route1', '/category/{name}')
437
+ ->controller([DefaultController::class, 'category'])
438
+ ->options([
439
+ 'utf8' => true,
440
+ ])
441
+ ;
442
+ };
450
443
451
444
In this route, the ``utf8 `` option set to ``true `` makes Symfony consider the
452
445
``. `` requirement to match any UTF-8 characters instead of just a single
@@ -471,22 +464,22 @@ You can also include UTF-8 strings as routing requirements:
471
464
* @Route(
472
465
* "/category/{name}",
473
466
* name="route2",
474
- * requirements ={"default "="한국어"},
467
+ * defaults ={"name "="한국어"},
475
468
* options={"utf8": true}
476
469
* )
477
470
*/
478
- public function default ()
471
+ public function category ()
479
472
{
480
473
// ...
481
474
}
482
475
483
476
.. code-block :: yaml
484
477
485
478
route2 :
486
- path : /default/{default }
487
- defaults : { _controller: 'App\Controller\DefaultController::default' }
488
- requirements :
489
- default : " 한국어"
479
+ path : /category/{name }
480
+ controller : ' App\Controller\DefaultController::category '
481
+ defaults :
482
+ name : " 한국어"
490
483
options :
491
484
utf8 : true
492
485
@@ -498,34 +491,30 @@ You can also include UTF-8 strings as routing requirements:
498
491
xsi : schemaLocation =" http://symfony.com/schema/routing
499
492
http://symfony.com/schema/routing/routing-1.0.xsd" >
500
493
501
- <route id =" route2" path =" /default/{default}" >
502
- <default key =" _controller" >App\Controller\DefaultController::default</default >
503
- <requirement key =" default" >한국어</requirement >
494
+ <route id =" route2" path =" /category/{name}" controller =" App\Controller\DefaultController::category" >
495
+ <default key =" name" >한국어</default >
504
496
<option key =" utf8" >true</option >
505
497
</route >
506
498
</routes >
507
499
508
500
.. code-block :: php
509
501
510
- use Symfony\Component\Routing\RouteCollection;
511
- use Symfony\Component\Routing\Route;
512
-
513
- $routes = new RouteCollection();
514
- $routes->add('route2', new Route('/default/{default}',
515
- [
516
- '_controller' => 'App\Controller\DefaultController::default',
517
- ],
518
- [
519
- 'default' => '한국어',
520
- ],
521
- [
522
- 'utf8' => true,
523
- ]
524
- ));
525
-
526
- // ...
527
-
528
- return $routes;
502
+ // config/routes.php
503
+ namespace Symfony\Component\Routing\Loader\Configurator;
504
+
505
+ use App\Controller\DefaultController;
506
+
507
+ return function (RoutingConfigurator $routes) {
508
+ $routes->add('route2', '/category/{name}')
509
+ ->controller([DefaultController::class, 'category'])
510
+ ->defaults([
511
+ 'name' => '한국어',
512
+ ])
513
+ ->options([
514
+ 'utf8' => true,
515
+ ])
516
+ ;
517
+ };
529
518
530
519
.. tip ::
531
520
0 commit comments