Skip to content

Commit aa2ac38

Browse files
committed
Adding a kernel that loads routes from itself
1 parent 4b94274 commit aa2ac38

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Kernel;
13+
14+
use Symfony\Bundle\FrameworkBundle\Routing\RouteCollectionBuilder;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\DependencyInjection\ContainerBuilder;
17+
use Symfony\Component\HttpKernel\MicroKernel;
18+
use Symfony\Component\Routing\Loader\RouteLoaderInterface;
19+
20+
/**
21+
* A kernel that adds some functionality that depends on FrameworkBundle.
22+
*
23+
* @author Ryan Weaver <ryan@knpuniversity.com>
24+
*/
25+
abstract class FrameworkKernel extends MicroKernel implements RouteLoaderInterface
26+
{
27+
/**
28+
* Add or import routes into your application.
29+
*
30+
* $routes->import('config/routing.yml');
31+
* $routes->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard');
32+
*
33+
* @param RouteCollectionBuilder $routes
34+
* @return void
35+
*/
36+
abstract protected function configureRoutes(RouteCollectionBuilder $routes);
37+
38+
/**
39+
* Creates a RouteCollectionBuilder for convenience and calls configureRoutes.
40+
*
41+
* @param LoaderInterface $loader
42+
* @return \Symfony\Component\Routing\RouteCollection
43+
*/
44+
public function getRouteCollection(LoaderInterface $loader)
45+
{
46+
$routes = new RouteCollectionBuilder($loader);
47+
$routes->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard');
48+
49+
$this->configureRoutes($routes);
50+
51+
return $routes->build();
52+
}
53+
54+
/**
55+
* Overridden to make the routing resource be the kernel.
56+
*
57+
* @param LoaderInterface $loader
58+
*/
59+
public function registerContainerConfiguration(LoaderInterface $loader)
60+
{
61+
$loader->load(function (ContainerBuilder $container) {
62+
$container->prependExtensionConfig('framework', array(
63+
'router' => array(
64+
'resource' => 'kernel',
65+
'type' => 'service'
66+
),
67+
));
68+
});
69+
70+
parent::registerContainerConfiguration($loader);
71+
}
72+
}

0 commit comments

Comments
 (0)