Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 662ceec

Browse filesBrowse files
committed
Adding a kernel that loads routes from itself
1 parent 4b94274 commit 662ceec
Copy full SHA for 662ceec

File tree

Expand file treeCollapse file tree

1 file changed

+71
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+71
-0
lines changed
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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 as BaseMicroKernel;
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 MicroKernel extends BaseMicroKernel 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+
48+
$this->configureRoutes($routes);
49+
50+
return $routes->build();
51+
}
52+
53+
/**
54+
* Overridden to make the routing resource be the kernel.
55+
*
56+
* @param LoaderInterface $loader
57+
*/
58+
public function registerContainerConfiguration(LoaderInterface $loader)
59+
{
60+
$loader->load(function (ContainerBuilder $container) {
61+
$container->prependExtensionConfig('framework', array(
62+
'router' => array(
63+
'resource' => 'kernel',
64+
'type' => 'service'
65+
),
66+
));
67+
});
68+
69+
parent::registerContainerConfiguration($loader);
70+
}
71+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.