Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DataProviderFactory.php
Go to the documentation of this file.
1 <?php
7 
10 
16 {
20  private $objectManager;
21 
25  private $dataProvider;
26 
32  public function __construct(
33  ObjectManagerInterface $objectManager,
34  EngineResolverInterface $engineResolver,
35  $dataProviders
36  ) {
37  $this->objectManager = $objectManager;
38  $configValue = $engineResolver->getCurrentSearchEngine();
39  if (isset($dataProviders[$configValue])) {
40  $this->dataProvider = $dataProviders[$configValue];
41  } else {
42  throw new \LogicException("DataProvider not found by config {$configValue}");
43  }
44  }
45 
52  public function create(array $data = [])
53  {
54  $dataProvider = $this->objectManager->create($this->dataProvider, $data);
55  if (!$dataProvider instanceof DataProviderInterface) {
56  throw new \LogicException(
57  'DataProvider not instance of interface ' . DataProviderInterface::class
58  );
59  }
60  return $dataProvider;
61  }
62 }
$objectManager
Definition: bootstrap.php:17
__construct(ObjectManagerInterface $objectManager, EngineResolverInterface $engineResolver, $dataProviders)