ClientFactoryProxy.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Elasticsearch\Elasticsearch5\Model\Client;
  7. use Magento\AdvancedSearch\Model\Client\ClientFactoryInterface;
  8. use Magento\AdvancedSearch\Model\Client\ClientResolver;
  9. /**
  10. * Proxy for client factories
  11. */
  12. class ClientFactoryProxy implements ClientFactoryInterface
  13. {
  14. /**
  15. * @var ClientResolver
  16. */
  17. private $clientResolver;
  18. /**
  19. * @var ClientFactoryInterface[]
  20. */
  21. private $clientFactories;
  22. /**
  23. * CategoryFieldsProviderProxy constructor.
  24. * @param ClientResolver $clientResolver
  25. * @param ClientFactoryInterface[] $clientFactories
  26. */
  27. public function __construct(
  28. ClientResolver $clientResolver,
  29. array $clientFactories
  30. ) {
  31. $this->clientResolver = $clientResolver;
  32. $this->clientFactories = $clientFactories;
  33. }
  34. /**
  35. * @return ClientFactoryInterface
  36. */
  37. private function getClientFactory()
  38. {
  39. return $this->clientFactories[$this->clientResolver->getCurrentEngine()];
  40. }
  41. /**
  42. * @inheritdoc
  43. */
  44. public function create(array $options = [])
  45. {
  46. return $this->getClientFactory()->create($options);
  47. }
  48. }