Skip to content

[WIP] Route building in the kernel #15948

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
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
71 changes: 71 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Kernel/MicroKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Kernel;

use Symfony\Bundle\FrameworkBundle\Routing\RouteCollectionBuilder;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\MicroKernel as BaseMicroKernel;
use Symfony\Component\Routing\Loader\RouteLoaderInterface;

/**
* A kernel that adds some functionality that depends on FrameworkBundle.
*
* @author Ryan Weaver <ryan@knpuniversity.com>
*/
abstract class MicroKernel extends BaseMicroKernel implements RouteLoaderInterface
{
/**
* Add or import routes into your application.
*
* $routes->import('config/routing.yml');
* $routes->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard');
*
* @param RouteCollectionBuilder $routes
*/
abstract protected function configureRoutes(RouteCollectionBuilder $routes);

/**
* Creates a RouteCollectionBuilder for convenience and calls configureRoutes.
*
* @param LoaderInterface $loader
*
* @return \Symfony\Component\Routing\RouteCollection
*/
public function getRouteCollection(LoaderInterface $loader)
{
$routes = new RouteCollectionBuilder($loader);

$this->configureRoutes($routes);

return $routes->build();
}

/**
* Overridden to make the routing resource be the kernel.
*
* @param LoaderInterface $loader
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(function (ContainerBuilder $container) {
$container->prependExtensionConfig('framework', array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadFromExtension is enough here as we are always the first to be called.

'router' => array(
'resource' => 'kernel',
'type' => 'service',
),
));
});

parent::registerContainerConfiguration($loader);
}
}