vendor/shopware/elasticsearch/Elasticsearch.php line 28

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Elasticsearch;
  3. use Shopware\Core\Framework\Bundle;
  4. use Shopware\Core\Framework\Log\Package;
  5. use Shopware\Core\Kernel;
  6. use Shopware\Elasticsearch\DependencyInjection\ElasticsearchExtension;
  7. use Shopware\Elasticsearch\Profiler\ElasticsearchProfileCompilerPass;
  8. use Symfony\Component\Config\FileLocator;
  9. use Symfony\Component\Config\Loader\DelegatingLoader;
  10. use Symfony\Component\Config\Loader\LoaderResolver;
  11. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
  14. use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
  15. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  16. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  17. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  18. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  19. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  20. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  21. /**
  22.  * @internal
  23.  */
  24. #[Package('core')]
  25. class Elasticsearch extends Bundle
  26. {
  27.     public function getTemplatePriority(): int
  28.     {
  29.         return -1;
  30.     }
  31.     public function build(ContainerBuilder $container): void
  32.     {
  33.         parent::build($container);
  34.         // Needs to run before the ProfilerPass
  35.         $container->addCompilerPass(new ElasticsearchProfileCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION5000);
  36.         $this->buildConfig($container);
  37.     }
  38.     protected function createContainerExtension(): ?ExtensionInterface
  39.     {
  40.         return new ElasticsearchExtension();
  41.     }
  42.     private function buildConfig(ContainerBuilder $container): void
  43.     {
  44.         $locator = new FileLocator('Resources/config');
  45.         $resolver = new LoaderResolver([
  46.             new XmlFileLoader($container$locator),
  47.             new YamlFileLoader($container$locator),
  48.             new IniFileLoader($container$locator),
  49.             new PhpFileLoader($container$locator),
  50.             new GlobFileLoader($container$locator),
  51.             new DirectoryLoader($container$locator),
  52.             new ClosureLoader($container),
  53.         ]);
  54.         $configLoader = new DelegatingLoader($resolver);
  55.         $confDir $this->getPath() . '/Resources/config';
  56.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  57.         $env $container->getParameter('kernel.environment');
  58.         if (!\is_string($env)) {
  59.             throw new \RuntimeException('Container parameter "kernel.environment" needs to be a string');
  60.         }
  61.         $configLoader->load($confDir '/{packages}/' $env '/*' Kernel::CONFIG_EXTS'glob');
  62.     }
  63. }