objectManager = $objectManager; $this->adapterPool = $adapters; $this->engineResolver = $engineResolver; } /** * Create Adapter instance * * @param array $data * @return \Magento\Framework\Search\AdapterInterface */ public function create(array $data = []) { $currentAdapter = $this->engineResolver->getCurrentSearchEngine(); if (!isset($this->adapterPool[$currentAdapter])) { throw new \LogicException( 'There is no such adapter: ' . $currentAdapter ); } $adapterClass = $this->adapterPool[$currentAdapter]; $adapter = $this->objectManager->create($adapterClass, $data); if (!($adapter instanceof \Magento\Framework\Search\AdapterInterface)) { throw new \InvalidArgumentException( 'Adapter must implement \Magento\Framework\Search\AdapterInterface' ); } return $adapter; } }