src/FlexApp/Kernel.php line 38

Open in your IDE?
  1. <?php
  2. namespace FlexApp;
  3. use Exception;
  4. use FlexApp\Extensions\RouterDecorator;
  5. use FlexApp\Service\CollectionsDataStructureForLeaveReviewProvider;
  6. use FlexApp\Service\CommentablePageDataProvider;
  7. use FlexApp\Service\ConsDataForContactsPageProvider;
  8. use FlexApp\Service\ConsDefiner;
  9. use FlexApp\Service\CurrentUserProvider;
  10. use FlexApp\Service\ExtendedCountryListProvider;
  11. use FlexApp\Service\LoginLinkGenerator;
  12. use FlexApp\Service\ParametersGenerator;
  13. use FlexApp\Service\RedisCachePool;
  14. use FlexApp\Service\SystemChatNotificationService;
  15. use FlexApp\Service\TimeFormatTransformer;
  16. use FlexApp\Service\TimezoneManager;
  17. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  18. use Symfony\Component\Config\Exception\LoaderLoadException;
  19. use Symfony\Component\Config\Loader\LoaderInterface;
  20. use Symfony\Component\Config\Resource\FileResource;
  21. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  22. use Symfony\Component\DependencyInjection\Container;
  23. use Symfony\Component\DependencyInjection\ContainerBuilder;
  24. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  25. use Symfony\Component\Routing\RouteCollectionBuilder;
  26. define('DS'DIRECTORY_SEPARATOR);
  27. define('ROOT_DIR'__DIR__ '/../../');
  28. class Kernel extends BaseKernel implements CompilerPassInterface
  29. {
  30.     use MicroKernelTrait;
  31.     private const CONFIG_EXTS '.{php,xml,yaml,yml}';
  32.     public function registerBundles(): iterable
  33.     {
  34.         /** @noinspection PhpIncludeInspection */
  35.         $contents = require $this->getProjectDir() . '/config/bundles.php';
  36.         foreach ($contents as $class => $envs) {
  37.             if ($envs[$this->environment] ?? $envs['all'] ?? false) {
  38.                 yield new $class();
  39.             }
  40.         }
  41.     }
  42.     public function getProjectDir(): string
  43.     {
  44.         return \dirname(dirname(__DIR__));
  45.     }
  46.     /**
  47.      * @param ContainerBuilder $c
  48.      * @param LoaderInterface  $loader
  49.      * @throws Exception
  50.      */
  51.     protected function configureContainer(ContainerBuilder $cLoaderInterface $loader): void
  52.     {
  53.         $availableEnvironments = ['te_dev''te''test'];
  54.         if (!in_array($this->getEnvironment(), $availableEnvironments)) {
  55.             throw new Exception(sprintf('Окружение %s не существует. Используйте одно из следующих окружений: %s'$this->getEnvironment(), implode(', '$availableEnvironments)));
  56.         }
  57.         $c->addResource(new FileResource($this->getProjectDir() . '/config/bundles.php'));
  58.         $c->setParameter('container.dumper.inline_class_loader', \PHP_VERSION_ID 70400 || !ini_get('opcache.preload'));
  59.         $c->setParameter('container.dumper.inline_factories'true);
  60.         $confDir $this->getProjectDir() . '/config';
  61.         $loader->load($confDir '/parameters' self::CONFIG_EXTS'glob');
  62.         $loader->load($confDir '/{packages}/*' self::CONFIG_EXTS'glob');
  63.         $loader->load($confDir '/{packages}/' $this->environment '/*' self::CONFIG_EXTS'glob');
  64.         $loader->load($confDir '/{services}' self::CONFIG_EXTS'glob');
  65.         $loader->load($confDir '/{services}_' $this->environment self::CONFIG_EXTS'glob');
  66.         $loader->load($confDir '/../config/config' self::CONFIG_EXTS'glob');
  67.         $loader->load($confDir '/command.yml');
  68.         $loader->load($confDir '/listeners.yml');
  69.         $loader->load($confDir '/voters.yml');
  70.         $loader->load(function (Container $container) {
  71.             if ($container->getParameter('assets_base_url')) {
  72.                 /* @noinspection PhpPossiblePolymorphicInvocationInspection */
  73.                 $container->loadFromExtension('framework', [
  74.                     'assets' => [
  75.                         'packages' => [
  76.                             'webpack' => [
  77.                                 'base_url' => $container->getParameter('assets_base_url'),
  78.                             ],
  79.                         ],
  80.                     ],
  81.                 ]);
  82.             }
  83.         });
  84.     }
  85.     /**
  86.      * @param RouteCollectionBuilder $routes
  87.      * @throws LoaderLoadException
  88.      */
  89.     protected function configureRoutes(RouteCollectionBuilder $routes): void
  90.     {
  91.         $confDir $this->getProjectDir() . '/config';
  92.         $routes->import($confDir '/{routes}/' $this->environment '/*' self::CONFIG_EXTS'/''glob');
  93.         $routes->import($confDir '/{routes}/*' self::CONFIG_EXTS'/''glob');
  94.         $routes->import($confDir '/{routes}' self::CONFIG_EXTS'/''glob');
  95.     }
  96.     /**
  97.      * {@inheritdoc}
  98.      */
  99.     public function process(ContainerBuilder $container)
  100.     {
  101.         $container->getDefinition('swiftmailer.email_sender.listener')->setPublic(true);
  102.         $container->getDefinition('console.error_listener')->setPublic(true);
  103.         $container->getDefinition('mobile_detect.mobile_detector.default')->setPublic(true);
  104.         $container->getDefinition(ConsDefiner::class)->setPublic(true);
  105.         $container->getDefinition(CurrentUserProvider::class)->setPublic(true);
  106.         $container->getDefinition(SystemChatNotificationService::class)->setPublic(true);
  107.         $container->getDefinition('security.authentication_utils')->setPublic(true);
  108.         $container->getDefinition(ConsDataForContactsPageProvider::class)->setPublic(true);
  109.         $container->getDefinition(ParametersGenerator::class)->setPublic(true);
  110.         $container->getDefinition(ExtendedCountryListProvider::class)->setPublic(true);
  111.         $container->getDefinition(CommentablePageDataProvider::class)->setPublic(true);
  112.         $container->getDefinition(TimeFormatTransformer::class)->setPublic(true);
  113.         $container->getDefinition(RedisCachePool::class)->setPublic(true);
  114.         $container->getDefinition(RouterDecorator::class)->setPublic(true);
  115.         $container->getDefinition(CollectionsDataStructureForLeaveReviewProvider::class)->setPublic(true);
  116.         $container->getDefinition(LoginLinkGenerator::class)->setPublic(true);
  117.         $container->getDefinition(TimezoneManager::class)->setPublic(true);
  118.     }
  119.     public function getLogDir()
  120.     {
  121.         return $this->getProjectDir() . '/var/logs';
  122.     }
  123. }