src/Kernel.php line 68

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use Doctrine\Common\Annotations\AnnotationReader;
  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\RouteCollectionBuilder;
  10. use WAM\Bundle\WebContentBundle\Twig\MenuExtension;
  11. class Kernel extends BaseKernel
  12. {
  13.     use MicroKernelTrait;
  14.     private const CONFIG_EXTS '.{php,xml,yaml,yml}';
  15.     const CACHE_DIR_PREFIX '/var/tmp/';
  16. //    public function getCacheDir()
  17. //    {
  18. //        $dir = parent::getCacheDir();
  19. //
  20. //        if ($this->isDebug()) {
  21. //            return $this->getVagrantDir($dir);
  22. //        }
  23. //
  24. //        return $dir;
  25. //    }
  26. //
  27. //    public function getLogDir()
  28. //    {
  29. //        $dir = parent::getLogDir();
  30. //
  31. //        if ($this->isDebug()) {
  32. //            return $this->getVagrantDir($dir);
  33. //        }
  34. //
  35. //        return $dir;
  36. //    }
  37. //    private function getVagrantDir($dir)
  38. //    {
  39. //        return self::CACHE_DIR_PREFIX.trim(str_replace('/', '_', $dir), '_');
  40. //    }
  41.     public function registerBundles(): iterable
  42.     {
  43.         $contents = require $this->getProjectDir().'/config/bundles.php';
  44.         foreach ($contents as $class => $envs) {
  45.             if ($envs[$this->environment] ?? $envs['all'] ?? false) {
  46.                 yield new $class();
  47.             }
  48.         }
  49.     }
  50.     public function getProjectDir(): string
  51.     {
  52.         return \dirname(__DIR__);
  53.     }
  54.     public function boot()
  55.     {
  56.         AnnotationReader::addGlobalIgnoredName('mixin');
  57.         return parent::boot();
  58.     }
  59.     protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader): void
  60.     {
  61.         $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
  62.         $container->setParameter('container.dumper.inline_class_loader'true);
  63.         $confDir $this->getProjectDir().'/config';
  64.         $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS'glob');
  65.         $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS'glob');
  66.         $loader->load($confDir.'/{packages}/{wam,sonata}/*'.self::CONFIG_EXTS'glob');
  67.         $loader->load($confDir.'/{services}'.self::CONFIG_EXTS'glob');
  68.         $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS'glob');
  69.         $container->removeDefinition(MenuExtension::class);
  70.     }
  71.     protected function configureRoutes(RouteCollectionBuilder $routes): void
  72.     {
  73.         $confDir $this->getProjectDir().'/config';
  74.         $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS'/''glob');
  75.         $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS'/''glob');
  76.         $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS'/''glob');
  77.     }
  78. }