Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d73e48a

Browse filesBrowse files
author
Jules Pietri
committed
used RoutingConfigurator in examples
1 parent d245b45 commit d73e48a
Copy full SHA for d73e48a

21 files changed

+515
-499
lines changed

‎components/routing.rst

Copy file name to clipboardExpand all lines: components/routing.rst
+43-54Lines changed: 43 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,14 @@ If you use the :class:`Symfony\\Component\\Routing\\Loader\\PhpFileLoader` you
305305
have to provide the name of a PHP file which returns a :class:`Symfony\\Component\\Routing\\RouteCollection`::
306306

307307
// 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-
// ...
308+
namespace Symfony\Component\Routing\Loader\Configurator;
317309

318-
return $routes;
310+
return function (RoutingConfigurator $routes) {
311+
$routes->add('route_name', '/foo')
312+
->controller('ExampleController')
313+
// ...
314+
;
315+
};
319316

320317
Routes as Closures
321318
..................
@@ -410,7 +407,7 @@ routes with UTF-8 characters:
410407
411408
route1:
412409
path: /category/{name}
413-
defaults: { _controller: 'App\Controller\DefaultController::category' }
410+
controller: App\Controller\DefaultController::category
414411
options:
415412
utf8: true
416413
@@ -429,23 +426,19 @@ routes with UTF-8 characters:
429426
430427
.. code-block:: php
431428
432-
use Symfony\Component\Routing\RouteCollection;
433-
use Symfony\Component\Routing\Route;
434-
435-
$routes = new RouteCollection();
436-
$routes->add('route1', new Route('/category/{name}',
437-
[
438-
'_controller' => 'App\Controller\DefaultController::category',
439-
],
440-
[],
441-
[
442-
'utf8' => true,
443-
]
444-
));
429+
// config/routes.php
430+
namespace Symfony\Component\Routing\Loader\Configurator;
445431
446-
// ...
432+
use App\Controller\DefaultController;
447433
448-
return $routes;
434+
return function (RoutingConfigurator $routes) {
435+
$routes->add('route1', '/category/{name}')
436+
->controller([DefaultController::class, 'category'])
437+
->options([
438+
'utf8' => true,
439+
])
440+
;
441+
};
449442
450443
In this route, the ``utf8`` option set to ``true`` makes Symfony consider the
451444
``.`` requirement to match any UTF-8 characters instead of just a single
@@ -470,22 +463,22 @@ You can also include UTF-8 strings as routing requirements:
470463
* @Route(
471464
* "/category/{name}",
472465
* name="route2",
473-
* requirements={"default"="한국어"},
466+
* defaults={"name"="한국어"},
474467
* options={"utf8": true}
475468
* )
476469
*/
477-
public function default()
470+
public function category()
478471
{
479472
// ...
480473
}
481474
482475
.. code-block:: yaml
483476
484477
route2:
485-
path: /default/{default}
486-
defaults: { _controller: 'App\Controller\DefaultController::default' }
487-
requirements:
488-
default: "한국어"
478+
path: /category/{name}
479+
controller: 'App\Controller\DefaultController::category'
480+
defaults:
481+
name: "한국어"
489482
options:
490483
utf8: true
491484
@@ -497,34 +490,30 @@ You can also include UTF-8 strings as routing requirements:
497490
xsi:schemaLocation="http://symfony.com/schema/routing
498491
http://symfony.com/schema/routing/routing-1.0.xsd">
499492
500-
<route id="route2" path="/default/{default}"
501-
controller="App\Controller\DefaultController::default">
502-
<requirement key="default">한국어</requirement>
493+
<route id="route2" path="/category/{name}" controller="App\Controller\DefaultController::category">
494+
<default key="name">한국어</default>
503495
<option key="utf8">true</option>
504496
</route>
505497
</routes>
506498
507499
.. code-block:: php
508500
509-
use Symfony\Component\Routing\RouteCollection;
510-
use Symfony\Component\Routing\Route;
511-
512-
$routes = new RouteCollection();
513-
$routes->add('route2', new Route('/default/{default}',
514-
[
515-
'_controller' => 'App\Controller\DefaultController::default',
516-
],
517-
[
518-
'default' => '한국어',
519-
],
520-
[
521-
'utf8' => true,
522-
]
523-
));
524-
525-
// ...
526-
527-
return $routes;
501+
// config/routes.php
502+
namespace Symfony\Component\Routing\Loader\Configurator;
503+
504+
use App\Controller\DefaultController;
505+
506+
return function (RoutingConfigurator $routes) {
507+
$routes->add('route2', '/category/{name}')
508+
->controller([DefaultController::class, 'category'])
509+
->defaults([
510+
'name' => '한국어',
511+
])
512+
->options([
513+
'utf8' => true,
514+
])
515+
;
516+
};
528517
529518
.. tip::
530519

‎controller/error_pages.rst

Copy file name to clipboardExpand all lines: controller/error_pages.rst
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,21 @@ automatically when installing Twig support):
171171
xsi:schemaLocation="http://symfony.com/schema/routing
172172
http://symfony.com/schema/routing/routing-1.0.xsd">
173173
174-
<import resource="@TwigBundle/Resources/config/routing/errors.xml"
175-
prefix="/_error" />
174+
<import resource="@TwigBundle/Resources/config/routing/errors.xml" prefix="/_error" />
176175
</routes>
177176
178177
.. code-block:: php
179178
180179
// config/routes/dev/twig.php
181-
use Symfony\Component\Routing\RouteCollection;
180+
namespace Symfony\Component\Routing\Loader\Configurator;
182181
183-
$routes = new RouteCollection();
184-
$routes->addCollection(
185-
$loader->import('@TwigBundle/Resources/config/routing/errors.xml')
186-
);
187-
$routes->addPrefix("/_error");
182+
use App\Controller\ArticleController;
188183
189-
return $routes;
184+
return function (RoutingConfigurator $routes) {
185+
$routes->import('@TwigBundle/Resources/config/routing/errors.xml')
186+
->prefix('/_error')
187+
;
188+
};
190189
191190
With this route added, you can use URLs like these to preview the *error* page
192191
for a given status code as HTML or for a given status code and format.

‎controller/service.rst

Copy file name to clipboardExpand all lines: controller/service.rst
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,16 @@ a service like: ``App\Controller\HelloController::index``:
6464
.. code-block:: php
6565
6666
// config/routes.php
67-
$collection->add('hello', new Route('/hello', [
68-
'_controller' => 'App\Controller\HelloController::index',
69-
], [], [], '', [], ['GET']));
67+
namespace Symfony\Component\Routing\Loader\Configurator;
68+
69+
use App\Controller\HelloController;
70+
71+
return function (RoutingConfigurator $routes) {
72+
$routes->add('hello', '/hello')
73+
->controller(['HelloController::class, 'index'])
74+
->methods(['GET'])
75+
;
76+
};
7077
7178
.. _controller-service-invoke:
7279

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.