vendor/pimcore/portal-engine/src/DependencyInjection/PimcorePortalEngineExtension.php line 141

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\DependencyInjection;
  12. use Pimcore\Bundle\PortalEngineBundle\Enum\DependencyInjection\ContainerParameter;
  13. use Pimcore\Bundle\PortalEngineBundle\EventSubscriber\AdminSettingsSubscriber;
  14. use Pimcore\Bundle\PortalEngineBundle\EventSubscriber\SecuritySubscriber;
  15. use Pimcore\Bundle\PortalEngineBundle\Form\LoginForm;
  16. use Pimcore\Bundle\PortalEngineBundle\Form\RecoverPasswordForm;
  17. use Pimcore\Bundle\PortalEngineBundle\MessageHandler\BatchTask\Download;
  18. use Pimcore\Bundle\PortalEngineBundle\MessageHandler\BatchTask\UpdateAssetMetadata;
  19. use Pimcore\Bundle\PortalEngineBundle\Service\BatchTask\BatchTaskService;
  20. use Pimcore\Bundle\PortalEngineBundle\Service\Download\SizeEstimation\AsyncSizeEstimationService;
  21. use Pimcore\Bundle\PortalEngineBundle\Service\Frontend\FrontendConfigService;
  22. use Pimcore\Bundle\PortalEngineBundle\Service\PortalConfig\FrontendBuildService;
  23. use Pimcore\Bundle\PortalEngineBundle\Service\SearchIndex\ElasticSearchConfigService;
  24. use Pimcore\Bundle\PortalEngineBundle\Service\Security\Authentication\User\RecoverPasswordService;
  25. use Pimcore\Bundle\PortalEngineBundle\Service\Security\Authentication\UserProvider;
  26. use Pimcore\Bundle\PortalEngineBundle\Twig\WebpackExtension;
  27. use Symfony\Component\Config\FileLocator;
  28. use Symfony\Component\DependencyInjection\ContainerBuilder;
  29. use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
  30. use Symfony\Component\DependencyInjection\Loader;
  31. use Symfony\Component\HttpKernel\DependencyInjection\Extension;
  32. use Symfony\Component\Yaml\Exception\ParseException;
  33. use Symfony\Component\Yaml\Yaml;
  34. /**
  35.  * This is the class that loads and manages your bundle configuration.
  36.  *
  37.  * @link http://symfony.com/doc/current/cookbook/bundles/extension.html
  38.  */
  39. class PimcorePortalEngineExtension extends Extension implements PrependExtensionInterface
  40. {
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function load(array $configsContainerBuilder $container)
  45.     {
  46.         $configuration = new Configuration();
  47.         $config $this->processConfiguration($configuration$configs);
  48.         $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ '/../Resources/config'));
  49.         $loader->load('services.yml');
  50.         $this
  51.             ->registerCustomizedFrontendBuilds($container$config['customized_frontend_builds'])
  52.             ->registerFrontendParams($container$config['frontend'])
  53.             ->registerPossiblePortalDomains($container$config['wizard']['possible_portal_domains'] ?? [])
  54.             ->registerElasticSearchClientParams($container$config['index_service'])
  55.             ->registerCoreFields($container$config['core_fields_configuration'])
  56.             ->registerBatchTaskQueue($container$config['batch_task_queue'])
  57.             ->registerDataPool($container$config['data_pool'])
  58.             ->registerDownload($container$config['download'])
  59.             ->registerLogin($container$config['login'])
  60.             ->registerRecoverPassword($container$config['login'])
  61.             ->registerCustomPublicRoutes($container$config['custom_public_routes'])
  62.         ;
  63.     }
  64.     /**
  65.      * @param ContainerBuilder $container
  66.      * @param array $customizedFrontendBuilds
  67.      *
  68.      * @return $this
  69.      */
  70.     protected function registerCustomizedFrontendBuilds(ContainerBuilder $container, array $customizedFrontendBuilds)
  71.     {
  72.         $definition $container->getDefinition(FrontendBuildService::class);
  73.         $definition->setArgument('$customizedFrontendBuilds'$customizedFrontendBuilds);
  74.         return $this;
  75.     }
  76.     protected function registerPossiblePortalDomains(ContainerBuilder $container, array $possiblePortalDomains)
  77.     {
  78.         $definition $container->getDefinition(AdminSettingsSubscriber::class);
  79.         $definition->setArgument('$possiblePortalDomains'$possiblePortalDomains);
  80.         return $this;
  81.     }
  82.     protected function registerFrontendParams(ContainerBuilder $container, array $config)
  83.     {
  84.         $definition $container->getDefinition(FrontendConfigService::class);
  85.         $definition->addMethodCall('setConfig', ['geo.tileLayerUrl'$config['geo_tile_layer_url']]);
  86.         $definition->addMethodCall('setConfig', ['geo.copyright'$config['geo_copyright']]);
  87.         return $this;
  88.     }
  89.     /**
  90.      * @param ContainerBuilder $container
  91.      * @param array $esClientParams
  92.      *
  93.      * @return $this
  94.      */
  95.     protected function registerElasticSearchClientParams(ContainerBuilder $container, array $esClientParams)
  96.     {
  97.         $definition $container->getDefinition(ElasticSearchConfigService::class);
  98.         $definition->setArgument('$host'$esClientParams['es_client_params']['host']);
  99.         $definition->setArgument('$index_prefix'$esClientParams['es_client_params']['index_prefix']);
  100.         $definition->setArgument('$indexSettings'$esClientParams['index_settings']);
  101.         $definition->setArgument('$searchSettings'$esClientParams['search_settings']);
  102.         $definition->setArgument('$connectionParams'$esClientParams['es_client_params']['connection_params']);
  103.         $container->setParameter('portal-engine.elasticsearch.index-prefix'$esClientParams['es_client_params']['index_prefix']);
  104.         return $this;
  105.     }
  106.     /**
  107.      * @param ContainerBuilder $container
  108.      * @param array $coreFields
  109.      *
  110.      * @return $this
  111.      */
  112.     protected function registerCoreFields(ContainerBuilder $container, array $coreFields)
  113.     {
  114.         $container->setParameter(
  115.             'pimcore_portal_engine.core_fields_configuration',
  116.             $coreFields
  117.         );
  118.         return $this;
  119.     }
  120.     /**
  121.      * @param ContainerBuilder $container
  122.      */
  123.     public function prepend(ContainerBuilder $container)
  124.     {
  125.         $portals = [];
  126.         $portalsJsonFile FrontendBuildService::APP_FRONTEND_PORTALS_JSON;
  127.         if (file_exists($portalsJsonFile)) {
  128.             $portals json_decode(file_get_contents($portalsJsonFile), true);
  129.         }
  130.         $builds = [
  131.             'portalEngineBundle' => realpath(__DIR__ '/../Resources/public/build/bundle'),
  132.         ];
  133.         foreach ($portals as $portal) {
  134.             $portalId $portal['id'];
  135.             $builds[WebpackExtension::BUILD_PORTAL_CONFIG '_' $portalId] = FrontendBuildService::APP_FRONTEND_ROOT '/build/portal_' $portalId;
  136.         }
  137.         $customizedFrontendBuildsJsonFile FrontendBuildService::APP_FRONTEND_CUSTOMIZED_FRONTEND_BUILDS_JSON;
  138.         if (file_exists($customizedFrontendBuildsJsonFile)) {
  139.             $frontendBuilds json_decode(file_get_contents($customizedFrontendBuildsJsonFile), true);
  140.             foreach ($frontendBuilds as $frontendBuild) {
  141.                 $builds[WebpackExtension::BUILD_CUSTOMIZED '_' $frontendBuild] = FrontendBuildService::APP_FRONTEND_CUSTOMIZED_FRONTEND_BUILDS '/build/' $frontendBuild;
  142.             }
  143.         }
  144.         $container->prependExtensionConfig('webpack_encore', [
  145.             // 'output_path' => realpath(__DIR__ . '/../Resources/public/build')
  146.             'output_path' => false,
  147.             'builds' => $builds
  148.         ]);
  149.         if ($container->hasExtension('doctrine_migrations')) {
  150.             $loader = new Loader\YamlFileLoader(
  151.                 $container,
  152.                 new FileLocator(__DIR__ '/../Resources/config')
  153.             );
  154.             $loader->load('doctrine_migrations.yml');
  155.         }
  156.         $yamlParser = new Yaml();
  157.         $filename __DIR__ '/../Resources/config/doctrine.yml';
  158.         try {
  159.             $config $yamlParser->parse(
  160.                 file_get_contents($filename)
  161.             );
  162.         } catch (ParseException $e) {
  163.             throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.'$filename), 0$e);
  164.         }
  165.         $container->prependExtensionConfig('doctrine'$config['doctrine']);
  166.     }
  167.     protected function registerBatchTaskQueue(ContainerBuilder $container, array $config)
  168.     {
  169.         $startHandler $container->getDefinition(Download\StartHandler::class);
  170.         $startHandler->setArgument('$batchSize'$config['download']['batch_size']);
  171.         $startHandler $container->getDefinition(UpdateAssetMetadata\StartHandler::class);
  172.         $startHandler->setArgument('$batchSize'$config['update_asset_metadata']['batch_size']);
  173.         $batchTaskService $container->getDefinition(BatchTaskService::class);
  174.         $batchTaskService->setArgument('$cleanupUncompletedTasksAfterHours'$config['cleanup']['cleanup_uncompleted_tasks_after_hours']);
  175.         $batchTaskService->setArgument('$cleanupFinishedTasksAfterHours'$config['cleanup']['cleanup_finished_tasks_after_hours']);
  176.         return $this;
  177.     }
  178.     protected function registerDataPool(ContainerBuilder $container, array $config)
  179.     {
  180.         $searchServices = [
  181.             \Pimcore\Bundle\PortalEngineBundle\Service\Rest\Api\DataObject\ListHandler::class,
  182.             \Pimcore\Bundle\PortalEngineBundle\Service\Rest\Api\Asset\ListHandler::class,
  183.         ];
  184.         $container->setParameter(ContainerParameter::SELECT_ALL_MAX_SIZE$config['select_all_max_size']);
  185.         foreach ($searchServices as $service) {
  186.             $searchService $container->getDefinition($service);
  187.             $searchService->setArgument('$selectAllMaxSize'$config['select_all_max_size']);
  188.         }
  189.         return $this;
  190.     }
  191.     protected function registerDownload(ContainerBuilder $container, array $config)
  192.     {
  193.         $asyncSizeEstimationService $container->getDefinition(AsyncSizeEstimationService::class);
  194.         $asyncSizeEstimationService->setArgument('$zipWarningSize'$config['zip_warning_size']);
  195.         $asyncSizeEstimationService->setArgument('$zipRejectSize'$config['zip_reject_size']);
  196.         return $this;
  197.     }
  198.     protected function registerLogin(ContainerBuilder $container, array $config)
  199.     {
  200.         $loginFormService $container->getDefinition(LoginForm::class);
  201.         $loginFormService->setArgument('$fields'$config['fields']);
  202.         $userProviderService $container->getDefinition(UserProvider::class);
  203.         $userProviderService->setArgument('$fields'$config['fields']);
  204.         return $this;
  205.     }
  206.     protected function registerRecoverPassword(ContainerBuilder $container, array $config)
  207.     {
  208.         $recoverPasswordFormService $container->getDefinition(RecoverPasswordForm::class);
  209.         $recoverPasswordFormService->setArgument('$fields'$config['fields']);
  210.         $recoverPasswordService $container->getDefinition(RecoverPasswordService::class);
  211.         $recoverPasswordService->setArgument('$fields'$config['fields']);
  212.         return $this;
  213.     }
  214.     protected function registerCustomPublicRoutes(ContainerBuilder $container, array $customPublicRoutes)
  215.     {
  216.         $securitySubscriber $container->getDefinition(SecuritySubscriber::class);
  217.         $securitySubscriber->setArgument('$customPublicRoutes'$customPublicRoutes);
  218.     }
  219. }