src/Kernel.php line 72

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