src/Kernel.php line 51

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 App\Service\Processor\OrderShipmentProcessor;
  13. use PSS\SymfonyMockerContainer\DependencyInjection\MockerContainer;
  14. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  15. use Symfony\Component\Config\Loader\LoaderInterface;
  16. use Symfony\Component\Config\Resource\FileResource;
  17. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  18. use Symfony\Component\DependencyInjection\ContainerBuilder;
  19. use Symfony\Component\DependencyInjection\Reference;
  20. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  21. use Symfony\Component\Routing\RouteCollectionBuilder;
  22. /**
  23.  * @method string getBuildDir()
  24.  */
  25. final class Kernel extends BaseKernel implements CompilerPassInterface
  26. {
  27.     use MicroKernelTrait;
  28.     private const CONFIG_EXTS '.{php,xml,yaml,yml}';
  29.     public function getCacheDir(): string
  30.     {
  31.         return $this->getProjectDir() . '/var/cache/' $this->environment;
  32.     }
  33.     public function getLogDir(): string
  34.     {
  35.         return $this->getProjectDir() . '/var/log';
  36.     }
  37.     public function registerBundles(): iterable
  38.     {
  39.         $contents = require $this->getProjectDir() . '/config/bundles.php';
  40.         foreach ($contents as $class => $envs) {
  41.             if (isset($envs['all']) || isset($envs[$this->environment])) {
  42.                 yield new $class();
  43.             }
  44.         }
  45.     }
  46.     protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader): void
  47.     {
  48.         $container->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
  49.         $container->setParameter('container.dumper.inline_class_loader'true);
  50.         $confDir $this->getProjectDir() . '/config';
  51.         $loader->load($confDir '/{packages}/*' self::CONFIG_EXTS'glob');
  52.         $loader->load($confDir '/{packages}/' $this->environment '/**/*' self::CONFIG_EXTS'glob');
  53.         $loader->load($confDir '/{services}' self::CONFIG_EXTS'glob');
  54.         $loader->load($confDir '/{services}_' $this->environment self::CONFIG_EXTS'glob');
  55.     }
  56.     protected function configureRoutes(RouteCollectionBuilder $routes): void
  57.     {
  58.         $confDir $this->getProjectDir() . '/config';
  59.         $routes->import($confDir '/{routes}/*' self::CONFIG_EXTS'/''glob');
  60.         $routes->import($confDir '/{routes}/' $this->environment '/**/*' self::CONFIG_EXTS'/''glob');
  61.         $routes->import($confDir '/{routes}' self::CONFIG_EXTS'/''glob');
  62.     }
  63.     protected function getContainerBaseClass(): string
  64.     {
  65.         if ($this->isTestEnvironment() && class_exists(MockerContainer::class)) {
  66.             return MockerContainer::class;
  67.         }
  68.         return parent::getContainerBaseClass();
  69.     }
  70.     private function isTestEnvironment(): bool
  71.     {
  72.         return === strpos($this->getEnvironment(), 'test');
  73.     }
  74.     /**
  75.      * @param ContainerBuilder $container
  76.      * @return void
  77.      */
  78.     public function process(ContainerBuilder $container): void
  79.     {
  80.         $container->getDefinition('sylius.order_processing.order_shipment_processor')
  81.             ->setClass(OrderShipmentProcessor::class)
  82.             ->addArgument(new Reference('doctrine.orm.entity_manager'))
  83.         ;
  84.     }
  85. }