Skip to content

Commit 662ceec

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

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy