/** * 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 */ 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)) { $result = $this->_typeProcessor->processSimpleAndAnyType($value, $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($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; }
public function testIsTypeSimple() { $this->assertTrue($this->_typeProcessor->isTypeSimple('string')); $this->assertTrue($this->_typeProcessor->isTypeSimple('string[]')); $this->assertTrue($this->_typeProcessor->isTypeSimple('int')); $this->assertTrue($this->_typeProcessor->isTypeSimple('float')); $this->assertTrue($this->_typeProcessor->isTypeSimple('double')); $this->assertTrue($this->_typeProcessor->isTypeSimple('boolean')); $this->assertFalse($this->_typeProcessor->isTypeSimple('blah')); }
/** * Process array of types. * * @param string $type * @param array $callInfo * @return void */ protected function _processArrayParameter($type, $callInfo = array()) { $arrayItemType = $this->_typeProcessor->getArrayItemType($type); $arrayTypeName = $this->_typeProcessor->translateArrayTypeName($type); if (!$this->_typeProcessor->isTypeSimple($arrayItemType)) { $this->addComplexType($arrayItemType, $callInfo); } $arrayTypeParameters = array(self::ARRAY_ITEM_KEY_NAME => array('type' => $arrayItemType, 'required' => false, 'isArray' => true, 'documentation' => sprintf('An item of %s.', $arrayTypeName))); $arrayTypeData = array('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 = array(); $callInfo[$direction][$condition]['calls'][] = $operation; $this->_typeProcessor->setTypeData($parameterType, array('callInfo' => $callInfo)); } } } }