|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (C) 2013-2016 |
|
4
|
|
|
* Piotr Olaszewski <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
7
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
8
|
|
|
* in the Software without restriction, including without limitation the rights |
|
9
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
10
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
11
|
|
|
* furnished to do so, subject to the following conditions: |
|
12
|
|
|
* |
|
13
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
14
|
|
|
* all copies or substantial portions of the Software. |
|
15
|
|
|
* |
|
16
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
18
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
19
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
20
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
21
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
22
|
|
|
* SOFTWARE. |
|
23
|
|
|
*/ |
|
24
|
|
|
namespace WSDL\XML\XMLStyle; |
|
25
|
|
|
|
|
26
|
|
|
use DOMDocument; |
|
27
|
|
|
use DOMElement; |
|
28
|
|
|
use WSDL\Parser\Node; |
|
29
|
|
|
use WSDL\XML\XMLAttributeHelper; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* XMLRpcStyle |
|
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', array( |
|
45
|
|
|
'style' => 'rpc', |
|
46
|
|
|
'transport' => 'http://schemas.xmlsoap.org/soap/http' |
|
47
|
|
|
)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @inheritdoc |
|
52
|
|
|
*/ |
|
53
|
|
|
public function generateMessagePart(DOMDocument $DOMDocument, $nodes) |
|
54
|
|
|
{ |
|
55
|
|
|
$parts = array(); |
|
56
|
|
|
foreach ($nodes as $node) { |
|
57
|
|
|
$attributes = $this->attributes($node, $node->getSanitizedName()); |
|
58
|
|
|
$parts[] = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('part', $attributes); |
|
59
|
|
|
} |
|
60
|
|
|
return $parts; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @inheritdoc |
|
65
|
|
|
*/ |
|
66
|
|
|
public function generateTypes(DOMDocument $DOMDocument, $parameters, $soapVersion) |
|
67
|
|
|
{ |
|
68
|
|
|
$return = array(); |
|
69
|
|
|
foreach ($parameters as $parameter) { |
|
70
|
|
|
$node = $parameter->getNode(); |
|
71
|
|
|
$nodeGen = $this->parameterGenerate($DOMDocument, $node, null, $soapVersion); |
|
72
|
|
|
$return = array_merge($return, $nodeGen); |
|
73
|
|
|
} |
|
74
|
|
|
return $return; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param DOMDocument $DOMDocument |
|
79
|
|
|
* @param Node $node |
|
80
|
|
|
* @param DOMElement|null $sequenceElement |
|
81
|
|
|
* @param string $soapVersion |
|
82
|
|
|
* @return array |
|
83
|
|
|
*/ |
|
84
|
|
|
private function parameterGenerate(DOMDocument $DOMDocument, Node $node, DOMElement $sequenceElement = null, $soapVersion) |
|
85
|
|
|
{ |
|
86
|
|
|
$result = array(); |
|
87
|
|
|
if ($sequenceElement) { |
|
88
|
|
|
$attributes = $this->attributes($node, $node->getNameForObject()); |
|
89
|
|
|
$elementPartElement = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', $attributes); |
|
90
|
|
|
$sequenceElement->appendChild($elementPartElement); |
|
91
|
|
|
} |
|
92
|
|
|
if ($node->isArray()) { |
|
93
|
|
|
$complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
94
|
|
|
->createElementWithAttributes('xsd:complexType', array('name' => $node->getNameForArray())); |
|
95
|
|
|
$complexContentElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:complexContent'); |
|
96
|
|
|
$restrictionElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
97
|
|
|
->createElementWithAttributes('xsd:restriction', array('base' => 'soapenc:Array')); |
|
98
|
|
|
$type = $node->isObject() ? 'ns:' . $node->getNameForObject() . '[]' : 'xsd:' . $node->getType() . '[]'; |
|
99
|
|
|
$attributeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
100
|
|
|
->createElementWithAttributes('xsd:attribute', array( |
|
101
|
|
|
'ref' => 'soapenc:arrayType', |
|
102
|
|
|
$soapVersion . ':arrayType' => $type |
|
103
|
|
|
)); |
|
104
|
|
|
$restrictionElement->appendChild($attributeElement); |
|
105
|
|
|
$complexContentElement->appendChild($restrictionElement); |
|
106
|
|
|
$complexTypeElement->appendChild($complexContentElement); |
|
107
|
|
|
$result[] = $complexTypeElement; |
|
108
|
|
|
} |
|
109
|
|
|
if ($node->isObject()) { |
|
110
|
|
|
$name = $node->getNameForObject(); |
|
111
|
|
|
$element = XMLAttributeHelper::forDOM($DOMDocument)->createElementWithAttributes('xsd:element', array( |
|
112
|
|
|
'name' => $name, 'nillable' => 'true', 'type' => 'ns:' . $name |
|
113
|
|
|
)); |
|
114
|
|
|
$result[] = $element; |
|
115
|
|
|
|
|
116
|
|
|
$complexTypeElement = XMLAttributeHelper::forDOM($DOMDocument) |
|
117
|
|
|
->createElementWithAttributes('xsd:complexType', array('name' => $node->getNameForObject())); |
|
118
|
|
|
$sequenceElement = XMLAttributeHelper::forDOM($DOMDocument)->createElement('xsd:sequence'); |
|
119
|
|
|
$complexTypeElement->appendChild($sequenceElement); |
|
120
|
|
|
|
|
121
|
|
|
$result[] = $complexTypeElement; |
|
122
|
|
|
foreach ($node->getElements() as $nodeElement) { |
|
123
|
|
|
$tmp = $this->parameterGenerate($DOMDocument, $nodeElement, $sequenceElement, $soapVersion); |
|
124
|
|
|
$result = array_merge($result, $tmp); |
|
125
|
|
|
} |
|
126
|
|
|
} |
|
127
|
|
|
return $result; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param Node $node |
|
132
|
|
|
* @param string $nameForObject |
|
133
|
|
|
* @return array |
|
134
|
|
|
*/ |
|
135
|
|
|
private function attributes(Node $node, $nameForObject) |
|
136
|
|
|
{ |
|
137
|
|
|
if ($node->isArray()) { |
|
138
|
|
|
$attributes = array( |
|
139
|
|
|
'name' => $node->getSanitizedName(), |
|
140
|
|
|
'type' => 'ns:' . $node->getNameForArray() |
|
141
|
|
|
); |
|
142
|
|
|
} else if ($node->isObject()) { |
|
143
|
|
|
$attributes = array( |
|
144
|
|
|
'name' => $nameForObject, |
|
145
|
|
|
'element' => 'ns:' . $node->getNameForObject() |
|
146
|
|
|
); |
|
147
|
|
|
} else { |
|
148
|
|
|
$attributes = array( |
|
149
|
|
|
'name' => $node->getSanitizedName(), |
|
150
|
|
|
'type' => 'xsd:' . $node->getType() |
|
151
|
|
|
); |
|
152
|
|
|
} |
|
153
|
|
|
return $attributes; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|