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

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