public function testIsTypeAny() { $this->assertTrue($this->_typeProcessor->isTypeAny('mixed')); $this->assertTrue($this->_typeProcessor->isTypeAny('mixed[]')); $this->assertFalse($this->_typeProcessor->isTypeAny('int')); $this->assertFalse($this->_typeProcessor->isTypeAny('int[]')); }
/** * 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; }
/** * 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; }
/** * Convert data from array to Data Object representation if type is Data Object or array of Data Objects. * * @param mixed $value * @param string $type Convert given value to the this type * @return mixed * @throws WebapiException * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _convertValue($value, $type) { $isArrayType = $this->typeProcessor->isArrayType($type); if ($isArrayType && isset($value['item'])) { $value = $this->_removeSoapItemNode($value); } if ($this->typeProcessor->isTypeSimple($type) || $this->typeProcessor->isTypeAny($type)) { try { $result = $this->typeProcessor->processSimpleAndAnyType($value, $type); } catch (SerializationException $e) { throw new WebapiException(new Phrase($e->getMessage())); } } 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($value) ? [] : null; $itemType = $this->typeProcessor->getArrayItemType($type); if (is_array($value)) { foreach ($value as $key => $item) { $result[$key] = $this->_createFromArray($itemType, $item); } } } else { $result = $this->_createFromArray($type, $value); } } return $result; }
/** * Process array of types. * * @param string $type * @param array $callInfo * @return void */ protected function _processArrayParameter($type, $callInfo = []) { $arrayItemType = $this->_typeProcessor->getArrayItemType($type); $arrayTypeName = $this->_typeProcessor->translateArrayTypeName($type); if (!$this->_typeProcessor->isTypeSimple($arrayItemType) && !$this->_typeProcessor->isTypeAny($arrayItemType)) { $this->addComplexType($arrayItemType, $callInfo); } $arrayTypeParameters = [self::ARRAY_ITEM_KEY_NAME => ['type' => $arrayItemType, 'required' => false, 'isArray' => true, 'documentation' => sprintf('An item of %s.', $arrayTypeName)]]; $arrayTypeData = ['documentation' => sprintf('An array of %s items.', $arrayItemType), 'parameters' => $arrayTypeParameters]; $this->_typeProcessor->setTypeData($arrayTypeName, $arrayTypeData); $this->addComplexType($arrayTypeName, $callInfo); }
/** * Process call info data from interface. * * @param array $interface * @param string $serviceName * @param string $methodName * @return void */ protected function _processInterfaceCallInfo($interface, $serviceName, $methodName) { foreach ($interface as $direction => $interfaceData) { $direction = $direction == 'in' ? 'requiredInput' : 'returned'; foreach ($interfaceData['parameters'] as $parameterData) { $parameterType = $parameterData['type']; if (!$this->_typeProcessor->isTypeSimple($parameterType) && !$this->_typeProcessor->isTypeAny($parameterType)) { $operation = $this->getOperationName($serviceName, $methodName); if ($parameterData['required']) { $condition = $direction == 'requiredInput' ? 'yes' : 'always'; } else { $condition = $direction == 'requiredInput' ? 'no' : 'conditionally'; } $callInfo = []; $callInfo[$direction][$condition]['calls'][] = $operation; $this->_typeProcessor->setTypeData($parameterType, ['callInfo' => $callInfo]); } } } }