<?php
namespace App;
use App\Component\GDPR\DependencyInjection\Compiler\AddAnonymizersCompilerPass;
use App\DependencyInjection\Compiler\MoneyFormatterCompilerPass;
use App\DependencyInjection\Compiler\MultiMediaAdapterCollectionPass;
use App\DependencyInjection\Compiler\SettingTypeCollectionPass;
use App\DependencyInjection\Compiler\ThemeInheritanceCompilerPass;
use App\DependencyInjection\Compiler\VacancyIOCompilerPass;
use App\DependencyInjection\Compiler\WidgetCollectionPass;
use EightPoints\Bundle\GuzzleBundle\EightPointsGuzzleBundle;
use FOS\HttpCache\SymfonyCache\HttpCacheAware;
use FOS\HttpCache\SymfonyCache\HttpCacheProvider;
use Gregurco\Bundle\GuzzleBundleOAuth2Plugin\GuzzleBundleOAuth2Plugin;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class Kernel extends BaseKernel implements HttpCacheProvider
{
use HttpCacheAware;
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function __construct(string $environment, bool $debug)
{
$this->setHttpCache(new CacheKernel($this, null, ['debug' => $debug]));
parent::__construct($environment, $debug);
}
public function getLogDir(): string
{
return self::getRealProjectDir().'/var/log';
}
public function getCacheDir(): string
{
return self::getRealProjectDir().'/var/cache/'.$this->environment;
}
public static function getLockDir(): string
{
return self::getRealProjectDir().'/var/lock';
}
public function registerBundles(): iterable
{
$contents = require $this->getProjectDir().'/config/bundles.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
if (EightPointsGuzzleBundle::class === $class) {
yield new $class([
new GuzzleBundleOAuth2Plugin(),
]);
} else {
yield new $class();
}
}
}
}
public static function getRealProjectDir(): string
{
if (\defined('SERENA_PROJECT_DIR')) {
return SERENA_PROJECT_DIR;
}
if (isset($_SERVER['PWD'])) {
return $_SERVER['PWD'];
}
throw new \LogicException('Cannot find the real project directory (please check if the constant or PWD environment var exist)');
}
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
{
$container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
$container->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || $this->debug);
$container->setParameter('container.dumper.inline_factories', true);
$confDir = $this->getProjectDir().'/config';
$loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{packages}/'.$this->environment.'/*'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
$loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
}
protected function configureRoutes(RouteCollectionBuilder $routes): void
{
$confDir = $this->getProjectDir().'/config';
$routes->import($confDir.'/{routes}/'.$this->environment.'/*'.self::CONFIG_EXTS, '/', 'glob');
$routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
}
/**
* {@inheritDoc}
*/
protected function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new ThemeInheritanceCompilerPass());
$container->addCompilerPass(new SettingTypeCollectionPass());
$container->addCompilerPass(new WidgetCollectionPass());
$container->addCompilerPass(new MoneyFormatterCompilerPass());
$container->addCompilerPass(new VacancyIOCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 999);
$container->addCompilerPass(new MultiMediaAdapterCollectionPass());
$container->addCompilerPass(new AddAnonymizersCompilerPass());
}
/**
* Gets the application root dir (path of the project's composer file).
*
* @return string The project root dir
*/
public function getProjectDir(): string
{
if (\defined('SERENA_PROJECT_DIR')) {
return SERENA_PROJECT_DIR;
}
if (isset($_SERVER['PWD'])) {
return $_SERVER['PWD'];
}
throw new \LogicException('Cannot find the project directory (please check if the constant or PWD environment var exist)');
}
public function process(ContainerBuilder $container): void
{
// this is added to support calling a consumer command from a controller
// (ExternalIntegrationController::runExternalIntegrationQueueFlush)
if (\PHP_SAPI !== 'cli') {
$container->removeDefinition('messenger.listener.dispatch_pcntl_signal_listener');
$container->removeDefinition('messenger.listener.stop_worker_on_sigterm_signal_listener');
}
}
}