src/Kernel.php line 73

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use App\EventListener\RemoveTagsOnOriginalDeserializeListener;
  4. use Exception;
  5. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  6. use Symfony\Component\Config\Loader\LoaderInterface;
  7. use Symfony\Component\Config\Resource\FileResource;
  8. use Symfony\Component\DependencyInjection\ContainerBuilder;
  9. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  10. class Kernel extends BaseKernel
  11. {
  12.     use MicroKernelTrait;
  13.     public function __construct(string $environmentbool $debug)
  14.     {
  15.         date_default_timezone_set($_ENV['APP_TIMEZONE'] ?? 'UTC');
  16.         parent::__construct($environment$debug);
  17.     }
  18.     private const CONFIG_EXTS '.{php,xml,yaml,yml}';
  19.     public function registerBundles(): iterable
  20.     {
  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.     {
  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', \PHP_VERSION_ID 70400 || $this->debug);
  36.         $container->setParameter('container.dumper.inline_factories'true);
  37.         $confDir $this->getProjectDir().'/config';
  38.         $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS'glob');
  39.         $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS'glob');
  40.         $loader->load($confDir.'/{services}'.self::CONFIG_EXTS'glob');
  41.         $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS'glob');
  42.     }
  43.     protected function configureRouting(\Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator $routes): void
  44.     {
  45.         $confDir $this->getProjectDir().'/config';
  46.         $routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS'/''glob');
  47.         $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS'/''glob');
  48.         $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS'/''glob');
  49.     }
  50.     protected function build(ContainerBuilder $container)
  51.     {
  52.         parent::build($container);
  53.         $container->addCompilerPass(new RemoveTagsOnOriginalDeserializeListener(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION0);
  54.     }
  55.     /**
  56.      * @return void
  57.      *
  58.      * @throws Exception
  59.      */
  60.     protected function initializeContainer()
  61.     {
  62.         static $first true;
  63.         if ('test' !== $this->getEnvironment()) {
  64.             parent::initializeContainer();
  65.             return;
  66.         }
  67.         $debug $this->debug;
  68.         if (!$first) {
  69.             // disable debug mode on all but the first initialization
  70.             $this->debug false;
  71.         }
  72.         // will not work with --process-isolation
  73.         $first false;
  74.         try {
  75.             parent::initializeContainer();
  76.         } catch (Exception $e) {
  77.             $this->debug $debug;
  78.             throw $e;
  79.         }
  80.         $this->debug $debug;
  81.     }
  82. }