Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
QueryModifierFactory.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
18  private $objectManager;
19 
23  private $queryModifiers;
24 
31  public function __construct(
32  ObjectManagerInterface $objectManager,
33  array $queryModifiers = []
34  ) {
35  $this->objectManager = $objectManager;
36  $this->queryModifiers = $queryModifiers;
37  }
38 
47  public function create($type, array $data = [])
48  {
49  if (!isset($this->queryModifiers[$type])) {
50  throw new \InvalidArgumentException('Unknown query modifier type ' . $type);
51  }
52  $queryModifier = $this->objectManager->create($this->queryModifiers[$type], $data);
53  if (!($queryModifier instanceof QueryModifierInterface)) {
54  throw new \InvalidArgumentException(
55  $this->queryModifiers[$type] . ' must implement ' . QueryModifierInterface::class
56  );
57  }
58  return $queryModifier;
59  }
60 }
$objectManager
Definition: bootstrap.php:17
$type
Definition: item.phtml:13
__construct(ObjectManagerInterface $objectManager, array $queryModifiers=[])