vendor/shopware/elasticsearch/Elasticsearch.php line 26

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