src/Kernel.php line 54

Open in your IDE?
  1. <?php
  2. namespace App;
  3. use App\Component\GDPR\DependencyInjection\Compiler\AddAnonymizersCompilerPass;
  4. use App\DependencyInjection\Compiler\FilterSetPass;
  5. use App\DependencyInjection\Compiler\MoneyFormatterCompilerPass;
  6. use App\DependencyInjection\Compiler\MultiMediaAdapterCollectionPass;
  7. use App\DependencyInjection\Compiler\SettingTypeCollectionPass;
  8. use App\DependencyInjection\Compiler\ThemeInheritanceCompilerPass;
  9. use App\DependencyInjection\Compiler\VacancyIOCompilerPass;
  10. use App\DependencyInjection\Compiler\WidgetCollectionPass;
  11. use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle;
  12. use FOS\HttpCache\SymfonyCache\HttpCacheAware;
  13. use FOS\HttpCache\SymfonyCache\HttpCacheProvider;
  14. use Gregurco\Bundle\GuzzleBundleOAuth2Plugin\GuzzleBundleOAuth2Plugin;
  15. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  16. use Symfony\Component\Config\Loader\LoaderInterface;
  17. use Symfony\Component\Config\Resource\FileResource;
  18. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  19. use Symfony\Component\DependencyInjection\ContainerBuilder;
  20. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  21. use Symfony\Component\Routing\RouteCollectionBuilder;
  22. class Kernel extends BaseKernel implements HttpCacheProvider
  23. {
  24.     use HttpCacheAware;
  25.     use MicroKernelTrait;
  26.     private const CONFIG_EXTS '.{php,xml,yaml,yml}';
  27.     public function __construct(string $environmentbool $debug)
  28.     {
  29.         $this->setHttpCache(new CacheKernel($thisnull, ['debug' => $debug]));
  30.         parent::__construct($environment$debug);
  31.     }
  32.     public function getLogDir(): string
  33.     {
  34.         return self::getRealProjectDir().'/var/log';
  35.     }
  36.     public function getCacheDir(): string
  37.     {
  38.         return self::getRealProjectDir().'/var/cache/'.$this->environment;
  39.     }
  40.     public static function getLockDir(): string
  41.     {
  42.         return self::getRealProjectDir().'/var/lock';
  43.     }
  44.     public function registerBundles(): iterable
  45.     {
  46.         $contents = require $this->getProjectDir().'/config/bundles.php';
  47.         foreach ($contents as $class => $envs) {
  48.             if (isset($envs['all']) || isset($envs[$this->environment])) {
  49.                 if (EightPointsGuzzleBundle::class === $class) {
  50.                     yield new $class([
  51.                         new GuzzleBundleOAuth2Plugin(),
  52.                     ]);
  53.                 } else {
  54.                     yield new $class();
  55.                 }
  56.             }
  57.         }
  58.     }
  59.     public static function getRealProjectDir(): string
  60.     {
  61.         if (\defined('SERENA_PROJECT_DIR')) {
  62.             return SERENA_PROJECT_DIR;
  63.         }
  64.         if (isset($_SERVER['PWD'])) {
  65.             return $_SERVER['PWD'];
  66.         }
  67.         throw new \LogicException('Cannot find the real project directory (please check if the constant or PWD environment var exist)');
  68.     }
  69.     protected function configureContainer(ContainerBuilder $containerLoaderInterface $loader): void
  70.     {
  71.         $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
  72.         $container->setParameter('container.dumper.inline_class_loader'\PHP_VERSION_ID 70400 || $this->debug);
  73.         $container->setParameter('container.dumper.inline_factories'true);
  74.         $confDir $this->getProjectDir().'/config';
  75.         $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS'glob');
  76.         $loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS'glob');
  77.         $loader->load($confDir.'/{services}'.self::CONFIG_EXTS'glob');
  78.         $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS'glob');
  79.     }
  80.     protected function configureRoutes(RouteCollectionBuilder $routes): void
  81.     {
  82.         $confDir $this->getProjectDir().'/config';
  83.         $routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS'/''glob');
  84.         $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS'/''glob');
  85.     }
  86.     /**
  87.      * {@inheritDoc}
  88.      */
  89.     protected function build(ContainerBuilder $container)
  90.     {
  91.         parent::build($container);
  92.         $container->addCompilerPass(new ThemeInheritanceCompilerPass());
  93.         $container->addCompilerPass(new SettingTypeCollectionPass());
  94.         $container->addCompilerPass(new WidgetCollectionPass());
  95.         $container->addCompilerPass(new FilterSetPass());
  96.         $container->addCompilerPass(new MoneyFormatterCompilerPass());
  97.         $container->addCompilerPass(new VacancyIOCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION999);
  98.         $container->addCompilerPass(new MultiMediaAdapterCollectionPass());
  99.         $container->addCompilerPass(new AddAnonymizersCompilerPass());
  100.     }
  101.     /**
  102.      * Gets the application root dir (path of the project's composer file).
  103.      *
  104.      * @return string The project root dir
  105.      */
  106.     public function getProjectDir(): string
  107.     {
  108.         if (\defined('SERENA_PROJECT_DIR')) {
  109.             return SERENA_PROJECT_DIR;
  110.         }
  111.         if (isset($_SERVER['PWD'])) {
  112.             return $_SERVER['PWD'];
  113.         }
  114.         throw new \LogicException('Cannot find the project directory (please check if the constant or PWD environment var exist)');
  115.     }
  116.     public function process(ContainerBuilder $container): void
  117.     {
  118.         // this is added to support calling a consumer command from a controller
  119.         // (ExternalIntegrationController::runExternalIntegrationQueueFlush)
  120.         if (\PHP_SAPI !== 'cli') {
  121.             $container->removeDefinition('messenger.listener.dispatch_pcntl_signal_listener');
  122.             $container->removeDefinition('messenger.listener.stop_worker_on_sigterm_signal_listener');
  123.         }
  124.     }
  125. }