<?php
namespace FlexApp;
use Exception;
use FlexApp\Extensions\RouterDecorator;
use FlexApp\Service\CollectionsDataStructureForLeaveReviewProvider;
use FlexApp\Service\CommentablePageDataProvider;
use FlexApp\Service\ConsDataForContactsPageProvider;
use FlexApp\Service\ConsDefiner;
use FlexApp\Service\CurrentUserProvider;
use FlexApp\Service\ExtendedCountryListProvider;
use FlexApp\Service\LoginLinkGenerator;
use FlexApp\Service\ParametersGenerator;
use FlexApp\Service\RedisCachePool;
use FlexApp\Service\SystemChatNotificationService;
use FlexApp\Service\TimeFormatTransformer;
use FlexApp\Service\TimezoneManager;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\Config\Exception\LoaderLoadException;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_DIR', __DIR__ . '/../../');
class Kernel extends BaseKernel implements CompilerPassInterface
{
use MicroKernelTrait;
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function registerBundles(): iterable
{
/** @noinspection PhpIncludeInspection */
$contents = require $this->getProjectDir() . '/config/bundles.php';
foreach ($contents as $class => $envs) {
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
yield new $class();
}
}
}
public function getProjectDir(): string
{
return \dirname(dirname(__DIR__));
}
/**
* @param ContainerBuilder $c
* @param LoaderInterface $loader
* @throws Exception
*/
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
{
$availableEnvironments = ['te_dev', 'te', 'test'];
if (!in_array($this->getEnvironment(), $availableEnvironments)) {
throw new Exception(sprintf('Окружение %s не существует. Используйте одно из следующих окружений: %s', $this->getEnvironment(), implode(', ', $availableEnvironments)));
}
$c->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
$c->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID < 70400 || !ini_get('opcache.preload'));
$c->setParameter('container.dumper.inline_factories', true);
$confDir = $this->getProjectDir() . '/config';
$loader->load($confDir . '/parameters' . self::CONFIG_EXTS, 'glob');
$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');
$loader->load($confDir . '/../config/config' . self::CONFIG_EXTS, 'glob');
$loader->load($confDir . '/command.yml');
$loader->load($confDir . '/listeners.yml');
$loader->load($confDir . '/voters.yml');
$loader->load(function (Container $container) {
if ($container->getParameter('assets_base_url')) {
/* @noinspection PhpPossiblePolymorphicInvocationInspection */
$container->loadFromExtension('framework', [
'assets' => [
'packages' => [
'webpack' => [
'base_url' => $container->getParameter('assets_base_url'),
],
],
],
]);
}
});
}
/**
* @param RouteCollectionBuilder $routes
* @throws LoaderLoadException
*/
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');
$routes->import($confDir . '/{routes}' . self::CONFIG_EXTS, '/', 'glob');
}
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$container->getDefinition('swiftmailer.email_sender.listener')->setPublic(true);
$container->getDefinition('console.error_listener')->setPublic(true);
$container->getDefinition('mobile_detect.mobile_detector.default')->setPublic(true);
$container->getDefinition(ConsDefiner::class)->setPublic(true);
$container->getDefinition(CurrentUserProvider::class)->setPublic(true);
$container->getDefinition(SystemChatNotificationService::class)->setPublic(true);
$container->getDefinition('security.authentication_utils')->setPublic(true);
$container->getDefinition(ConsDataForContactsPageProvider::class)->setPublic(true);
$container->getDefinition(ParametersGenerator::class)->setPublic(true);
$container->getDefinition(ExtendedCountryListProvider::class)->setPublic(true);
$container->getDefinition(CommentablePageDataProvider::class)->setPublic(true);
$container->getDefinition(TimeFormatTransformer::class)->setPublic(true);
$container->getDefinition(RedisCachePool::class)->setPublic(true);
$container->getDefinition(RouterDecorator::class)->setPublic(true);
$container->getDefinition(CollectionsDataStructureForLeaveReviewProvider::class)->setPublic(true);
$container->getDefinition(LoginLinkGenerator::class)->setPublic(true);
$container->getDefinition(TimezoneManager::class)->setPublic(true);
}
public function getLogDir()
{
return $this->getProjectDir() . '/var/logs';
}
}