Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexStructureFactory.php
Go to the documentation of this file.
1 <?php
7 
11 
19 {
26  protected $objectManager = null;
27 
34  protected $structures = null;
38  private $engineResolver;
39 
47  public function __construct(
49  EngineResolverInterface $engineResolver,
50  array $structures = []
51  ) {
52  $this->objectManager = $objectManager;
53  $this->structures = $structures;
54  $this->engineResolver = $engineResolver;
55  }
56 
64  public function create(array $data = [])
65  {
66  $currentStructure = $this->engineResolver->getCurrentSearchEngine();
67  if (!isset($this->structures[$currentStructure])) {
68  throw new \LogicException(
69  'There is no such index structure: ' . $currentStructure
70  );
71  }
72  $indexStructure = $this->objectManager->create($this->structures[$currentStructure], $data);
73 
74  if (!$indexStructure instanceof IndexStructureInterface) {
75  throw new \InvalidArgumentException(
76  $currentStructure . ' index structure doesn\'t implement '. IndexStructureInterface::class
77  );
78  }
79 
80  return $indexStructure;
81  }
82 }
__construct(ObjectManagerInterface $objectManager, EngineResolverInterface $engineResolver, array $structures=[])