src/Kernel.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace App;
  12. use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
  13. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  14. use Symfony\Component\Config\Loader\LoaderInterface;
  15. use Symfony\Component\Config\Resource\FileResource;
  16. use Symfony\Component\DependencyInjection\ContainerBuilder;
  17. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  18. use Symfony\Component\Routing\RouteCollectionBuilder;
  19. final class Kernel extends BaseKernel
  20. {
  21.     use MicroKernelTrait;
  22.     private const CONFIG_EXTS '.{php,xml,yaml,yml}';
  23.     public function getCacheDir(): string
  24.     {
  25.         return $this->getProjectDir() . '/var/cache/' $this->environment;
  26.     }
  27.     public function getLogDir(): string
  28.     {
  29.         return $this->getProjectDir() . '/var/log';
  30.     }
  31.     public function registerBundles(): iterable
  32.     {
  33.         $contents = require $this->getProjectDir() . '/config/bundles.php';
  34.         foreach ($contents as $class => $envs) {
  35.             if (isset($envs['all']) || isset($envs[$this->environment])) {
  36.                 yield new $class();
  37.             }
  38.         }
  39.     }
  40.     protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader): void
  41.     {
  42.         $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
  43.         $container->setParameter('container.dumper.inline_class_loader'true);
  44.         $confDir $this->getProjectDir() . '/config';
  45.         $loader->load($confDir '/{packages}/*' self::CONFIG_EXTS'glob');
  46.         $loader->load($confDir '/{packages}/' $this->environment '/**/*' self::CONFIG_EXTS'glob');
  47.         $loader->load($confDir '/{services}' self::CONFIG_EXTS'glob');
  48.         $loader->load($confDir '/{services}_' $this->environment self::CONFIG_EXTS'glob');
  49.     }
  50.     protected function configureRoutes(RouteCollectionBuilder $routes): void
  51.     {
  52.         $confDir $this->getProjectDir() . '/config';
  53.         $routes->import($confDir '/{routes}/*' self::CONFIG_EXTS'/''glob');
  54.         $routes->import($confDir '/{routes}/' $this->environment '/**/*' self::CONFIG_EXTS'/''glob');
  55.         $routes->import($confDir '/{routes}' self::CONFIG_EXTS'/''glob');
  56.     }
  57.     protected function getContainerBaseClass(): string
  58.     {
  59.         if ($this->isTestEnvironment() && class_exists(MockerContainer::class)) {
  60.             return MockerContainer::class;
  61.         }
  62.         return parent::getContainerBaseClass();
  63.     }
  64.     private function isTestEnvironment(): bool
  65.     {
  66.         return === strpos($this->getEnvironment(), 'test');
  67.     }
  68. }