Esempio n. 1
0
 /**
  * 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);
     }
 }
Esempio n. 2
0
 /**
  * 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);
     }
 }
Esempio n. 3
0
 /**
  * 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');
     }
 }