platform/src/Elasticsearch/Elasticsearch.php line 22

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\Loader\ClosureLoader;
  13. use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
  14. use Symfony\Component\DependencyInjection\Loader\GlobFileLoader;
  15. use Symfony\Component\DependencyInjection\Loader\IniFileLoader;
  16. use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
  17. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  18. use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
  19. class Elasticsearch extends Bundle
  20. {
  21.     protected $name 'Elasticsearch';
  22.     public function build(ContainerBuilder $container): void
  23.     {
  24.         parent::build($container);
  25.         // Needs to run before the ProfilerPass
  26.         $container->addCompilerPass(new ElasticsearchProfileCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION5000);
  27.         $this->buildConfig($container);
  28.     }
  29.     public function createContainerExtension()
  30.     {
  31.         return new ElasticsearchExtension();
  32.     }
  33.     private function buildConfig(ContainerBuilder $container): void
  34.     {
  35.         $locator = new FileLocator('Resources/config');
  36.         $resolver = new LoaderResolver([
  37.             new XmlFileLoader($container$locator),
  38.             new YamlFileLoader($container$locator),
  39.             new IniFileLoader($container$locator),
  40.             new PhpFileLoader($container$locator),
  41.             new GlobFileLoader($container$locator),
  42.             new DirectoryLoader($container$locator),
  43.             new ClosureLoader($container),
  44.         ]);
  45.         $configLoader = new DelegatingLoader($resolver);
  46.         $confDir $this->getPath() . '/Resources/config';
  47.         $configLoader->load($confDir '/{packages}/*' Kernel::CONFIG_EXTS'glob');
  48.         $env $container->getParameter('kernel.environment');
  49.         if (!\is_string($env)) {
  50.             throw new \RuntimeException('Container parameter "kernel.environment" needs to be a string');
  51.         }
  52.         $configLoader->load($confDir '/{packages}/' $env '/*' Kernel::CONFIG_EXTS'glob');
  53.     }
  54. }