Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
ConditionFactory Class Reference

Public Member Functions

 __construct (ObjectManagerInterface $objectManager)
 
 create ($type)
 

Detailed Description

Definition at line 11 of file ConditionFactory.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ObjectManagerInterface  $objectManager)
Parameters
ObjectManagerInterface$objectManager

Definition at line 28 of file ConditionFactory.php.

29  {
30  $this->objectManager = $objectManager;
31  }
$objectManager
Definition: bootstrap.php:17

Member Function Documentation

◆ create()

create (   $type)

Create new object for each requested model. If model is requested first time, store it at array. It's made by performance reasons to avoid initialization of same models each time when rules are being processed.

Parameters
string$type
Returns
\Magento\Rule\Model\Condition\ConditionInterface
Exceptions

Definition at line 46 of file ConditionFactory.php.

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  }
$type
Definition: item.phtml:13

The documentation for this class was generated from the following file: