3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Soap\Wsdl\ComplexTypeStrategy
;
14 class ArrayOfTypeSequence
extends DefaultComplexType
17 * Add an unbounded ArrayOfType based on the xsd:sequence syntax if
18 * type[] is detected in return value doc comment.
21 * @return string tns:xsd-type
23 public function addComplexType($type)
25 $nestedCounter = $this->_getNestedCount($type);
27 if ($nestedCounter > 0) {
28 $singularType = $this->_getSingularType($type);
31 for ($i = 1; $i <= $nestedCounter; $i++
) {
32 $complexType = $this->_getTypeBasedOnNestingLevel($singularType, $i);
33 $complexTypePhp = $singularType . str_repeat('[]', $i);
34 $childType = $this->_getTypeBasedOnNestingLevel($singularType, $i-1);
36 $this->_addSequenceType($complexType, $childType, $complexTypePhp);
42 if (($soapType = $this->scanRegisteredTypes($type)) !== null) {
43 // Existing complex type
47 // New singular complex type
48 return parent
::addComplexType($type);
52 * Return the ArrayOf or simple type name based on the singular xsdtype
53 * and the nesting level
55 * @param string $singularType
59 protected function _getTypeBasedOnNestingLevel($singularType, $level)
62 // This is not an Array anymore, return the xsd simple type
63 return $this->getContext()->getType($singularType);
66 return Wsdl
::TYPES_NS
. ':' . str_repeat('ArrayOf', $level) . ucfirst($this->getContext()->translateType($singularType));
70 * From a nested definition with type[], get the singular xsd:type
75 protected function _getSingularType($type)
77 return str_replace('[]', '', $type);
81 * Return the array nesting level based on the type name
86 protected function _getNestedCount($type)
88 return substr_count($type, '[]');
92 * Append the complex type definition to the WSDL via the context access
94 * @param string $arrayType Array type name (e.g. 'tns:ArrayOfArrayOfInt')
95 * @param string $childType Qualified array items type (e.g. 'xsd:int', 'tns:ArrayOfInt')
96 * @param string $phpArrayType PHP type (e.g. 'int[][]', '\MyNamespace\MyClassName[][][]')
98 protected function _addSequenceType($arrayType, $childType, $phpArrayType)
100 if ($this->scanRegisteredTypes($phpArrayType) !== null) {
104 // Register type here to avoid recursion
105 $this->getContext()->addType($phpArrayType, $arrayType);
108 $dom = $this->getContext()->toDomDocument();
110 $arrayTypeName = substr($arrayType, strpos($arrayType, ':') +
1);
112 $complexType = $dom->createElementNS(Wsdl
::XSD_NS_URI
, 'complexType');
113 $this->getContext()->getSchema()->appendChild($complexType);
115 $complexType->setAttribute('name', $arrayTypeName);
117 $sequence = $dom->createElementNS(Wsdl
::XSD_NS_URI
, 'sequence');
118 $complexType->appendChild($sequence);
120 $element = $dom->createElementNS(Wsdl
::XSD_NS_URI
, 'element');
121 $sequence->appendChild($element);
123 $element->setAttribute('name', 'item');
124 $element->setAttribute('type', $childType);
125 $element->setAttribute('minOccurs', 0);
126 $element->setAttribute('maxOccurs', 'unbounded');