Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsoapresponse.php
Go to the documentation of this file.
1 <?php
18 class eZSOAPResponse extends eZSOAPEnvelope
19 {
26 public function __construct( $name="", $namespace="" )
27 {
28 $this->Name = $name;
29 $this->Namespace = $namespace;
30
31 parent::__construct();
32 }
33
37 function decodeStream( $request, $stream )
38 {
39 $dom = new DOMDocument( "1.0" );
40
41 $success = $dom->loadXML( $this->stripHTTPHeader( $stream ) );
42 $this->DOMDocument = $dom;
43
44 if ( $success && !empty( $dom ) )
45 {
46 // check for fault
47 $response = $dom->getElementsByTagNameNS( eZSOAPEnvelope::ENV, 'Fault' );
48
49 if ( $response->length == 1 )
50 {
51 $this->IsFault = 1;
52 foreach( $dom->getElementsByTagName( "faultstring" ) as $faultNode )
53 {
54 $this->FaultString = $faultNode->textContent;
55 break;
56 }
57
58 foreach( $dom->getElementsByTagName( "faultcode" ) as $faultNode )
59 {
60 $this->FaultCode = $faultNode->textContent;
61 break;
62 }
63 return;
64 }
65
66 // get the response
67 $response = $dom->getElementsByTagNameNS( $request->ns(), $request->name() . "Response" );
68
69 /* Some protocols do not use namespaces, and do not work with an empty namespace.
70 So, if we get no response, try again without namespace.
71 */
72 if ( $response->length == 0 )
73 {
74 $response = $dom->getElementsByTagName( $request->name() . "Response" );
75 }
76
77 $response = $response->item(0);
78
79 if ( !empty( $response ) )
80 {
81 /* Cut from the SOAP spec:
82 The method response is viewed as a single struct containing an accessor
83 for the return value and each [out] or [in/out] parameter.
84 The first accessor is the return value followed by the parameters
85 in the same order as in the method signature.
86
87 Each parameter accessor has a name corresponding to the name
88 of the parameter and type corresponding to the type of the parameter.
89 The name of the return value accessor is not significant.
90 Likewise, the name of the struct is not significant.
91 However, a convention is to name it after the method name
92 with the string "Response" appended.
93 */
94
95 $responseAccessors = $response->getElementsByTagName( 'return' );
96 if ( $responseAccessors->length > 0 )
97 {
98 $returnObject = $responseAccessors->item( 0 );
99 $this->Value = $this->decodeDataTypes( $returnObject );
100 }
101 }
102 else
103 {
104 eZDebug::writeError( "Got error from server" );
105 }
106 }
107 else
108 {
109 eZDebug::writeError( "Could not process XML in response" );
110 }
111 }
112
117 static function decodeDataTypes( $node, $type = "" )
118 {
119 $returnValue = false;
120
121 $attributeValue = '';
122 $attribute = $node->getAttributeNodeNS( eZSOAPEnvelope::SCHEMA_INSTANCE, 'type' );
123 if ( !$attribute )
124 {
125 $attribute = $node->getAttributeNodeNS( 'http://www.w3.org/1999/XMLSchema-instance', 'type' );
126 }
127 $attributeValue = $attribute->value;
128
129 $dataType = $type;
130 $attrParts = explode( ":", $attributeValue );
131 if ( $attrParts[1] )
132 {
133 $dataType = $attrParts[1];
134 }
135
136 /*
137 $typeNamespacePrefix = $this->DOMDocument->namespaceByAlias( $attrParts[0] );
138
139 check that this is a namespace type definition
140 if ( ( $typeNamespacePrefix == eZSOAPEnvelope::SCHEMA_DATA ) ||
141 ( $typeNamespacePrefix == eZSOAPEnvelope::ENC )
142 )
143 TODO: add encoding checks with schema validation.
144 */
145
146 switch ( $dataType )
147 {
148 case "string" :
149 case "int" :
150 case "float" :
151 case 'double' :
152 {
153 $returnValue = $node->textContent;
154 } break;
155
156 case "boolean" :
157 {
158 if ( $node->textContent == "true" )
159 $returnValue = true;
160 else
161 $returnValue = false;
162 } break;
163
164 case "base64" :
165 {
166 $returnValue = base64_decode( $node->textContent );
167 } break;
168
169 case "Array" :
170 {
171 // Get array type
172 $arrayType = $node->getAttributeNodeNS( eZSOAPEnvelope::ENC, 'arrayType' )->value;
173 $arrayTypeParts = explode( ":", $arrayType );
174
175 preg_match( "#(.*)\[(.*)\]#", $arrayTypeParts[1], $matches );
176
177 $type = $matches[1];
178 $count = $matches[2];
179
180 $returnValue = array();
181 foreach( $node->childNodes as $child )
182 {
183 if ( $child instanceof DOMElement )
184 {
185 $returnValue[] = eZSOAPResponse::decodeDataTypes( $child, $type );
186 }
187 }
188 }break;
189
190 case "SOAPStruct" :
191 {
192 $returnValue = array();
193
194 foreach( $node->childNodes as $child )
195 {
196 if ( $child instanceof DOMElement )
197 {
198 $returnValue[$child->tagName] = eZSOAPResponse::decodeDataTypes( $child );
199 }
200 }
201 }break;
202
203 default:
204 {
205 foreach ( $node->childNodes as $childNode )
206 {
207 if ( $childNode instanceof DOMElement )
208 {
209 // check data type for child
210 $attr = $childNode->getAttributeNodeNS( eZSOAPEnvelope::SCHEMA_INSTANCE, 'type' )->value;
211
212 $dataType = false;
213 $attrParts = explode( ":", $attr );
214 $dataType = $attrParts[1];
215
216 $returnValue[$childNode->tagName] = eZSOAPResponse::decodeDataTypes( $childNode );
217 }
218 }
219
220 } break;
221 }
222
223 return $returnValue;
224 }
225
229 function payload( )
230 {
231 $doc = new DOMDocument( '1.0', 'utf-8' );
232 // $doc->name = "eZSOAP message";
233
234 $root = $doc->createElementNS( eZSOAPEnvelope::ENV, eZSOAPEnvelope::ENV_PREFIX . ':Envelope' );
235
236 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::XSI_PREFIX, eZSOAPEnvelope::SCHEMA_INSTANCE );
237 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::XSD_PREFIX, eZSOAPEnvelope::SCHEMA_DATA );
238 $root->setAttribute( 'xmlns:' . eZSOAPEnvelope::ENC_PREFIX, eZSOAPEnvelope::ENC );
239
240 // add the body
241 $body = $doc->createElement( eZSOAPEnvelope::ENV_PREFIX . ':Body' );
242 $root->appendChild( $body );
243
244 // Check if it's a fault
245 if ( $this->Value instanceof eZSOAPFault )
246 {
247 $fault = $doc->createElement( eZSOAPEnvelope::ENV_PREFIX . ':Fault' );
248
249 $faultCodeNode = $doc->createElement( "faultcode", $this->Value->faultCode() );
250 $fault->appendChild( $faultCodeNode );
251
252 $faultStringNode = $doc->createElement( "faultstring", $this->Value->faultString() );
253 $fault->appendChild( $faultStringNode );
254
255 $body->appendChild( $fault );
256 }
257 else
258 {
259 // add the request
260 $responseName = $this->Name . "Response";
261 if ( $this->Namespace == '' )
262 $response = $doc->createElement( "resp:".$responseName );
263 else
264 $response = $doc->createElementNS( $this->Namespace, "resp:".$responseName );
265
266 $return = $doc->createElement( "return" );
267
268 $value = eZSOAPCodec::encodeValue( $doc, "return", $this->Value );
269
270 $body->appendChild( $response );
271
272 $response->appendChild( $value );
273 }
274
275 $doc->appendChild( $root );
276
277 return $doc->saveXML();
278 }
279
285 function stripHTTPHeader( $data )
286 {
287 $missingxml = false;
288 $start = strpos( $data, "<?xml" );
289 if ( $start === false )
290 {
291 eZDebug::writeWarning( "missing <?xml ...> in HTTP response, attempting workaround", __METHOD__ );
292 $start = strpos( $data, "<E:Envelope" );
293 $missingxml = true;
294 }
295 $data = substr( $data, $start, strlen( $data ) - $start );
296
297 if ( $missingxml == true )
298 {
299 $data = '<?xml version="1.0"?>' . $data;
300 }
301
302 return $data;
303 }
304
308 function value()
309 {
310 return $this->Value;
311 }
312
316 function setValue( $value )
317 {
318 $this->Value = $value;
319 }
320
324 function isFault()
325 {
326 return $this->IsFault;
327 }
328
332 function faultCode()
333 {
334 return $this->FaultCode;
335 }
336
340 function faultString()
341 {
342 return $this->FaultString;
343 }
344
346 public $Value = false;
348 public $Type = false;
350 public $FaultString = false;
352 public $FaultCode = false;
354 public $IsFault = false;
356 public $Name;
358 public $Namespace;
359
361 public $DOMDocument = false;
362 }
363
364 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZSOAPCodec\encodeValue
static encodeValue( $doc, $name, $value)
Definition: ezsoapcodec.php:23
eZSOAPEnvelope
SOAP envelope handling and definition.
Definition: ezsoapenvelope.php:21
eZSOAPEnvelope\XSI_PREFIX
const XSI_PREFIX
Definition: ezsoapenvelope.php:29
eZSOAPEnvelope\ENC_PREFIX
const ENC_PREFIX
Definition: ezsoapenvelope.php:28
eZSOAPEnvelope\ENV_PREFIX
const ENV_PREFIX
Definition: ezsoapenvelope.php:27
eZSOAPEnvelope\XSD_PREFIX
const XSD_PREFIX
Definition: ezsoapenvelope.php:30
eZSOAPEnvelope\SCHEMA_DATA
const SCHEMA_DATA
Definition: ezsoapenvelope.php:25
eZSOAPEnvelope\ENC
const ENC
Definition: ezsoapenvelope.php:23
eZSOAPEnvelope\ENV
const ENV
Definition: ezsoapenvelope.php:22
eZSOAPEnvelope\SCHEMA_INSTANCE
const SCHEMA_INSTANCE
Definition: ezsoapenvelope.php:24
eZSOAPFault
eZSOAPFault handles SOAP fault messages
Definition: ezsoapfault.php:19
eZSOAPResponse
eZSOAPResponse handles SOAP response packages
Definition: ezsoapresponse.php:19
eZSOAPResponse\isFault
isFault()
Definition: ezsoapresponse.php:324
eZSOAPResponse\$Namespace
$Namespace
Contains the target namespace for the response.
Definition: ezsoapresponse.php:358
eZSOAPResponse\$Type
$Type
Contains the response type.
Definition: ezsoapresponse.php:348
eZSOAPResponse\$Name
$Name
Contains the name of the response, i.e. function call name.
Definition: ezsoapresponse.php:356
eZSOAPResponse\$DOMDocument
$DOMDocument
Contains the DOM document for the current SOAP response.
Definition: ezsoapresponse.php:361
eZSOAPResponse\$FaultString
$FaultString
Contains fault string.
Definition: ezsoapresponse.php:350
eZSOAPResponse\payload
payload()
Definition: ezsoapresponse.php:229
eZSOAPResponse\__construct
__construct( $name="", $namespace="")
Definition: ezsoapresponse.php:26
eZSOAPResponse\decodeStream
decodeStream( $request, $stream)
Definition: ezsoapresponse.php:37
eZSOAPResponse\value
value()
Definition: ezsoapresponse.php:308
eZSOAPResponse\setValue
setValue( $value)
Definition: ezsoapresponse.php:316
eZSOAPResponse\$IsFault
$IsFault
Contains true if the response was an fault.
Definition: ezsoapresponse.php:354
eZSOAPResponse\$FaultCode
$FaultCode
Contains the fault code.
Definition: ezsoapresponse.php:352
eZSOAPResponse\decodeDataTypes
static decodeDataTypes( $node, $type="")
Definition: ezsoapresponse.php:117
eZSOAPResponse\$Value
$Value
Contains the response value.
Definition: ezsoapresponse.php:346
eZSOAPResponse\faultString
faultString()
Definition: ezsoapresponse.php:340
eZSOAPResponse\stripHTTPHeader
stripHTTPHeader( $data)
Definition: ezsoapresponse.php:285
eZSOAPResponse\faultCode
faultCode()
Definition: ezsoapresponse.php:332
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.