8000 [FrameworkBundle] MicroKernelTrait configureRouting(Configurator) by vudaltsov · Pull Request #12688 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] MicroKernelTrait configureRouting(Configurator) #12688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion configuration/front_controllers_and_kernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions configuration/micro_kernel_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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
Expand Down Expand Up @@ -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
-------------------------------------------------------------

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup/flex.rst
Original file line number Diff line number Diff line change
57B8 Expand Up @@ -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):
Expand Down
0