Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AdapterFactory.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Search\Model;
7 
9 
15 {
22  protected $scopeConfig;
23 
29  protected $objectManager;
30 
37  protected $path;
38 
43  protected $scope;
44 
50  private $adapterPool;
51 
55  private $engineResolver;
56 
62  public function __construct(
64  array $adapters,
65  EngineResolverInterface $engineResolver
66  ) {
67  $this->objectManager = $objectManager;
68  $this->adapterPool = $adapters;
69  $this->engineResolver = $engineResolver;
70  }
71 
78  public function create(array $data = [])
79  {
80  $currentAdapter = $this->engineResolver->getCurrentSearchEngine();
81  if (!isset($this->adapterPool[$currentAdapter])) {
82  throw new \LogicException(
83  'There is no such adapter: ' . $currentAdapter
84  );
85  }
86  $adapterClass = $this->adapterPool[$currentAdapter];
87  $adapter = $this->objectManager->create($adapterClass, $data);
88  if (!($adapter instanceof \Magento\Framework\Search\AdapterInterface)) {
89  throw new \InvalidArgumentException(
90  'Adapter must implement \Magento\Framework\Search\AdapterInterface'
91  );
92  }
93  return $adapter;
94  }
95 }
__construct(\Magento\Framework\ObjectManagerInterface $objectManager, array $adapters, EngineResolverInterface $engineResolver)
$adapter
Definition: webapi_user.php:16