src/Kernel.php line 20

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.     use MicroKernelTrait;
  11.     private
  12.     const CONFIG_EXTS '.{php,xml,yaml,yml}';
  13.     public function boot(): void {
  14.         parent::boot();
  15.         date_default_timezone_set($this->container->getParameter('date_timezone'));
  16.     }
  17.     public function __construct($environment$debug) {
  18.         parent::__construct($environment$debug);
  19.     }
  20.     public function registerBundles(): iterable {
  21.         $contents = require $this->getProjectDir() . '/config/bundles.php';
  22.         foreach ($contents as $class => $envs) {
  23.             if ($envs[$this->environment] ?? $envs['all'] ?? false) {
  24.                 yield new $class();
  25.             }
  26.         }
  27.     }
  28.     public function getProjectDir(): string {
  29.         return \dirname(__DIR__);
  30.     }
  31.     protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader): void {
  32.         $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
  33.         $container->setParameter('container.dumper.inline_class_loader'true);
  34.         $confDir $this->getProjectDir() . '/config';
  35.         $loader->load($confDir '/{packages}/*' self::CONFIG_EXTS'glob');
  36.         $loader->load($confDir '/{packages}/' $this->environment '/**/*' self::CONFIG_EXTS'glob');
  37.         $loader->load($confDir '/{services}' self::CONFIG_EXTS'glob');
  38.         $loader->load($confDir '/{services}_' $this->environment self::CONFIG_EXTS'glob');
  39.     }
  40.     protected function configureRoutes(RouteCollectionBuilder $routes): void {
  41.         $confDir $this->getProjectDir() . '/config';
  42.         $routes->import($confDir '/{routes}/' $this->environment '/**/*' self::CONFIG_EXTS'/''glob');
  43.         $routes->import($confDir '/{routes}/*' self::CONFIG_EXTS'/''glob');
  44.         $routes->import($confDir '/{routes}' self::CONFIG_EXTS'/''glob');
  45.     }
  46. }