/**
  * @expectedException \LogicException
  * @expectedExceptionMessage Class "\Some\Class" does not exist. Please note that namespace must be specified.
  */
 public function testResolveObjectTypeWithConfiguredAttributeAndNonExistedClass()
 {
     $code = 'some_code';
     $value = new \stdClass();
     $context = '\\Some\\Class';
     $config = ['Some\\Class' => ['some_code' => ['type' => '\\Some\\Class']]];
     $this->typeProcessor->expects($this->once())->method('getArrayItemType')->with('\\Some\\Class')->willReturn('\\Some\\Class');
     $this->configMock->expects($this->once())->method('get')->willReturn($config);
     $this->model->resolveObjectType($code, $value, $context);
 }
Exemplo n.º 2
0
 /**
  * Ensure that specified type is either a simple type or a valid service data type.
  *
  * @param string $typeName
  * @return $this
  * @throws \Exception In case when type is invalid
  */
 protected function validateType($typeName)
 {
     if ($this->typeProcessor->isTypeSimple($typeName)) {
         return $this;
     }
     if ($this->typeProcessor->isArrayType($typeName)) {
         $arrayItemType = $this->typeProcessor->getArrayItemType($typeName);
         $this->methodsMap->getMethodsMap($arrayItemType);
     } else {
         $this->methodsMap->getMethodsMap($typeName);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * All types names should be absolute (include namespace) in the registry.
  * First '\' will be removed if exists.
  * Array types (\Some\Type[]) will be converted into simple types (Some\Type).
  * Simple types names will be converted to it's canonical versions (bool => boolean).
  *
  * @param string $type
  * @return string
  */
 public function normalizeType($type)
 {
     $result = $this->_typeProcessor->normalizeType($type);
     if ($result && $result[0] == '\\') {
         $result = substr($result, 1);
         // remove leading slash
     }
     if ($this->isArray($result)) {
         $result = substr($result, 0, -2);
         // remove '[]' at the end
     }
     return $result;
 }
Exemplo n.º 4
0
 public function testGetParameterDescription()
 {
     $class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
     $methodReflection = $class->getMethod('setName');
     $paramsReflection = $methodReflection->getParameters();
     $this->assertEquals('Name of the attribute', $this->_typeProcessor->getParamDescription($paramsReflection[0]));
 }
 /**
  * Analyze $type and save type properties into the registry.
  *
  * @param string $type
  * @return \Praxigento\Core\Reflection\Data\Property[] array with type properties or empty array for simple types.
  */
 public function register($type)
 {
     $typeNorm = $this->_toolsType->normalizeType($type);
     $isSimple = $this->_typeProcessor->isTypeSimple($typeNorm);
     if (!isset($this->_registry[$typeNorm])) {
         if (!$isSimple) {
             /* analyze properties for complex type */
             $this->_registry[$typeNorm] = [];
             /* process annotated methods */
             /** @var \Zend\Code\Reflection\ClassReflection $reflection */
             $reflection = new \Zend\Code\Reflection\ClassReflection($typeNorm);
             $docBlock = $reflection->getDocBlock();
             if ($docBlock) {
                 $this->_processDocBlock($typeNorm, $docBlock);
             }
             /* process normal methods (not annotated) */
             $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
             $this->_processMethods($typeNorm, $methods);
         } else {
             /* this is simple type w/o props */
             $this->_registry[$typeNorm] = [];
         }
     }
     return $this->_registry[$typeNorm];
 }
Exemplo n.º 6
0
 /**
  * @param ExtensibleDataInterface $dataObject
  * @param string $getterMethodName
  * @param string $methodName
  * @param array $value
  * @param string $interfaceName
  * @return $this
  */
 protected function setComplexValue(ExtensibleDataInterface $dataObject, $getterMethodName, $methodName, array $value, $interfaceName)
 {
     if ($interfaceName == null) {
         $interfaceName = get_class($dataObject);
     }
     $returnType = $this->methodsMapProcessor->getMethodReturnType($interfaceName, $getterMethodName);
     if ($this->typeProcessor->isTypeSimple($returnType)) {
         $dataObject->{$methodName}($value);
         return $this;
     }
     if ($this->typeProcessor->isArrayType($returnType)) {
         $type = $this->typeProcessor->getArrayItemType($returnType);
         $objects = [];
         foreach ($value as $arrayElementData) {
             $object = $this->objectFactory->create($type, []);
             $this->populateWithArray($object, $arrayElementData, $type);
             $objects[] = $object;
         }
         $dataObject->{$methodName}($objects);
         return $this;
     }
     if (is_subclass_of($returnType, '\\Magento\\Framework\\Api\\ExtensibleDataInterface')) {
         $object = $this->objectFactory->create($returnType, []);
         $this->populateWithArray($object, $value, $returnType);
     } else {
         if (is_subclass_of($returnType, '\\Magento\\Framework\\Api\\ExtensionAttributesInterface')) {
             $object = $this->extensionFactory->create(get_class($dataObject), $value);
         } else {
             $object = $this->objectFactory->create($returnType, $value);
         }
     }
     $dataObject->{$methodName}($object);
     return $this;
 }
 /**
  * Convert data from array to Data Object representation if type is Data Object or array of Data Objects.
  *
  * @param mixed $data
  * @param string $type Convert given value to the this type
  * @return mixed
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function convertValue($data, $type)
 {
     $isArrayType = $this->typeProcessor->isArrayType($type);
     if ($isArrayType && isset($data['item'])) {
         $data = $this->_removeSoapItemNode($data);
     }
     if ($this->typeProcessor->isTypeSimple($type) || $this->typeProcessor->isTypeAny($type)) {
         $result = $this->typeProcessor->processSimpleAndAnyType($data, $type);
     } else {
         /** Complex type or array of complex types */
         if ($isArrayType) {
             // Initializing the result for array type else it will return null for empty array
             $result = is_array($data) ? [] : null;
             $itemType = $this->typeProcessor->getArrayItemType($type);
             if (is_array($data)) {
                 foreach ($data as $key => $item) {
                     $result[$key] = $this->_createFromArray($itemType, $item);
                 }
             }
         } else {
             $result = $this->_createFromArray($type, $data);
         }
     }
     return $result;
 }
 /** @inheritdoc */
 protected function _processMethod(\Zend\Code\Reflection\MethodReflection $methodReflection, $typeName)
 {
     /* skip basic methods of the DataObjects */
     $name = $methodReflection->getName();
     if ($name != self::SKIP_DATA && $name != self::SKIP_ITERATOR && $name != self::SKIP_DATA_UNSET) {
         parent::_processMethod($methodReflection, $typeName);
     }
 }
 /**
  * Collect data about complex types call info.
  *
  * Walks through all requested services and checks all methods 'in' and 'out' parameters.
  *
  * @param array $requestedServiceMetadata
  * @return void
  */
 protected function collectCallInfo($requestedServiceMetadata)
 {
     foreach ($requestedServiceMetadata as $serviceName => $serviceData) {
         foreach ($serviceData['methods'] as $methodName => $methodData) {
             $this->typeProcessor->processInterfaceCallInfo($methodData['interface'], $serviceName, $methodName);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function resolveObjectType($attributeCode, $value, $context)
 {
     if (!is_object($value)) {
         throw new \InvalidArgumentException('Provided value is not object type');
     }
     $data = $this->config->get();
     $context = trim($context, '\\');
     $config = isset($data[$context]) ? $data[$context] : [];
     $output = get_class($value);
     if (isset($config[$attributeCode])) {
         $type = $config[$attributeCode]['type'];
         $output = $this->typeProcessor->getArrayItemType($type);
         if (!(class_exists($output) || interface_exists($output))) {
             throw new \LogicException(sprintf('Class "%s" does not exist. Please note that namespace must be specified.', $type));
         }
     }
     return $output;
 }
Exemplo n.º 11
0
 /**
  * Retrieve method full documentation description.
  *
  * @param \Zend\Code\Reflection\MethodReflection $method
  * @return string
  */
 protected function extractMethodDescription(\Zend\Code\Reflection\MethodReflection $method)
 {
     $methodReflection = new MethodReflection($method->getDeclaringClass()->getName(), $method->getName());
     $docBlock = $methodReflection->getDocBlock();
     if (!$docBlock) {
         throw new \LogicException('The docBlock of the method ' . $method->getDeclaringClass()->getName() . '::' . $method->getName() . ' is empty.');
     }
     return $this->_typeProcessor->getDescription($docBlock);
 }
Exemplo n.º 12
0
 /**
  * Retrieve class full documentation description.
  *
  * @param string $className
  * @return string
  */
 public function extractClassDescription($className)
 {
     $classReflection = new \Zend\Code\Reflection\ClassReflection($className);
     $docBlock = $classReflection->getDocBlock();
     if (!$docBlock) {
         return '';
     }
     return $this->_typeProcessor->getDescription($docBlock);
 }
Exemplo n.º 13
0
 /**
  * Test exception for handle
  *
  * @expectedException        \Magento\Framework\Webapi\Exception
  * @expectedExceptionMessage exception message
  */
 public function testHandleWithException()
 {
     $genWSDL = 'generatedWSDL';
     $exceptionMsg = 'exception message';
     $requestedService = ['catalogProduct'];
     $serviceMetadata = ['methods' => ['methodName' => ['interface' => 'aInterface']]];
     $this->serviceMetadata->expects($this->any())->method('getServiceMetadata')->willReturn($serviceMetadata);
     $this->_typeProcessor->expects($this->once())->method('processInterfaceCallInfo')->willThrowException(new \Magento\Framework\Webapi\Exception(__($exceptionMsg)));
     $this->assertEquals($genWSDL, $this->_wsdlGenerator->generate($requestedService, 'http://', 'magento.host', '/soap/default'));
 }
Exemplo n.º 14
0
 /**
  * Retrieve method info
  *
  * @param \ReflectionMethod $method
  * @return array
  */
 protected function _getMethodInfo(\ReflectionMethod $method)
 {
     if (substr($method->getName(), 0, 2) == 'is') {
         $propertyName = substr($method->getName(), 2);
     } else {
         $propertyName = substr($method->getName(), 3);
     }
     $returnType = $this->typeProcessor->getGetterReturnType((new ClassReflection($this->_getSourceClassName()))->getMethod($method->getName()));
     $fieldName = strtolower(preg_replace('/(.)([A-Z])/', "\$1_\$2", $propertyName));
     $methodInfo = ['name' => 'set' . $propertyName, 'parameters' => [['name' => lcfirst($propertyName)]], 'body' => "\$this->_set('{$fieldName}', \$" . lcfirst($propertyName) . ");" . PHP_EOL . "return \$this;", 'docblock' => ['tags' => [['name' => 'param', 'description' => $returnType['type'] . " \$" . lcfirst($propertyName)], ['name' => 'return', 'description' => '$this']]]];
     return $methodInfo;
 }
 /**
  * Add separate flow for annotated data objects, all other objects are processed by original code.
  *
  * @param \Magento\Framework\Webapi\ServiceInputProcessor $subject
  * @param \Closure $proceed
  * @param $data
  * @param $type
  * @return mixed
  */
 public function aroundConvertValue(\Magento\Framework\Webapi\ServiceInputProcessor $subject, \Closure $proceed, $data, $type)
 {
     $result = null;
     if (is_subclass_of($type, \Flancer32\Lib\DataObject::class)) {
         if ($this->_typeProcessor->isTypeSimple($type) || $this->_typeProcessor->isTypeAny($type)) {
             $result = $this->_typeProcessor->processSimpleAndAnyType($data, $type);
         } else {
             /** Complex type or array of complex types */
             $isArrayType = $this->_typeProcessor->isArrayType($type);
             if ($isArrayType) {
                 // Initializing the result for array type else it will return null for empty array
                 $itemType = $this->_typeProcessor->getArrayItemType($type);
                 if (is_array($data)) {
                     $result = [];
                     foreach ($data as $key => $item) {
                         $result[$key] = $this->_parser->parseArrayData($itemType, $item);
                     }
                 }
             } else {
                 if (is_null($data)) {
                     // do nothing, result is null
                 } else {
                     $result = $this->_parser->parseArrayData($type, $data);
                 }
             }
         }
     } else {
         $result = $proceed($data, $type);
     }
     return $result;
 }
Exemplo n.º 16
0
 /**
  * @param mixed $dataObject
  * @param string $getterMethodName
  * @param string $methodName
  * @param array $value
  * @param string $interfaceName
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function setComplexValue($dataObject, $getterMethodName, $methodName, array $value, $interfaceName)
 {
     if ($interfaceName == null) {
         $interfaceName = get_class($dataObject);
     }
     $returnType = $this->methodsMapProcessor->getMethodReturnType($interfaceName, $getterMethodName);
     if ($this->typeProcessor->isTypeSimple($returnType)) {
         $dataObject->{$methodName}($value);
         return $this;
     }
     if ($this->typeProcessor->isArrayType($returnType)) {
         $type = $this->typeProcessor->getArrayItemType($returnType);
         $objects = [];
         foreach ($value as $arrayElementData) {
             $object = $this->objectFactory->create($type, []);
             $this->populateWithArray($object, $arrayElementData, $type);
             $objects[] = $object;
         }
         $dataObject->{$methodName}($objects);
         return $this;
     }
     if (is_subclass_of($returnType, '\\Magento\\Framework\\Api\\ExtensibleDataInterface')) {
         $object = $this->objectFactory->create($returnType, []);
         $this->populateWithArray($object, $value, $returnType);
     } else {
         if (is_subclass_of($returnType, '\\Magento\\Framework\\Api\\ExtensionAttributesInterface')) {
             foreach ($value as $extensionAttributeKey => $extensionAttributeValue) {
                 $extensionAttributeGetterMethodName = 'get' . \Magento\Framework\Api\SimpleDataObjectConverter::snakeCaseToUpperCamelCase($extensionAttributeKey);
                 $methodReturnType = $this->methodsMapProcessor->getMethodReturnType($returnType, $extensionAttributeGetterMethodName);
                 $extensionAttributeType = $this->typeProcessor->isArrayType($methodReturnType) ? $this->typeProcessor->getArrayItemType($methodReturnType) : $methodReturnType;
                 if ($this->typeProcessor->isTypeSimple($extensionAttributeType)) {
                     $value[$extensionAttributeKey] = $extensionAttributeValue;
                 } else {
                     if ($this->typeProcessor->isArrayType($methodReturnType)) {
                         foreach ($extensionAttributeValue as $key => $extensionAttributeArrayValue) {
                             $extensionAttribute = $this->objectFactory->create($extensionAttributeType, []);
                             $this->populateWithArray($extensionAttribute, $extensionAttributeArrayValue, $extensionAttributeType);
                             $value[$extensionAttributeKey][$key] = $extensionAttribute;
                         }
                     } else {
                         $value[$extensionAttributeKey] = $this->objectFactory->create($extensionAttributeType, ['data' => $extensionAttributeValue]);
                     }
                 }
             }
             $object = $this->extensionFactory->create(get_class($dataObject), ['data' => $value]);
         } else {
             $object = $this->objectFactory->create($returnType, $value);
         }
     }
     $dataObject->{$methodName}($object);
     return $this;
 }
Exemplo n.º 17
0
 /**
  * @param array $typeData
  * @param array $expected
  * @dataProvider testGenerateDefinitionDataProvider
  */
 public function testGenerateDefinition($typeData, $expected)
 {
     $getTypeData = function ($type) use($typeData) {
         return $typeData[$type];
     };
     $this->typeProcessorMock->method('getTypeData')->will($this->returnCallback($getTypeData));
     $method = new \ReflectionMethod($this->generator, 'generateDefinition');
     $method->setAccessible(true);
     $actual = $method->invoke($this->generator, key($typeData));
     ksort($expected);
     ksort($actual);
     $this->assertSame(json_encode($expected), json_encode($actual));
 }
 /**
  * Process different element types.
  *
  * @param string $elementType
  * @param string $documentation
  * @param \DOMElement $appInfoNode
  * @return void
  */
 protected function _processElementType($elementType, $documentation, \DOMElement $appInfoNode)
 {
     if ($elementType == 'int') {
         $this->_processRequiredAnnotation('min', $documentation, $appInfoNode);
         $this->_processRequiredAnnotation('max', $documentation, $appInfoNode);
     }
     if ($elementType == 'string') {
         $this->_processRequiredAnnotation('maxLength', $documentation, $appInfoNode);
     }
     if ($this->_typeProcessor->isArrayType($elementType)) {
         $natureOfTypeNode = $this->_getDom()->createElement(self::APP_INF_NS . ':natureOfType');
         $natureOfTypeNode->appendChild($this->_getDom()->createTextNode('array'));
         $appInfoNode->appendChild($natureOfTypeNode);
     }
 }
 /**
  * Test adding complex type with complex parameters and arrays.
  */
 public function testAddComplexTypeComplexParameters()
 {
     $type = 'VendorModuleADataStructure';
     $parameterType = 'ComplexType';
     $typeData = ['documentation' => 'test', 'parameters' => ['complex_param' => ['type' => $parameterType, 'required' => true, 'documentation' => 'complex type param.']]];
     $parameterData = ['documentation' => 'test', 'parameters' => ['string_param' => ['type' => 'ComplexTypeB[]', 'required' => true, 'documentation' => 'string param.']]];
     $this->_wsdl->expects($this->at(0))->method('getTypes')->will($this->returnValue([]));
     $this->_wsdl->expects($this->any())->method('getTypes')->will($this->returnValue([$type => Wsdl::TYPES_NS . ':' . $type]));
     $this->_wsdl->expects($this->any())->method('toDomDocument')->will($this->returnValue(new \DOMDocument()));
     $schemaMock = $this->getMock('DOMElement', [], ['a']);
     $schemaMock->expects($this->any())->method('appendChild');
     $this->_wsdl->expects($this->any())->method('getSchema')->will($this->returnValue($schemaMock));
     $this->_typeProcessor->expects($this->at(0))->method('getTypeData')->with($type)->will($this->returnValue($typeData));
     $this->_typeProcessor->expects($this->at(1))->method('getTypeData')->with($parameterType)->will($this->returnValue($parameterData));
     $this->assertEquals(Wsdl::TYPES_NS . ':' . $type, $this->_strategy->addComplexType($type));
 }
Exemplo n.º 20
0
 /**
  * Return routes loaded from cache if enabled or from files merged previously
  *
  * @return array
  */
 public function getRoutesConfig()
 {
     if (null === $this->routes) {
         $routesConfig = $this->cache->load(self::ROUTES_CONFIG_CACHE_ID);
         $typesData = $this->cache->load(self::REFLECTED_TYPES_CACHE_ID);
         if ($routesConfig && is_string($routesConfig) && $typesData && is_string($typesData)) {
             $this->routes = unserialize($routesConfig);
             $this->typeProcessor->setTypesData(unserialize($typesData));
         } else {
             $this->routes = $this->initRoutesMetadata();
             $this->cache->save(serialize($this->routes), self::ROUTES_CONFIG_CACHE_ID);
             $this->cache->save(serialize($this->typeProcessor->getTypesData()), self::REFLECTED_TYPES_CACHE_ID);
         }
     }
     return $this->routes;
 }
Exemplo n.º 21
0
 /**
  * Add WSDL elements related to generic SOAP fault, which are common for all operations: element, type and message.
  *
  * @param Wsdl $wsdl
  * @return string Default fault message name
  */
 protected function _addGenericFaultComplexTypeNodes($wsdl)
 {
     $faultMessageName = Fault::NODE_DETAIL_WRAPPER;
     $complexTypeName = $this->getElementComplexTypeName($faultMessageName);
     $wsdl->addElement(['name' => $faultMessageName, 'type' => Wsdl::TYPES_NS . ':' . $complexTypeName]);
     $faultParamsComplexType = Fault::NODE_DETAIL_PARAMETER;
     $faultParamsData = ['parameters' => [Fault::NODE_DETAIL_PARAMETER_KEY => ['type' => 'string', 'required' => true, 'documentation' => ''], Fault::NODE_DETAIL_PARAMETER_VALUE => ['type' => 'string', 'required' => true, 'documentation' => '']]];
     $wrappedErrorComplexType = Fault::NODE_DETAIL_WRAPPED_ERROR;
     $wrappedErrorData = ['parameters' => [Fault::NODE_DETAIL_WRAPPED_ERROR_MESSAGE => ['type' => 'string', 'required' => true, 'documentation' => ''], Fault::NODE_DETAIL_WRAPPED_ERROR_PARAMETERS => ['type' => "{$faultParamsComplexType}[]", 'required' => false, 'documentation' => 'Message parameters.']]];
     $genericFaultTypeData = ['parameters' => [Fault::NODE_DETAIL_TRACE => ['type' => 'string', 'required' => false, 'documentation' => 'Exception calls stack trace.'], Fault::NODE_DETAIL_PARAMETERS => ['type' => "{$faultParamsComplexType}[]", 'required' => false, 'documentation' => 'Additional exception parameters.'], Fault::NODE_DETAIL_WRAPPED_ERRORS => ['type' => "{$wrappedErrorComplexType}[]", 'required' => false, 'documentation' => 'Additional wrapped errors.']]];
     $this->_typeProcessor->setTypeData($faultParamsComplexType, $faultParamsData);
     $this->_typeProcessor->setTypeData($wrappedErrorComplexType, $wrappedErrorData);
     $this->_typeProcessor->setTypeData($complexTypeName, $genericFaultTypeData);
     $wsdl->addComplexType($complexTypeName);
     $wsdl->addMessage($faultMessageName, ['messageParameters' => ['element' => Wsdl::TYPES_NS . ':' . $faultMessageName]]);
     return Wsdl::TYPES_NS . ':' . $faultMessageName;
 }
Exemplo n.º 22
0
 /**
  * Retrieve requested service method params metadata.
  *
  * @param string $serviceClassName
  * @param string $serviceMethodName
  * @return array
  */
 protected function getMethodParams($serviceClassName, $serviceMethodName)
 {
     $cacheId = self::CACHE_ID_PREFIX . hash('md5', $serviceClassName . $serviceMethodName);
     $params = $this->cache->load($cacheId);
     if ($params !== false) {
         return unserialize($params);
     }
     $serviceClass = new ClassReflection($serviceClassName);
     /** @var MethodReflection $serviceMethod */
     $serviceMethod = $serviceClass->getMethod($serviceMethodName);
     $params = [];
     /** @var ParameterReflection $paramReflection */
     foreach ($serviceMethod->getParameters() as $paramReflection) {
         $isDefaultValueAvailable = $paramReflection->isDefaultValueAvailable();
         $params[] = ['name' => $paramReflection->getName(), 'type' => $this->typeProcessor->getParamType($paramReflection), 'isDefaultValueAvailable' => $isDefaultValueAvailable, 'defaultValue' => $isDefaultValueAvailable ? $paramReflection->getDefaultValue() : null];
     }
     $this->cache->save(serialize($params), $cacheId, [WebapiCache::CACHE_TAG]);
     return $params;
 }
Exemplo n.º 23
0
 /**
  * Use reflection to load the method information
  *
  * @param string $interfaceName
  * @return array
  */
 private function getMethodMapViaReflection($interfaceName)
 {
     $methodMap = [];
     $class = new ClassReflection($interfaceName);
     $baseClassMethods = false;
     foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         // Include all the methods of classes inheriting from AbstractExtensibleObject.
         // Ignore all the methods of AbstractExtensibleModel's parent classes
         if ($method->class === self::BASE_MODEL_CLASS) {
             $baseClassMethods = true;
         } elseif ($baseClassMethods) {
             // ReflectionClass::getMethods() sorts the methods by class (lowest in inheritance tree first)
             // then by the order they are defined in the class definition
             break;
         }
         if ($this->isSuitableMethod($method)) {
             $methodMap[$method->getName()] = $this->typeProcessor->getGetterReturnType($method);
         }
     }
     return $methodMap;
 }
Exemplo n.º 24
0
 /**
  * @param string $methodName
  * @param string $key
  * @param array $value
  * @return $this
  */
 protected function setComplexValue($methodName, $key, array $value)
 {
     $returnType = $this->objectProcessor->getMethodReturnType($this->_getDataObjectType(), $methodName);
     if ($this->typeProcessor->isTypeSimple($returnType)) {
         $this->data[$key] = $value;
         return $this;
     }
     if ($this->typeProcessor->isArrayType($returnType)) {
         $type = $this->typeProcessor->getArrayItemType($returnType);
         $dataBuilder = $this->dataBuilderFactory->getDataBuilder($type);
         $objects = [];
         foreach ($value as $arrayElementData) {
             $objects[] = $dataBuilder->populateWithArray($arrayElementData)->create();
         }
         $this->data[$key] = $objects;
         return $this;
     }
     $dataBuilder = $this->dataBuilderFactory->getDataBuilder($returnType);
     $object = $dataBuilder->populateWithArray($value)->create();
     $this->data[$key] = $object;
     return $this;
 }
Exemplo n.º 25
0
 /**
  * Populate a specific attribute code with join directive instructions.
  *
  * @param string $attributeCode
  * @param array $directive
  * @param array &$data
  * @param array &$extensionData
  * @param string $extensibleEntityClass
  * @return void
  */
 private function populateAttributeCodeWithDirective($attributeCode, $directive, &$data, &$extensionData, $extensibleEntityClass)
 {
     $attributeType = $directive[Converter::DATA_TYPE];
     $selectFields = $this->joinProcessorHelper->getSelectFieldsMap($attributeCode, $directive[Converter::JOIN_FIELDS]);
     foreach ($selectFields as $selectField) {
         $internalAlias = $selectField[JoinDataInterface::SELECT_FIELD_INTERNAL_ALIAS];
         if (isset($data[$internalAlias])) {
             if ($this->typeProcessor->isArrayType($attributeType)) {
                 throw new \LogicException(sprintf('Join directives cannot be processed for attribute (%s) of extensible entity (%s),' . ' which has an Array type (%s).', $attributeCode, $this->extensionAttributesFactory->getExtensibleInterfaceName($extensibleEntityClass), $attributeType));
             } elseif ($this->typeProcessor->isTypeSimple($attributeType)) {
                 $extensionData['data'][$attributeCode] = $data[$internalAlias];
                 unset($data[$internalAlias]);
                 break;
             } else {
                 if (!isset($extensionData['data'][$attributeCode])) {
                     $extensionData['data'][$attributeCode] = $this->objectManager->create($attributeType);
                 }
                 $setterName = $selectField[JoinDataInterface::SELECT_FIELD_SETTER];
                 $extensionData['data'][$attributeCode]->{$setterName}($data[$internalAlias]);
                 unset($data[$internalAlias]);
             }
         }
     }
 }
 /**
  * Set up helper.
  */
 protected function setUp()
 {
     $this->_typeProcessor = $this->getMock('\\Magento\\Framework\\Reflection\\TypeProcessor', ['process'], [], '', false);
     $this->_typeProcessor->expects($this->any())->method('process')->will($this->returnValueMap([['string', 'str'], ['int', 'int']]));
     $this->_classReflector = new \Magento\Webapi\Model\Config\ClassReflector($this->_typeProcessor);
 }
Exemplo n.º 27
0
 /**
  * @expectedException \Magento\Framework\Exception\SerializationException
  * @expectedExceptionMessage Invalid type for value :"1". Expected Type: "int[]".
  */
 public function testProcessSimpleTypeInvalidType()
 {
     $value = 1;
     $type = 'int[]';
     $this->_typeProcessor->processSimpleAndAnyType($value, $type);
 }
Exemplo n.º 28
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessageRegExp /Property :"InvalidAttribute" does not exist in the provided class: \w+/
  */
 public function testFindSetterMethodNameInvalidAttribute()
 {
     $class = new ClassReflection("\\Magento\\Framework\\Reflection\\Test\\Unit\\DataObject");
     $this->_typeProcessor->findSetterMethodName($class, 'InvalidAttribute');
 }
Exemplo n.º 29
0
 public function testGetOperationName()
 {
     $this->assertEquals("resNameMethodName", $this->_typeProcessor->getOperationName("resName", "methodName"));
 }
Exemplo n.º 30
0
 /**
  * Retrieve method full documentation description.
  *
  * @param ReflectionMethod $method
  * @return string
  */
 protected function extractMethodDescription(ReflectionMethod $method)
 {
     $methodReflection = new MethodReflection($method->getDeclaringClass()->getName(), $method->getName());
     $docBlock = $methodReflection->getDocBlock();
     return $this->_typeProcessor->getDescription($docBlock);
 }