Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArrayOfTypeSequence.php
Go to the documentation of this file.
1 <?php
25 #require_once "Zend/Soap/Wsdl/Strategy/DefaultComplexType.php";
26 
37 {
44  public function addComplexType($type)
45  {
46  $nestedCounter = $this->_getNestedCount($type);
47 
48  if($nestedCounter > 0) {
49  $singularType = $this->_getSingularType($type);
50 
51  for($i = 1; $i <= $nestedCounter; $i++) {
52  $complexTypeName = substr($this->_getTypeNameBasedOnNestingLevel($singularType, $i), 4);
53  $childTypeName = $this->_getTypeNameBasedOnNestingLevel($singularType, $i-1);
54 
55  $this->_addElementFromWsdlAndChildTypes($complexTypeName, $childTypeName);
56  }
57  // adding the PHP type which is resolved to a nested XSD type. therefore add only once.
58  $this->getContext()->addType($complexTypeName);
59 
60  return "tns:$complexTypeName";
61  } else if (!in_array($type, $this->getContext()->getTypes())) {
62  // New singular complex type
63  return parent::addComplexType($type);
64  } else {
65  // Existing complex type
66  return $this->getContext()->getType($type);
67  }
68  }
69 
77  protected function _getTypeNameBasedOnNestingLevel($singularType, $level)
78  {
79  if($level == 0) {
80  // This is not an Array anymore, return the xsd simple type
81  return $singularType;
82  } else {
83  $prefix = str_repeat("ArrayOf", $level);
84  $xsdType = $this->_getStrippedXsdType($singularType);
85  $arrayType = $prefix.$xsdType;
86  return "tns:$arrayType";
87  }
88  }
89 
96  protected function _getStrippedXsdType($singularType)
97  {
98  return ucfirst(substr(strtolower($singularType), 4));
99  }
100 
108  protected function _getSingularType($type)
109  {
110  $singulartype = $this->getContext()->getType(str_replace("[]", "", $type));
111  return $singulartype;
112  }
113 
120  protected function _getNestedCount($type)
121  {
122  return substr_count($type, "[]");
123  }
124 
132  protected function _addElementFromWsdlAndChildTypes($arrayType, $childTypeName)
133  {
134  if (!in_array($arrayType, $this->getContext()->getTypes())) {
135  $dom = $this->getContext()->toDomDocument();
136 
137  $complexType = $dom->createElement('xsd:complexType');
138  $complexType->setAttribute('name', $arrayType);
139 
140  $sequence = $dom->createElement('xsd:sequence');
141 
142  $element = $dom->createElement('xsd:element');
143  $element->setAttribute('name', 'item');
144  $element->setAttribute('type', $childTypeName);
145  $element->setAttribute('minOccurs', 0);
146  $element->setAttribute('maxOccurs', 'unbounded');
147  $sequence->appendChild($element);
148 
149  $complexType->appendChild($sequence);
150 
151  $this->getContext()->getSchema()->appendChild($complexType);
152  $this->getContext()->addType($arrayType);
153  }
154  }
155 }
$type
Definition: item.phtml:13
$prefix
Definition: name.phtml:25
$i
Definition: gallery.phtml:31
_addElementFromWsdlAndChildTypes($arrayType, $childTypeName)
$element
Definition: element.phtml:12