src/Kernel.php line 19

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use App\DependencyInjection\Compiler\WidgetCompilerPass;
  4. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  5. use Symfony\Component\Config\Loader\LoaderInterface;
  6. use Symfony\Component\Config\Resource\FileResource;
  7. use Symfony\Component\DependencyInjection\ContainerBuilder;
  8. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  9. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  10. class Kernel extends BaseKernel
  11. {
  12.     use MicroKernelTrait;
  13.     private const CONFIG_EXISTS '.{php,xml,yaml,yml}';
  14.     public function registerBundles(): iterable
  15.     {
  16.         $contents = require $this->getProjectDir() . '/config/bundles.php';
  17.         foreach ($contents as $class => $envs) {
  18.             if ($envs[$this->environment] ?? $envs['all'] ?? false) {
  19.                 yield new $class();
  20.             }
  21.         }
  22.     }
  23.     public function build(ContainerBuilder $container)
  24.     {
  25.         parent::build($container);
  26.         $container->addCompilerPass(new WidgetCompilerPass());
  27.     }
  28.     public function getProjectDir(): string
  29.     {
  30.         return \dirname(__DIR__);
  31.     }
  32.     protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader): void
  33.     {
  34.         $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
  35.         $container->setParameter('container.dumper.inline_class_loader',
  36.             \PHP_VERSION_ID 70400 || !ini_get('opcache.preload'));
  37.         $container->setParameter('container.dumper.inline_factories'true);
  38.         $confDir $this->getProjectDir() . '/config';
  39.         $loader->load($confDir '/{packages}/*' self::CONFIG_EXISTS'glob');
  40.         $loader->load($confDir '/{packages}/' $this->environment '/*' self::CONFIG_EXISTS'glob');
  41.         $loader->load($confDir '/{services}' self::CONFIG_EXISTS'glob');
  42.         $loader->load($confDir '/{services}_' $this->environment self::CONFIG_EXISTS'glob');
  43.     }
  44.     protected function configureRoutes(RoutingConfigurator $routes): void
  45.     {
  46.         $confDir $this->getProjectDir() . '/config';
  47.         $routes->import($confDir '/{routes}/' $this->environment '/*' self::CONFIG_EXISTS'glob');
  48.         $routes->import($confDir '/{routes}/*' self::CONFIG_EXISTS'glob');
  49.         $routes->import($confDir '/{routes}' self::CONFIG_EXISTS'glob');
  50.     }
  51. }