src/Kernel.php line 50

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