Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexSwitcherProxy.php
Go to the documentation of this file.
1 <?php
8 
11 
16 {
22  private $objectManager = null;
23 
29  private $handlers;
30 
34  private $engineResolver;
35 
43  public function __construct(
44  ObjectManagerInterface $objectManager,
45  EngineResolverInterface $engineResolver,
46  array $handlers = []
47  ) {
48  $this->objectManager = $objectManager;
49  $this->handlers = $handlers;
50  $this->engineResolver = $engineResolver;
51  }
52 
62  public function switchIndex(array $dimensions)
63  {
64  $currentHandler = $this->engineResolver->getCurrentSearchEngine();
65  if (!isset($this->handlers[$currentHandler])) {
66  return;
67  }
68  $this->create($currentHandler)->switchIndex($dimensions);
69  }
70 
77  private function create($handler)
78  {
79  $indexSwitcher = $this->objectManager->create($this->handlers[$handler]);
80 
81  if (!$indexSwitcher instanceof IndexSwitcherInterface) {
82  throw new \InvalidArgumentException(
83  $handler . ' index switcher doesn\'t implement ' . IndexSwitcherInterface::class
84  );
85  }
86 
87  return $indexSwitcher;
88  }
89 }
$objectManager
Definition: bootstrap.php:17
__construct(ObjectManagerInterface $objectManager, EngineResolverInterface $engineResolver, array $handlers=[])
catch(\Exception $e) $handler
Definition: index.php:30