![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-rule/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Rule\Model; use Magento\Framework\ObjectManagerInterface; use Magento\Rule\Model\Condition\ConditionInterface; class ConditionFactory { /** * @var ObjectManagerInterface */ private $objectManager; /** * Store all used condition models * * @var array */ private $conditionModels = []; /** * @param ObjectManagerInterface $objectManager */ public function __construct(ObjectManagerInterface $objectManager) { $this->objectManager = $objectManager; } /** * 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. * * @param string $type * * @return \Magento\Rule\Model\Condition\ConditionInterface * * @throws \LogicException * @throws \BadMethodCallException * @throws \InvalidArgumentException */ public function create($type) { if (!array_key_exists($type, $this->conditionModels)) { if (!class_exists($type)) { throw new \InvalidArgumentException('Class does not exist'); } if (!in_array(ConditionInterface::class, class_implements($type))) { throw new \InvalidArgumentException('Class does not implement condition interface'); } $this->conditionModels[$type] = $this->objectManager->create($type); } return clone $this->conditionModels[$type]; } }