src/Kernel.php line 64

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use App\Bridge\Symfony\DependencyInjection\Compiler\RemoveIdentityAccessTokenHandlersPass;
  4. use App\Bridge\Symfony\DependencyInjection\Compiler\ResolveDomainRedirectorPass;
  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\Compiler\PassConfig;
  9. use Symfony\Component\DependencyInjection\ContainerBuilder;
  10. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  11. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  12. use Symfony\Component\Routing\RouteCollectionBuilder;
  13. class Kernel extends BaseKernel
  14. {
  15.     use MicroKernelTrait;
  16.     private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
  17.     /**
  18.      * @inheritDoc
  19.      */
  20.     protected function build(ContainerBuilder $container)
  21.     {
  22.         parent::build($container);
  23.         $container->addCompilerPass(new ResolveDomainRedirectorPass());
  24.         $container->addCompilerPass(
  25.             new RemoveIdentityAccessTokenHandlersPass(),
  26.             PassConfig::TYPE_BEFORE_OPTIMIZATION,
  27.             1000
  28.         );
  29.     }
  30.     public function registerBundles(): iterable
  31.     {
  32.         $contents = require $this->getProjectDir().'/config/bundles.php';
  33.         foreach ($contents as $class => $envs) {
  34.             if ($envs[$this->environment] ?? $envs['all'] ?? false) {
  35.                 yield new $class();
  36.             }
  37.         }
  38.     }
  39.     protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
  40.     {
  41.         $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
  42.         $container->setParameter('container.dumper.inline_class_loader', true);
  43.         $confDir = $this->getProjectDir().'/config';
  44.         $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
  45.         $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
  46.         $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
  47.         $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
  48.     }
  49.     protected function configureRoutes(RoutingConfigurator $routes): void
  50.     {
  51.         $confDir = $this->getProjectDir().'/config';
  52.         $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS);
  53.         $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS);
  54.         $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS);
  55. //        dd($routes->collection());
  56.     }
  57.     /**
  58.      * @inheritDoc
  59.      */
  60.     public function getCacheDir(): string
  61.     {
  62.         if (isset($_ENV['CACHE_DIRECTORY'])) {
  63.             return rtrim($_ENV['CACHE_DIRECTORY'], '/')."/{$this->environment}";
  64.         }
  65.         return parent::getCacheDir();
  66.     }
  67. }