Skip to content

Commit d140c61

Browse files
committed
added a micro kernel
1 parent a76eae8 commit d140c61

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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\Component\HttpKernel;
13+
14+
use Symfony\Bundle\FrameworkBundle\Routing\RouteCollectionBuilder;
15+
use Symfony\Component\Config\Loader\LoaderInterface;
16+
use Symfony\Component\Config\Resource\FileResource;
17+
use Symfony\Component\DependencyInjection\ContainerBuilder;
18+
19+
/**
20+
* A Kernel that provides configuration hooks.
21+
*
22+
* @author Ryan Weaver <ryan@knpuniversity.com>
23+
* @author Fabien Potencier <fabien@symfony.com>
24+
*/
25+
abstract class MicroKernel extends Kernel
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+
*/
35+
protected function configureRoutes(RouteCollectionBuilder $routes)
36+
{
37+
}
38+
39+
/**
40+
* Configures container extensions.
41+
*
42+
* $c->loadFromExtension('framework', array(
43+
* 'secret' => '%secret%'
44+
* ));
45+
*
46+
* @param ContainerBuilder $c
47+
* @param LoaderInterface $loader
48+
*/
49+
protected function configureExtensions(ContainerBuilder $c, LoaderInterface $loader)
50+
{
51+
}
52+
53+
/**
54+
* Adds service definitions to the container.
55+
*
56+
* @param ContainerBuilder $c
57+
* @param LoaderInterface $loader
58+
*/
59+
protected function configureServices(ContainerBuilder $c, LoaderInterface $loader)
60+
{
61+
}
62+
63+
/**
64+
* {@inheritdoc}
65+
*/
66+
public function registerContainerConfiguration(LoaderInterface $loader)
67+
{
68+
$loader->load(function (ContainerBuilder $container) use ($loader) {
69+
$container->loadFromExtension('framework', array(
70+
'router' => array(
71+
'resource' => 'kernel:loadRoutes',
72+
'type' => 'service',
73+
),
74+
));
75+
76+
$this->configureExtensions($container, $loader);
77+
$this->configureServices($container, $loader);
78+
79+
$container->addObjectResource($this);
80+
});
81+
}
82+
83+
private function loadRoutes(LoaderInterface $loader)
84+
{
85+
$routes = new RouteCollectionBuilder($loader);
86+
$this->configureRoutes($routes);
87+
88+
return $routes->build();
89+
}
90+
}

0 commit comments

Comments
 (0)