Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Soap / Wsdl / ComplexTypeStrategy / ArrayOfTypeSequence.php
blob0c223bda1b474582d76d94ad7935c6063918a27c
1 <?php
2 /**
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
8 */
10 namespace Zend\Soap\Wsdl\ComplexTypeStrategy;
12 use Zend\Soap\Wsdl;
14 class ArrayOfTypeSequence extends DefaultComplexType
16 /**
17 * Add an unbounded ArrayOfType based on the xsd:sequence syntax if
18 * type[] is detected in return value doc comment.
20 * @param string $type
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);
29 $complexType = '';
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);
39 return $complexType;
42 if (($soapType = $this->scanRegisteredTypes($type)) !== null) {
43 // Existing complex type
44 return $soapType;
47 // New singular complex type
48 return parent::addComplexType($type);
51 /**
52 * Return the ArrayOf or simple type name based on the singular xsdtype
53 * and the nesting level
55 * @param string $singularType
56 * @param int $level
57 * @return string
59 protected function _getTypeBasedOnNestingLevel($singularType, $level)
61 if ($level == 0) {
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));
69 /**
70 * From a nested definition with type[], get the singular xsd:type
72 * @param string $type
73 * @return string
75 protected function _getSingularType($type)
77 return str_replace('[]', '', $type);
80 /**
81 * Return the array nesting level based on the type name
83 * @param string $type
84 * @return int
86 protected function _getNestedCount($type)
88 return substr_count($type, '[]');
91 /**
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) {
101 return;
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');