src/Kernel.php line 52

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