Skip to content

Commit

Permalink
used RoutingConfigurator in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Jules Pietri committed Mar 5, 2019
1 parent d245b45 commit d73e48a
Show file tree
Hide file tree
Showing 21 changed files with 515 additions and 499 deletions.
97 changes: 43 additions & 54 deletions components/routing.rst
Expand Up @@ -305,17 +305,14 @@ If you use the :class:`Symfony\\Component\\Routing\\Loader\\PhpFileLoader` you
have to provide the name of a PHP file which returns a :class:`Symfony\\Component\\Routing\\RouteCollection`::

// RouteProvider.php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$routes = new RouteCollection();
$routes->add(
'route_name',
new Route('/foo', ['_controller' => 'ExampleController'])
);
// ...
namespace Symfony\Component\Routing\Loader\Configurator;

return $routes;
return function (RoutingConfigurator $routes) {
$routes->add('route_name', '/foo')
->controller('ExampleController')
// ...
;
};

Routes as Closures
..................
Expand Down Expand Up @@ -410,7 +407,7 @@ routes with UTF-8 characters:
route1:
path: /category/{name}
defaults: { _controller: 'App\Controller\DefaultController::category' }
controller: App\Controller\DefaultController::category
options:
utf8: true
Expand All @@ -429,23 +426,19 @@ routes with UTF-8 characters:
.. code-block:: php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
$routes = new RouteCollection();
$routes->add('route1', new Route('/category/{name}',
[
'_controller' => 'App\Controller\DefaultController::category',
],
[],
[
'utf8' => true,
]
));
// config/routes.php
namespace Symfony\Component\Routing\Loader\Configurator;
// ...
use App\Controller\DefaultController;
return $routes;
return function (RoutingConfigurator $routes) {
$routes->add('route1', '/category/{name}')
->controller([DefaultController::class, 'category'])
->options([
'utf8' => true,
])
;
};
In this route, the ``utf8`` option set to ``true`` makes Symfony consider the
``.`` requirement to match any UTF-8 characters instead of just a single
Expand All @@ -470,22 +463,22 @@ You can also include UTF-8 strings as routing requirements:
* @Route(
* "/category/{name}",
* name="route2",
* requirements={"default"="한국어"},
* defaults={"name"="한국어"},
* options={"utf8": true}
* )
*/
public function default()
public function category()
{
// ...
}
.. code-block:: yaml
route2:
path: /default/{default}
defaults: { _controller: 'App\Controller\DefaultController::default' }
requirements:
default: "한국어"
path: /category/{name}
controller: 'App\Controller\DefaultController::category'
defaults:
name: "한국어"
options:
utf8: true
Expand All @@ -497,34 +490,30 @@ You can also include UTF-8 strings as routing requirements:
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="route2" path="/default/{default}"
controller="App\Controller\DefaultController::default">
<requirement key="default">한국어</requirement>
<route id="route2" path="/category/{name}" controller="App\Controller\DefaultController::category">
<default key="name">한국어</default>
<option key="utf8">true</option>
</route>
</routes>
.. code-block:: php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
$routes = new RouteCollection();
$routes->add('route2', new Route('/default/{default}',
[
'_controller' => 'App\Controller\DefaultController::default',
],
[
'default' => '한국어',
],
[
'utf8' => true,
]
));
// ...
return $routes;
// config/routes.php
namespace Symfony\Component\Routing\Loader\Configurator;
use App\Controller\DefaultController;
return function (RoutingConfigurator $routes) {
$routes->add('route2', '/category/{name}')
->controller([DefaultController::class, 'category'])
->defaults([
'name' => '한국어',
])
->options([
'utf8' => true,
])
;
};
.. tip::

Expand Down
17 changes: 8 additions & 9 deletions controller/error_pages.rst
Expand Up @@ -171,22 +171,21 @@ automatically when installing Twig support):
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="@TwigBundle/Resources/config/routing/errors.xml"
prefix="/_error" />
<import resource="@TwigBundle/Resources/config/routing/errors.xml" prefix="/_error" />
</routes>
.. code-block:: php
// config/routes/dev/twig.php
use Symfony\Component\Routing\RouteCollection;
namespace Symfony\Component\Routing\Loader\Configurator;
$routes = new RouteCollection();
$routes->addCollection(
$loader->import('@TwigBundle/Resources/config/routing/errors.xml')
);
$routes->addPrefix("/_error");
use App\Controller\ArticleController;
return $routes;
return function (RoutingConfigurator $routes) {
$routes->import('@TwigBundle/Resources/config/routing/errors.xml')
->prefix('/_error')
;
};
With this route added, you can use URLs like these to preview the *error* page
for a given status code as HTML or for a given status code and format.
Expand Down
13 changes: 10 additions & 3 deletions controller/service.rst
Expand Up @@ -64,9 +64,16 @@ a service like: ``App\Controller\HelloController::index``:
.. code-block:: php
// config/routes.php
$collection->add('hello', new Route('/hello', [
'_controller' => 'App\Controller\HelloController::index',
], [], [], '', [], ['GET']));
namespace Symfony\Component\Routing\Loader\Configurator;
use App\Controller\HelloController;
return function (RoutingConfigurator $routes) {
$routes->add('hello', '/hello')
->controller(['HelloController::class, 'index'])
->methods(['GET'])
;
};
.. _controller-service-invoke:

Expand Down

0 comments on commit d73e48a

Please sign in to comment.