Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ArrayOfTypeComplex.php
Go to the documentation of this file.
1 <?php
26 #require_once "Zend/Soap/Wsdl/Strategy/DefaultComplexType.php";
27 
38 {
39  protected $_inProcess = array();
40 
47  public function addComplexType($type)
48  {
49  if (in_array($type, $this->_inProcess)) {
50  return "tns:" . $type;
51  }
52  $this->_inProcess[$type] = $type;
53 
54  $nestingLevel = $this->_getNestedCount($type);
55 
56  if($nestingLevel > 1) {
57  #require_once "Zend/Soap/Wsdl/Exception.php";
58  throw new Zend_Soap_Wsdl_Exception(
59  "ArrayOfTypeComplex cannot return nested ArrayOfObject deeper than ".
60  "one level. Use array object properties to return deep nested data.
61  ");
62  }
63 
64  $singularType = $this->_getSingularPhpType($type);
65 
66  if(!class_exists($singularType)) {
67  #require_once "Zend/Soap/Wsdl/Exception.php";
68  throw new Zend_Soap_Wsdl_Exception(sprintf(
69  "Cannot add a complex type %s that is not an object or where ".
70  "class could not be found in 'DefaultComplexType' strategy.", $type
71  ));
72  }
73 
74  if($nestingLevel == 1) {
75  // The following blocks define the Array of Object structure
76  $xsdComplexTypeName = $this->_addArrayOfComplexType($singularType, $type);
77  } else {
78  $xsdComplexTypeName = $singularType;
79  }
80 
81  // The array for the objects has been created, now build the object definition:
82  if(!in_array($singularType, $this->getContext()->getTypes())) {
83  parent::addComplexType($singularType);
84  }
85 
86  unset($this->_inProcess[$type]);
87  return "tns:".$xsdComplexTypeName;
88  }
89 
90  protected function _addArrayOfComplexType($singularType, $type)
91  {
92  $dom = $this->getContext()->toDomDocument();
93 
94  $xsdComplexTypeName = $this->_getXsdComplexTypeName($singularType);
95 
96  if(!in_array($xsdComplexTypeName, $this->getContext()->getTypes())) {
97  $complexType = $dom->createElement('xsd:complexType');
98  $complexType->setAttribute('name', $xsdComplexTypeName);
99 
100  $complexContent = $dom->createElement("xsd:complexContent");
101  $complexType->appendChild($complexContent);
102 
103  $xsdRestriction = $dom->createElement("xsd:restriction");
104  $xsdRestriction->setAttribute('base', 'soap-enc:Array');
105  $complexContent->appendChild($xsdRestriction);
106 
107  $xsdAttribute = $dom->createElement("xsd:attribute");
108  $xsdAttribute->setAttribute("ref", "soap-enc:arrayType");
109  $xsdAttribute->setAttribute("wsdl:arrayType", sprintf("tns:%s[]", $singularType));
110  $xsdRestriction->appendChild($xsdAttribute);
111 
112  $this->getContext()->getSchema()->appendChild($complexType);
113  $this->getContext()->addType($xsdComplexTypeName);
114  }
115 
116  return $xsdComplexTypeName;
117  }
118 
119  protected function _getXsdComplexTypeName($type)
120  {
121  return sprintf('ArrayOf%s', $type);
122  }
123 
130  protected function _getSingularPhpType($type)
131  {
132  return str_replace("[]", "", $type);
133  }
134 
141  protected function _getNestedCount($type)
142  {
143  return substr_count($type, "[]");
144  }
145 }
$type
Definition: item.phtml:13