src/Kernel.php line 53

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