vendor/ibexa/product-catalog/src/bundle/IbexaProductCatalogBundle.php line 20

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. declare(strict_types=1);
  7. namespace Ibexa\Bundle\ProductCatalog;
  8. use Ibexa\Bundle\ProductCatalog\DependencyInjection\Compiler\AttributeStorageGatewayCompilerPass;
  9. use Ibexa\Bundle\ProductCatalog\DependencyInjection\Configuration\RepositoryAware\ProductCatalogParser as RepositoryAwareProductCatalogParser;
  10. use Ibexa\Bundle\ProductCatalog\DependencyInjection\Configuration\SiteAccessAware\ProductCatalogParser as SiteaccessAwareConfigurationParser;
  11. use Ibexa\ProductCatalog\Security\ProductCatalogPolicyProvider;
  12. use Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  15. use Symfony\Component\HttpKernel\Bundle\Bundle;
  16. final class IbexaProductCatalogBundle extends Bundle
  17. {
  18.     private bool $forceLoadingCommerceBridge;
  19.     public function __construct(bool $forceLoadingCommerceBridge false)
  20.     {
  21.         $this->forceLoadingCommerceBridge $forceLoadingCommerceBridge;
  22.     }
  23.     public function build(ContainerBuilder $container): void
  24.     {
  25.         $loader = new YamlFileLoader(
  26.             $container,
  27.             new FileLocator(__DIR__ '/Resources/config')
  28.         );
  29.         if ($container->hasExtension('ibexa_solr')) {
  30.             $loader->load('services/search/solr.yaml');
  31.         }
  32.         if ($container->hasExtension('ibexa_elasticsearch')) {
  33.             $loader->load('services/search/elasticsearch.yaml');
  34.         }
  35.         if ($container->hasExtension('ibexa_admin_ui')) {
  36.             $loader->load('services/limitations.yaml');
  37.         }
  38.         if ($container->hasExtension('ibexa_personalization')) {
  39.             $loader->load('services/personalization/storages.yaml');
  40.             $loader->load('services/personalization/services.yaml');
  41.             $loader->load('services/personalization/event_subscribers.yaml');
  42.         }
  43.         if ($this->shouldLoadCommerceBridge($container)) {
  44.             $loader->load('services/bridge.yaml');
  45.         }
  46.         if ($container->hasExtension('ibexa_field_type_matrix')) {
  47.             $loader->load('services/field_type_matrix/field_type.yaml');
  48.         }
  49.         /** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $kernel */
  50.         $kernel $container->getExtension('ibexa');
  51.         $kernel->addConfigParser(new SiteaccessAwareConfigurationParser());
  52.         $kernel->addRepositoryConfigParser(new RepositoryAwareProductCatalogParser());
  53.         $kernel->addDefaultSettings(__DIR__ '/Resources/config', ['default_settings.yaml']);
  54.         $kernel->addPolicyProvider(new ProductCatalogPolicyProvider());
  55.         $container->addCompilerPass(new AttributeStorageGatewayCompilerPass());
  56.     }
  57.     private function shouldLoadCommerceBridge(ContainerBuilder $container): bool
  58.     {
  59.         if ($this->forceLoadingCommerceBridge) {
  60.             return true;
  61.         }
  62.         $dependencies = [
  63.             'ibexa_commerce_eshop',
  64.             'ibexa_commerce_price',
  65.             'ibexa_commerce_checkout',
  66.             'ibexa_commerce_local_order_management',
  67.         ];
  68.         foreach ($dependencies as $dependency) {
  69.             if (!$container->hasExtension($dependency)) {
  70.                 return false;
  71.             }
  72.         }
  73.         return true;
  74.     }
  75. }