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

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\Compiler\CriterionMapperCompilerPass;
  10. use Ibexa\Bundle\ProductCatalog\DependencyInjection\Configuration\RepositoryAware\ProductCatalogParser as RepositoryAwareProductCatalogParser;
  11. use Ibexa\Bundle\ProductCatalog\DependencyInjection\Configuration\SiteAccessAware\ProductCatalogParser as SiteaccessAwareConfigurationParser;
  12. use Ibexa\ProductCatalog\Security\ProductCatalogPolicyProvider;
  13. use Symfony\Component\Config\FileLocator;
  14. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  17. use Symfony\Component\HttpKernel\Bundle\Bundle;
  18. final class IbexaProductCatalogBundle extends Bundle
  19. {
  20. private bool $forceLoadingCommerceBridge;
  21. public function __construct(bool $forceLoadingCommerceBridge = false)
  22. {
  23. $this->forceLoadingCommerceBridge = $forceLoadingCommerceBridge;
  24. }
  25. public function build(ContainerBuilder $container): void
  26. {
  27. $loader = new YamlFileLoader(
  28. $container,
  29. new FileLocator(__DIR__ . '/Resources/config')
  30. );
  31. if ($container->hasExtension('ibexa_solr')) {
  32. $loader->load('services/search/solr.yaml');
  33. }
  34. if ($container->hasExtension('ibexa_elasticsearch')) {
  35. $loader->load('services/search/elasticsearch.yaml');
  36. }
  37. if ($container->hasExtension('ibexa_admin_ui')) {
  38. $loader->load('services/limitations.yaml');
  39. }
  40. if ($container->hasExtension('ibexa_personalization')) {
  41. $loader->load('services/personalization/storages.yaml');
  42. $loader->load('services/personalization/services.yaml');
  43. $loader->load('services/personalization/event_subscribers.yaml');
  44. }
  45. if ($this->shouldLoadCommerceBridge($container)) {
  46. $loader->load('services/bridge.yaml');
  47. }
  48. if ($container->hasExtension('ibexa_field_type_matrix')) {
  49. $loader->load('services/field_type_matrix/field_type.yaml');
  50. }
  51. /** @var \Ibexa\Bundle\Core\DependencyInjection\IbexaCoreExtension $kernel */
  52. $kernel = $container->getExtension('ibexa');
  53. $kernel->addConfigParser(new SiteaccessAwareConfigurationParser());
  54. $kernel->addRepositoryConfigParser(new RepositoryAwareProductCatalogParser());
  55. $kernel->addDefaultSettings(__DIR__ . '/Resources/config', ['default_settings.yaml']);
  56. $kernel->addPolicyProvider(new ProductCatalogPolicyProvider());
  57. $container->addCompilerPass(new AttributeStorageGatewayCompilerPass());
  58. $container->addCompilerPass(new CriterionMapperCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 255);
  59. }
  60. private function shouldLoadCommerceBridge(ContainerBuilder $container): bool
  61. {
  62. if ($this->forceLoadingCommerceBridge) {
  63. return true;
  64. }
  65. $dependencies = [
  66. 'ibexa_commerce_eshop',
  67. 'ibexa_commerce_price',
  68. 'ibexa_commerce_checkout',
  69. 'ibexa_commerce_local_order_management',
  70. ];
  71. foreach ($dependencies as $dependency) {
  72. if (!$container->hasExtension($dependency)) {
  73. return false;
  74. }
  75. }
  76. return true;
  77. }
  78. }