|
| 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 | + return $routes; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * Configures container extensions. |
| 42 | + * |
| 43 | + * $c->loadFromExtension('framework', array( |
| 44 | + * 'secret' => '%secret%' |
| 45 | + * )); |
| 46 | + * |
| 47 | + * @param ContainerBuilder $c |
| 48 | + * @param LoaderInterface $loader |
| 49 | + */ |
| 50 | + protected function configureExtensions(ContainerBuilder $c, LoaderInterface $loader) |
| 51 | + { |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Adds service definitions to the container. |
| 56 | + * |
| 57 | + * @param ContainerBuilder $c |
| 58 | + * @param LoaderInterface $loader |
| 59 | + */ |
| 60 | + protected function configureServices(ContainerBuilder $c, LoaderInterface $loader) |
| 61 | + { |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * {@inheritdoc} |
| 66 | + */ |
| 67 | + public function registerContainerConfiguration(LoaderInterface $loader) |
| 68 | + { |
| 69 | + $loader->load(function (ContainerBuilder $container) use ($loader) { |
| 70 | + $container->loadFromExtension('framework', array( |
| 71 | + 'router' => array( |
| 72 | + 'resource' => null, |
| 73 | + 'type' => 'file', |
| 74 | + ), |
| 75 | + )); |
| 76 | + |
| 77 | + $this->configureExtensions($container, $loader); |
| 78 | + $this->configureServices($container, $loader); |
| 79 | + |
| 80 | + $container->addResource(new FileResource(__FILE__)); |
| 81 | + }); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * {@inheritdoc} |
| 86 | + */ |
| 87 | + public function boot() |
| 88 | + { |
| 89 | + if (true === $this->booted) { |
| 90 | + return; |
| 91 | + } |
| 92 | + |
| 93 | + parent::boot(); |
| 94 | + |
| 95 | + // 3.0 only |
| 96 | + $this->getContainer()->get('router')->setResource(function () { |
| 97 | + $loader = $this->getContainerLoader($this->getContainer()); |
| 98 | + |
| 99 | + return $this->configureRoutes(new RouteCollectionBuilder($loader))->build(); |
| 100 | + }); |
| 101 | + } |
| 102 | +} |
0 commit comments