Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConditionFactory.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Rule\Model;
7 
10 
12 {
16  private $objectManager;
17 
23  private $conditionModels = [];
24 
28  public function __construct(ObjectManagerInterface $objectManager)
29  {
30  $this->objectManager = $objectManager;
31  }
32 
46  public function create($type)
47  {
48  if (!array_key_exists($type, $this->conditionModels)) {
49  if (!class_exists($type)) {
50  throw new \InvalidArgumentException('Class does not exist');
51  }
52  if (!in_array(ConditionInterface::class, class_implements($type))) {
53  throw new \InvalidArgumentException('Class does not implement condition interface');
54  }
55  $this->conditionModels[$type] = $this->objectManager->create($type);
56  }
57 
58  return clone $this->conditionModels[$type];
59  }
60 }
$objectManager
Definition: bootstrap.php:17
$type
Definition: item.phtml:13
__construct(ObjectManagerInterface $objectManager)