diff --git a/configuration/front_controllers_and_kernel.rst b/configuration/front_controllers_and_kernel.rst index 42f6dcb2bdc..95fd0445e0b 100644 --- a/configuration/front_controllers_and_kernel.rst +++ b/configuration/front_controllers_and_kernel.rst @@ -85,10 +85,14 @@ you must implement them all: :method:`Symfony\\Component\\HttpKernel\\KernelInterface::registerBundles` It must return an array of all bundles needed to run the application. -:method:`Symfony\\Bundle\\FrameworkBundle\\Kernel\\MicroKernelTrait::configureRoutes` +:method:`Symfony\\Bundle\\FrameworkBundle\\Kernel\\MicroKernelTrait::configureRouting` It adds individual routes or collections of routes to the application (for example loading the routes defined in some config file). +.. versionadded:: 5.1 + + The ``configureRouting`` method was introduced in Symfony 5.1. + :method:`Symfony\\Bundle\\FrameworkBundle\\Kernel\\MicroKernelTrait::configureContainer` It loads the application configuration from config files or using the ``loadFromExtension()`` method and can also register new container parameters diff --git a/configuration/micro_kernel_trait.rst b/configuration/micro_kernel_trait.rst index d43d0bfe591..7b71738ea34 100644 --- a/configuration/micro_kernel_trait.rst +++ b/configuration/micro_kernel_trait.rst @@ -28,7 +28,7 @@ Next, create an ``index.php`` file that defines the kernel class and executes it use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Kernel as BaseKernel; - use Symfony\Component\Routing\RouteCollectionBuilder; + use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; require __DIR__.'/vendor/autoload.php'; @@ -51,7 +51,7 @@ Next, create an ``index.php`` file that defines the kernel class and executes it ]); } - protected function configureRoutes(RouteCollectionBuilder $routes) + protected function configureRouting(RoutingConfigurator $routes): void { // kernel is a service that points to this class // optional 3rd argument is the route name @@ -98,11 +98,15 @@ that define your bundles, your services and your routes: of what you see in a normal ``config/packages/*`` file). You can also register services directly in PHP or load external configuration files (shown below). -**configureRoutes(RouteCollectionBuilder $routes)** +**configureRouting(RoutingConfigurator $routes)** Your job in this method is to add routes to the application. The - ``RouteCollectionBuilder`` has methods that make adding routes in PHP more + ``RoutingConfigurator`` has methods that make adding routes in PHP more fun. You can also load external routing files (shown below). +.. versionadded:: 5.1 + + The ``configureRouting`` method was introduced in Symfony 5.1. + Advanced Example: Twig, Annotations and the Web Debug Toolbar ------------------------------------------------------------- @@ -138,7 +142,7 @@ hold the kernel. Now it looks like this:: use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; - use Symfony\Component\Routing\RouteCollectionBuilder; + use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; class Kernel extends BaseKernel { @@ -171,16 +175,22 @@ hold the kernel. Now it looks like this:: } } - protected function configureRoutes(RouteCollectionBuilder $routes) + protected function configureRouting(RoutingConfigurator $routes): void { // import the WebProfilerRoutes, only if the bundle is enabled if (isset($this->bundles['WebProfilerBundle'])) { - $routes->import('@WebProfilerBundle/Resources/config/routing/wdt.xml', '/_wdt'); - $routes->import('@WebProfilerBundle/Resources/config/routing/profiler.xml', '/_profiler'); + $routes + ->import('@WebProfilerBundle/Resources/config/routing/wdt.xml') + ->prefix('/_wdt') + ; + $routes + ->import('@WebProfilerBundle/Resources/config/routing/profiler.xml') + ->prefix('/_profiler') + ; } // load the annotation routes - $routes->import(__DIR__.'/../src/Controller/', '/', 'annotation'); + $routes->import(__DIR__.'/../src/Controller/', 'annotation'); } // optional, to use the standard Symfony cache directory diff --git a/setup/flex.rst b/setup/flex.rst index 87d40dd6c70..83df0762272 100644 --- a/setup/flex.rst +++ b/setup/flex.rst @@ -107,7 +107,7 @@ manual steps: Make sure that your previous configuration files don't have ``imports`` declarations pointing to resources already loaded by ``Kernel::configureContainer()`` - or ``Kernel::configureRoutes()`` methods. + or ``Kernel::configureRouting()`` methods. #. Move the rest of the ``app/`` contents as follows (and after that, remove the ``app/`` directory):