/** * Asserts that item type is collection defined type * * @param string $instanceName * @param string|int|null $index * @return void * @throws \InvalidArgumentException */ private function assertValidTypeLazy($instanceName, $index = null) { $realType = $this->configInterface->getInstanceType($this->configInterface->getPreference($instanceName)); if (!in_array($this->type, array_unique(array_merge(class_parents($realType), class_implements($realType))), true)) { $this->throwTypeException($realType, $index); } }
/** * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\Registry $coreRegistry * @param \Magento\Framework\ObjectManager\ConfigInterface $config */ public function __construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\ObjectManager\ConfigInterface $config, \Magento\Backend\App\ConfigInterface $backendConfig) { $this->_coreRegistry = $coreRegistry; $this->_preferences = $config->getPreferences(); $this->addDevToolData($this->preferencesKey, $this->_preferences); parent::__construct($context); }
/** * Asserts that item type is collection defined type * * @param string $instanceName * @param string|int|null $index * @return void * @throws \InvalidArgumentException */ private function assertValidTypeLazy($instanceName, $index = null) { $realType = $this->configInterface->getInstanceType($this->configInterface->getPreference($instanceName)); if (!in_array($this->type, $this->classReaderInterface->getParents($realType), true)) { $this->throwTypeException($realType, $index); } }
/** * Create instance with call time arguments * * @param string $requestedType * @param array $arguments * @return object * @throws \Exception * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function create($requestedType, array $arguments = []) { $args = $this->config->getArguments($requestedType); $type = $this->config->getInstanceType($requestedType); if (!$args) { return new $type(); } foreach ($args as $key => &$argument) { if (isset($arguments[$key])) { $argument = $arguments[$key]; } elseif (isset($argument['_i_'])) { $argument = $this->get($argument['_i_']); } elseif (isset($argument['_ins_'])) { $argument = $this->create($argument['_ins_']); } elseif (isset($argument['_v_'])) { $argument = $argument['_v_']; } elseif (isset($argument['_vac_'])) { $argument = $argument['_vac_']; $this->parseArray($argument); } elseif (isset($argument['_vn_'])) { $argument = null; } elseif (isset($argument['_a_'])) { if (isset($this->globalArguments[$argument['_a_']])) { $argument = $this->globalArguments[$argument['_a_']]; } else { $argument = $argument['_d_']; } } } $args = array_values($args); return $this->createObject($type, $args); }
/** * Parse array argument * * @param array $array * * @return void */ protected function parseArray(&$array) { foreach ($array as $key => $item) { if ($item === (array)$item) { if (isset($item['instance'])) { if (isset($item['shared'])) { $isShared = $item['shared']; } else { $isShared = $this->config->isShared($item['instance']); } if ($isShared) { $array[$key] = $this->objectManager->get($item['instance']); } else { $array[$key] = $this->objectManager->create($item['instance']); } } elseif (isset($item['argument'])) { if (isset($this->globalArguments[$item['argument']])) { $array[$key] = $this->globalArguments[$item['argument']]; } else { $array[$key] = null; } } else { $this->parseArray($array[$key]); } } } }
/** * @return CartItemProcessorInterface[] * @deprecated */ public function getCartItemProcessors() { if (!empty($this->cartItemProcessors)) { return $this->cartItemProcessors; } $arguments = $this->objectManagerConfig->getArguments(\Magento\Quote\Model\Quote\Item\Repository::class); if (isset($arguments['cartItemProcessors'])) { // Workaround for compiled mode. $processors = isset($arguments['cartItemProcessors']['_vac_']) ? $arguments['cartItemProcessors']['_vac_'] : $arguments['cartItemProcessors']; foreach ($processors as $name => $processor) { $className = isset($processor['instance']) ? $processor['instance'] : $processor['_i_']; $this->cartItemProcessors[$name] = ObjectManager::getInstance()->get($className); } } return $this->cartItemProcessors; }
/** * Returns instance argument * * @param string $instanceType * @return array|mixed */ private function getInstanceArgument($instanceType) { if ($this->diContainerConfig->isShared($instanceType)) { $argument = $this->sharedInstancePattern; $argument['_i_'] = $instanceType; } else { $argument = $this->notSharedInstancePattern; $argument['_ins_'] = $instanceType; } return $argument; }
/** * Identify type of objects which should be built with generated builder. Value can be one of self::TYPE_DATA_*. * * @return string * @throws \LogicException */ protected function getDataType() { $dataType = $this->_getDataObjectType(); if (is_subclass_of($dataType, '\\Magento\\Framework\\Api\\AbstractSimpleObject')) { return self::TYPE_DATA_OBJECT; } elseif (is_subclass_of($dataType, '\\Magento\\Framework\\Model\\AbstractExtensibleModel')) { return self::TYPE_DATA_MODEL; } $sourceClassPreference = $this->objectManagerConfig->getPreference($dataType); if (empty($sourceClassPreference)) { throw new \LogicException("Preference for {$this->_getDataObjectType()} is not defined."); } if (is_subclass_of($sourceClassPreference, '\\Magento\\Framework\\Api\\AbstractSimpleObject')) { return self::TYPE_DATA_OBJECT; } elseif (is_subclass_of($sourceClassPreference, '\\Magento\\Framework\\Model\\AbstractExtensibleModel')) { return self::TYPE_DATA_MODEL; } else { throw new \LogicException('Preference of ' . $this->_getDataObjectType() . ' must extend from AbstractSimpleObject or AbstractExtensibleModel'); } }
/** * Returns preferences for third party code * * @param ConfigInterface $config * @param DefinitionsCollection $definitionsCollection * @SuppressWarnings(PHPMD.UnusedLocalVariable) * * @return void */ private function fillThirdPartyInterfaces(ConfigInterface $config, DefinitionsCollection $definitionsCollection) { $definedInstances = $definitionsCollection->getInstancesNamesList(); foreach ($config->getPreferences() as $interface => $preference) { if (in_array($interface, $definedInstances)) { continue; } $definitionsCollection->addDefinition($interface, []); } }
/** * Returns instance argument * * @param string $instanceType * @return array|mixed */ private function getInstanceArgument($instanceType) { return $this->diContainerConfig->isShared($instanceType) ? $instanceType : self::getNonSharedInstance($instanceType); }