/** * Format $data according to specified $dataType recursively. * * Instantiate objects of proper classes and set data to its fields. * * @param mixed $data * @param string $dataType * @param Mage_Webapi_Model_ConfigAbstract $apiConfig * @return mixed * @throws LogicException If specified $dataType is invalid * @throws Mage_Webapi_Exception If required fields do not have values specified in $data */ protected function _formatParamData($data, $dataType, Mage_Webapi_Model_ConfigAbstract $apiConfig) { if ($this->_configHelper->isTypeSimple($dataType) || is_null($data)) { $formattedData = $data; } elseif ($this->_configHelper->isArrayType($dataType)) { $formattedData = $this->_formatArrayData($data, $dataType, $apiConfig); } else { $formattedData = $this->_formatComplexObjectData($data, $dataType, $apiConfig); } return $formattedData; }
/** * Process different element types. * * @param string $elementType * @param string $documentation * @param DOMElement $appInfoNode */ 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->_helper->isArrayType($elementType)) { $natureOfTypeNode = $this->_dom->createElement(self::APP_INF_NS . ':natureOfType'); $natureOfTypeNode->appendChild($this->_dom->createTextNode('array')); $appInfoNode->appendChild($natureOfTypeNode); } }
/** * Assert parameter data. * * @param string $expectedName * @param string $expectedType * @param string $expectedIsRequired * @param string $expectedDoc * @param array $expectedAppinfo * @param DOMElement $complexType with actual parameter element. */ protected function _assertParameter($expectedName, $expectedType, $expectedIsRequired, $expectedDoc, $expectedAppinfo, DOMElement $complexType) { $xsdNs = Wsdl::XSD_NS; $tns = Wsdl::TYPES_NS; /** @var DOMElement $parameterElement */ $parameterElement = $this->_xpath->query("{$xsdNs}:sequence/{$xsdNs}:element[@name='{$expectedName}']", $complexType)->item(0); $this->assertNotNull($parameterElement, sprintf('"%s" element was not found in complex type "%s".', $expectedName, $complexType->getAttribute('name'))); $isArray = $this->_helper->isArrayType($expectedType); if ($isArray) { $expectedType = $this->_helper->translateArrayTypeName($expectedType); } else { $this->assertEquals($expectedIsRequired ? 1 : 0, $parameterElement->getAttribute('minOccurs')); $this->assertEquals(1, $parameterElement->getAttribute('maxOccurs')); } $expectedNs = $this->_helper->isTypeSimple($expectedType) ? $xsdNs : $tns; $this->assertEquals("{$expectedNs}:{$expectedType}", $parameterElement->getAttribute('type')); $this->_assertDocumentation($expectedDoc, $parameterElement); $this->_assertAppinfo($expectedAppinfo, $parameterElement); }
/** * Retrieve complex type information from class public properties. * * @param string $class * @return array * @throws InvalidArgumentException */ protected function _processComplexType($class) { $typeName = $this->_helper->translateTypeName($class); $this->_types[$typeName] = array(); if ($this->_helper->isArrayType($class)) { $this->process($this->_helper->getArrayItemType($class)); } else { if (!class_exists($class)) { throw new InvalidArgumentException(sprintf('Could not load the "%s" class as parameter type.', $class)); } $reflection = new ClassReflection($class); $docBlock = $reflection->getDocBlock(); $this->_types[$typeName]['documentation'] = $docBlock ? $this->_getDescription($docBlock) : ''; $defaultProperties = $reflection->getDefaultProperties(); /** @var \Zend\Code\Reflection\PropertyReflection $property */ foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { $this->_processProperty($property, $defaultProperties, $typeName); } } return $this->_types[$typeName]; }