vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php line 92

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\FrameworkBundle\Kernel;
  11. use Symfony\Component\Config\Loader\LoaderInterface;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  14. use Symfony\Component\Routing\RouteCollectionBuilder;
  15. /**
  16.  * A Kernel that provides configuration hooks.
  17.  *
  18.  * @author Ryan Weaver <ryan@knpuniversity.com>
  19.  * @author Fabien Potencier <fabien@symfony.com>
  20.  */
  21. trait MicroKernelTrait
  22. {
  23.     /**
  24.      * Add or import routes into your application.
  25.      *
  26.      *     $routes->import('config/routing.yml');
  27.      *     $routes->add('/admin', 'App\Controller\AdminController::dashboard', 'admin_dashboard');
  28.      */
  29.     abstract protected function configureRoutes(RouteCollectionBuilder $routes);
  30.     /**
  31.      * Configures the container.
  32.      *
  33.      * You can register extensions:
  34.      *
  35.      *     $container->loadFromExtension('framework', [
  36.      *         'secret' => '%secret%'
  37.      *     ]);
  38.      *
  39.      * Or services:
  40.      *
  41.      *     $container->register('halloween', 'FooBundle\HalloweenProvider');
  42.      *
  43.      * Or parameters:
  44.      *
  45.      *     $container->setParameter('halloween', 'lot of fun');
  46.      */
  47.     abstract protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader);
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public function registerContainerConfiguration(LoaderInterface $loader)
  52.     {
  53.         $loader->load(function (ContainerBuilder $container) use ($loader) {
  54.             $container->loadFromExtension('framework', [
  55.                 'router' => [
  56.                     'resource' => 'kernel::loadRoutes',
  57.                     'type' => 'service',
  58.                 ],
  59.             ]);
  60.             if (!$container->hasDefinition('kernel')) {
  61.                 $container->register('kernel', static::class)
  62.                     ->setSynthetic(true)
  63.                     ->setPublic(true)
  64.                 ;
  65.             }
  66.             $kernelDefinition $container->getDefinition('kernel');
  67.             $kernelDefinition->addTag('routing.route_loader');
  68.             if ($this instanceof EventSubscriberInterface) {
  69.                 $kernelDefinition->addTag('kernel.event_subscriber');
  70.             }
  71.             $this->configureContainer($container$loader);
  72.             $container->addObjectResource($this);
  73.         });
  74.     }
  75.     /**
  76.      * @internal
  77.      */
  78.     public function loadRoutes(LoaderInterface $loader)
  79.     {
  80.         $routes = new RouteCollectionBuilder($loader);
  81.         $this->configureRoutes($routes);
  82.         return $routes->build();
  83.     }
  84. }