| @@ 36-144 (lines=109) @@ | ||
| 33 | * |
|
| 34 | * @author Piotr Olaszewski <[email protected]> |
|
| 35 | */ |
|
| 36 | class XMLDocumentStyle implements XMLStyle |
|
| 37 | { |
|
| 38 | /** |
|
| 39 | * @inheritdoc |
|
| 40 | */ |
|
| 41 | public function generateBinding(DOMDocument $DOMDocument, $soapVersion) |
|
| 42 | { |
|
| 43 | return XMLAttributeHelper::forDOM($DOMDocument) |
|
| 44 | ->createElementWithAttributes($soapVersion . ':binding', [ |
|
| 45 | 'style' => 'document', 'transport' => 'http://schemas.xmlsoap.org/soap/http' |
|
| 46 | ]); |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * @inheritdoc |
|
| 51 | */ |
|
| 52 | public function generateMessagePart(DOMDocument $DOMDocument, $nodes) |
|
| 53 | { |
|
| 54 | $parts = []; |
|
| 55 | foreach ($nodes as $node) { |
|
| 56 | $parts[] = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('part', [ |
|
| 57 | 'name' => $node->getSanitizedName(), 'element' => 'ns:' . $node->getSanitizedName() |
|
| 58 | ]); |
|
| 59 | } |
|
| 60 | return $parts; |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @inheritdoc |
|
| 65 | */ |
|
| 66 | public function generateTypes(DOMDocument $DOMDocument, $parameters, $soapVersion) |
|
| 67 | { |
|
| 68 | $types = []; |
|
| 69 | foreach ($parameters as $parameter) { |
|
| 70 | $node = $parameter->getNode(); |
|
| 71 | $attributes = $this->attributes($node); |
|
| 72 | $element = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', $attributes); |
|
| 73 | $types[] = $element; |
|
| 74 | $complexIfNeeded = $this->generateParameters($DOMDocument, $node, null, $soapVersion); |
|
| 75 | if ($complexIfNeeded) { |
|
| 76 | $types = array_merge($types, $complexIfNeeded); |
|
| 77 | } |
|
| 78 | } |
|
| 79 | return $types; |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * @param DOMDocument $DOMDocument |
|
| 84 | * @param Node $node |
|
| 85 | * @param DOMElement|null $sequenceElement |
|
| 86 | * @param string $soapVersion |
|
| 87 | * @return DOMElement[] |
|
| 88 | */ |
|
| 89 | private function generateParameters(DOMDocument $DOMDocument, Node $node, DOMElement $sequenceElement = null, $soapVersion) |
|
| 90 | { |
|
| 91 | $result = []; |
|
| 92 | if ($sequenceElement) { |
|
| 93 | $attributes = $this->attributes($node); |
|
| 94 | $elementPartElement = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', $attributes); |
|
| 95 | $sequenceElement->appendChild($elementPartElement); |
|
| 96 | } |
|
| 97 | if ($node->isArray()) { |
|
| 98 | $complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 99 | ->createElementWithAttributes('xsd:complexType', ['name' => $node->getNameForArray()]); |
|
| 100 | $complexContentElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:complexContent'); |
|
| 101 | $restrictionElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 102 | ->createElementWithAttributes('xsd:restriction', ['base' => 'soapenc:Array']); |
|
| 103 | $type = $node->isObject() ? 'ns:' . $node->getNameForObject() . '[]' : 'xsd:' . $node->getType() . '[]'; |
|
| 104 | $attributeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 105 | ->createElementWithAttributes('xsd:attribute', [ |
|
| 106 | 'ref' => 'soapenc:arrayType', |
|
| 107 | $soapVersion . ':arrayType' => $type |
|
| 108 | ]); |
|
| 109 | $restrictionElement->appendChild($attributeElement); |
|
| 110 | $complexContentElement->appendChild($restrictionElement); |
|
| 111 | $complexTypeElement->appendChild($complexContentElement); |
|
| 112 | $result[] = $complexTypeElement; |
|
| 113 | } |
|
| 114 | if ($node->isObject()) { |
|
| 115 | $complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 116 | ->createElementWithAttributes('xsd:complexType', ['name' => $node->getNameForObject()]); |
|
| 117 | $sequenceElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:sequence'); |
|
| 118 | $complexTypeElement->appendChild($sequenceElement); |
|
| 119 | ||
| 120 | $result[] = $complexTypeElement; |
|
| 121 | foreach ($node->getElements() as $nodeElement) { |
|
| 122 | $tmp = $this->generateParameters($DOMDocument, $nodeElement, $sequenceElement, $soapVersion); |
|
| 123 | $result = array_merge($result, $tmp); |
|
| 124 | } |
|
| 125 | } |
|
| 126 | return $result; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param Node $node |
|
| 131 | * @return array |
|
| 132 | */ |
|
| 133 | private function attributes(Node $node) |
|
| 134 | { |
|
| 135 | if ($node->isArray()) { |
|
| 136 | $attributes = ['name' => $node->getSanitizedName(), 'type' => 'ns:' . $node->getNameForArray()]; |
|
| 137 | } elseif ($node->isObject()) { |
|
| 138 | $attributes = ['name' => $node->getSanitizedName(), 'type' => 'ns:' . $node->getNameForObject()]; |
|
| 139 | } else { |
|
| 140 | $attributes = ['name' => $node->getSanitizedName(), 'type' => 'xsd:' . $node->getType()]; |
|
| 141 | } |
|
| 142 | return $attributes; |
|
| 143 | } |
|
| 144 | } |
|
| 145 | ||
| @@ 36-144 (lines=109) @@ | ||
| 33 | * |
|
| 34 | * @author Piotr Olaszewski <[email protected]> |
|
| 35 | */ |
|
| 36 | class XMLRpcStyle implements XMLStyle |
|
| 37 | { |
|
| 38 | /** |
|
| 39 | * @inheritdoc |
|
| 40 | */ |
|
| 41 | public function generateBinding(DOMDocument $DOMDocument, $soapVersion) |
|
| 42 | { |
|
| 43 | return XMLAttributeHelper::forDOM($DOMDocument) |
|
| 44 | ->createElementWithAttributes($soapVersion . ':binding', [ |
|
| 45 | 'style' => 'rpc', 'transport' => 'http://schemas.xmlsoap.org/soap/http' |
|
| 46 | ]); |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * @inheritdoc |
|
| 51 | */ |
|
| 52 | public function generateMessagePart(DOMDocument $DOMDocument, $nodes) |
|
| 53 | { |
|
| 54 | $parts = []; |
|
| 55 | foreach ($nodes as $node) { |
|
| 56 | $attributes = $this->attributes($node); |
|
| 57 | $parts[] = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('part', $attributes); |
|
| 58 | } |
|
| 59 | return $parts; |
|
| 60 | } |
|
| 61 | ||
| 62 | /** |
|
| 63 | * @inheritdoc |
|
| 64 | */ |
|
| 65 | public function generateTypes(DOMDocument $DOMDocument, $parameters, $soapVersion) |
|
| 66 | { |
|
| 67 | $types = []; |
|
| 68 | foreach ($parameters as $parameter) { |
|
| 69 | $node = $parameter->getNode(); |
|
| 70 | $nodeGen = $this->generateParameters($DOMDocument, $node, null, $soapVersion); |
|
| 71 | $types = array_merge($types, $nodeGen); |
|
| 72 | } |
|
| 73 | return $types; |
|
| 74 | } |
|
| 75 | ||
| 76 | /** |
|
| 77 | * @param DOMDocument $DOMDocument |
|
| 78 | * @param Node $node |
|
| 79 | * @param DOMElement|null $sequenceElement |
|
| 80 | * @param string $soapVersion |
|
| 81 | * @return DOMElement[] |
|
| 82 | */ |
|
| 83 | private function generateParameters(DOMDocument $DOMDocument, Node $node, DOMElement $sequenceElement = null, $soapVersion) |
|
| 84 | { |
|
| 85 | $result = []; |
|
| 86 | if ($sequenceElement) { |
|
| 87 | $attributes = $this->attributes($node); |
|
| 88 | $elementPartElement = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', $attributes); |
|
| 89 | $sequenceElement->appendChild($elementPartElement); |
|
| 90 | } |
|
| 91 | if ($node->isArray()) { |
|
| 92 | $complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 93 | ->createElementWithAttributes('xsd:complexType', ['name' => $node->getNameForArray()]); |
|
| 94 | $complexContentElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:complexContent'); |
|
| 95 | $restrictionElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 96 | ->createElementWithAttributes('xsd:restriction', ['base' => 'soapenc:Array']); |
|
| 97 | $type = $node->isObject() ? 'ns:' . $node->getNameForObject() . '[]' : 'xsd:' . $node->getType() . '[]'; |
|
| 98 | $attributeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 99 | ->createElementWithAttributes('xsd:attribute', [ |
|
| 100 | 'ref' => 'soapenc:arrayType', |
|
| 101 | $soapVersion . ':arrayType' => $type |
|
| 102 | ]); |
|
| 103 | $restrictionElement->appendChild($attributeElement); |
|
| 104 | $complexContentElement->appendChild($restrictionElement); |
|
| 105 | $complexTypeElement->appendChild($complexContentElement); |
|
| 106 | $result[] = $complexTypeElement; |
|
| 107 | } |
|
| 108 | if ($node->isObject()) { |
|
| 109 | $name = $node->getNameForObject(); |
|
| 110 | $element = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', [ |
|
| 111 | 'name' => $name, 'nillable' => 'true', 'type' => 'ns:' . $name |
|
| 112 | ]); |
|
| 113 | $result[] = $element; |
|
| 114 | ||
| 115 | $complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
| 116 | ->createElementWithAttributes('xsd:complexType', ['name' => $node->getNameForObject()]); |
|
| 117 | $sequenceElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:sequence'); |
|
| 118 | $complexTypeElement->appendChild($sequenceElement); |
|
| 119 | ||
| 120 | $result[] = $complexTypeElement; |
|
| 121 | foreach ($node->getElements() as $nodeElement) { |
|
| 122 | $tmp = $this->generateParameters($DOMDocument, $nodeElement, $sequenceElement, $soapVersion); |
|
| 123 | $result = array_merge($result, $tmp); |
|
| 124 | } |
|
| 125 | } |
|
| 126 | return $result; |
|
| 127 | } |
|
| 128 | ||
| 129 | /** |
|
| 130 | * @param Node $node |
|
| 131 | * @return array |
|
| 132 | */ |
|
| 133 | private function attributes(Node $node) |
|
| 134 | { |
|
| 135 | if ($node->isArray()) { |
|
| 136 | $attributes = ['name' => $node->getSanitizedName(), 'type' => 'ns:' . $node->getNameForArray()]; |
|
| 137 | } elseif ($node->isObject()) { |
|
| 138 | $attributes = ['name' => $node->getSanitizedName(), 'element' => 'ns:' . $node->getNameForObject()]; |
|
| 139 | } else { |
|
| 140 | $attributes = ['name' => $node->getSanitizedName(), 'type' => 'xsd:' . $node->getType()]; |
|
| 141 | } |
|
| 142 | return $attributes; |
|
| 143 | } |
|
| 144 | } |
|
| 145 | ||