00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 include_once( "lib/ezutils/classes/ezdebug.php" );
00042 include_once( 'lib/ezsoap/classes/ezsoapcodec.php' );
00043 include_once( "lib/ezxml/classes/ezxml.php" );
00044 include_once( "lib/ezsoap/classes/ezsoapenvelope.php" );
00045
00046 class eZSOAPResponse extends eZSOAPEnvelope
00047 {
00048
00049
00050
00051 function eZSOAPResponse( $name="", $namespace="" )
00052 {
00053 $this->Name = $name;
00054 $this->Namespace = $namespace;
00055
00056
00057 $this->eZSOAPEnvelope();
00058 }
00059
00060
00061
00062
00063 function decodeStream( $request, $stream )
00064 {
00065 $stream = $this->stripHTTPHeader( $stream );
00066
00067 $xml = new eZXML();
00068
00069 $dom = $xml->domTree( $stream );
00070 $this->DOMDocument = $dom;
00071
00072 if ( get_class( $dom ) == "ezdomdocument" )
00073 {
00074
00075 $response = $dom->elementsByNameNS( 'Fault', EZ_SOAP_ENV );
00076
00077 if ( count( $response ) == 1 )
00078 {
00079 $this->IsFault = 1;
00080 $faultStringArray = $dom->elementsByName( "faultstring" );
00081 $this->FaultString = $faultStringArray[0]->textContent();
00082
00083 $faultCodeArray = $dom->elementsByName( "faultcode" );
00084 $this->FaultCode = $faultCodeArray[0]->textContent();
00085 return;
00086 }
00087
00088
00089 $response = $dom->elementsByNameNS( $request->name() . "Response", $request->namespace() );
00090
00091 $response = $response[0];
00092
00093 if ( get_class( $response ) == "ezdomnode" )
00094 {
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 $responseAccessors = $response->children();
00110 if ( count($responseAccessors) > 0 )
00111 {
00112 $returnObject = $responseAccessors[0];
00113 $this->Value = $this->decodeDataTypes( $returnObject );
00114 }
00115 }
00116 else
00117 {
00118 eZDebug::writeError( "Got error from server" );
00119 }
00120 }
00121 else
00122 {
00123 eZDebug::writeError( "Could not process XML in response" );
00124 }
00125 }
00126
00127
00128
00129
00130
00131 function decodeDataTypes( $node, $type="" )
00132 {
00133 $returnValue = false;
00134
00135 $attr = $node->attributeValueNS( "type", EZ_SOAP_SCHEMA_INSTANCE );
00136
00137 if ( !$attr )
00138 {
00139 $attr = $node->attributeValueNS( "type", "http://www.w3.org/1999/XMLSchema-instance" );
00140 }
00141
00142 $dataType = $type;
00143 $attrParts = explode( ":", $attr );
00144 if ( $attrParts[1] )
00145 {
00146 $dataType = $attrParts[1];
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 switch ( $dataType )
00160 {
00161 case "string" :
00162 case "int" :
00163 case "float" :
00164 case 'double' :
00165 {
00166 $returnValue = $node->textContent();
00167 } break;
00168
00169 case "boolean" :
00170 {
00171 if ( $node->textContent() == "true" )
00172 $returnValue = true;
00173 else
00174 $returnValue = false;
00175 } break;
00176
00177 case "base64" :
00178 {
00179 $returnValue = base64_decode( $node->textContent() );
00180 } break;
00181
00182 case "Array" :
00183 {
00184
00185 $arrayType = $node->attributeValueNS( "arrayType", EZ_SOAP_ENC );
00186
00187 $arrayTypeParts = explode( ":", $arrayType );
00188
00189 preg_match( "#(.*)\[(.*)\]#", $arrayTypeParts[1], $matches );
00190
00191 $type = $matches[1];
00192 $count = $matches[2];
00193
00194 $returnValue = array();
00195 foreach( $node->children() as $child )
00196 {
00197 $returnValue[] = eZSOAPResponse::decodeDataTypes( $child, $type );
00198 }
00199 }break;
00200
00201 case "SOAPStruct" :
00202 {
00203 $returnValue = array();
00204
00205 foreach( $node->children() as $child )
00206 {
00207 $returnValue[$child->name()] = eZSOAPResponse::decodeDataTypes( $child );
00208 }
00209 }break;
00210
00211 default:
00212 {
00213 foreach ( $node->children() as $childNode )
00214 {
00215
00216 $attr = $childNode->attributeValueNS( "type", EZ_SOAP_SCHEMA_INSTANCE );
00217
00218 $dataType = false;
00219 $attrParts = explode( ":", $attr );
00220 $dataType = $attrParts[1];
00221
00222
00223 $returnValue[$childNode->name()] = eZSOAPResponse::decodeDataTypes( $childNode );
00224 }
00225
00226 } break;
00227 }
00228
00229 return $returnValue;
00230 }
00231
00232
00233
00234
00235 function payload( )
00236 {
00237 $doc = new eZDOMDocument();
00238 $doc->setName( "eZSOAP message" );
00239
00240 $root = $doc->createElementNodeNS( EZ_SOAP_ENV, "Envelope" );
00241
00242 $root->appendAttribute( $doc->createAttributeNamespaceDefNode( EZ_SOAP_XSI_PREFIX, EZ_SOAP_SCHEMA_INSTANCE ) );
00243 $root->appendAttribute( $doc->createAttributeNamespaceDefNode( EZ_SOAP_XSD_PREFIX, EZ_SOAP_SCHEMA_DATA ) );
00244 $root->appendAttribute( $doc->createAttributeNamespaceDefNode( EZ_SOAP_ENC_PREFIX, EZ_SOAP_ENC ) );
00245 $root->setPrefix( EZ_SOAP_ENV_PREFIX );
00246
00247
00248 $body = $doc->createElementNode( "Body" );
00249
00250 $body->setPrefix( EZ_SOAP_ENV_PREFIX );
00251 $root->appendChild( $body );
00252
00253
00254 if ( get_class( $this->Value ) == 'ezsoapfault' )
00255 {
00256 $fault = $doc->createElementNode( "Fault" );
00257 $fault->setPrefix( EZ_SOAP_ENV_PREFIX );
00258
00259 $faultCodeNode = $doc->createElementNode( "faultcode" );
00260 $faultCodeNode->appendChild( eZDOMDocument::createTextNode( $this->Value->faultCode() ) );
00261
00262 $fault->appendChild( $faultCodeNode );
00263
00264 $faultStringNode = $doc->createElementNode( "faultstring" );
00265 $faultStringNode->appendChild( eZDOMDocument::createTextNode( $this->Value->faultString() ) );
00266
00267 $fault->appendChild( $faultStringNode );
00268
00269 $body->appendChild( $fault );
00270 }
00271 else
00272 {
00273
00274 $responseName = $this->Name . "Response";
00275 $response = $doc->createElementNode( $responseName );
00276 $response->setPrefix( "resp" );
00277 $response->appendAttribute( $doc->createAttributeNamespaceDefNode( "resp", $this->Namespace ) );
00278
00279 $return = $doc->createElementNode( "return" );
00280 $return->setPrefix( "resp" );
00281
00282 $value = eZSOAPCodec::encodeValue( "return", $this->Value );
00283
00284 $body->appendChild( $response );
00285
00286 $response->appendChild( $value );
00287 }
00288
00289 $doc->setRoot( $root );
00290
00291 return $doc->toString();
00292 }
00293
00294
00295
00296
00297
00298
00299 function stripHTTPHeader( $data )
00300 {
00301 $missingxml = false;
00302 $start = strpos( $data, "<?xml" );
00303 if ( $start == 0 )
00304 {
00305 eZDebug::writeWarning( "missing <?xml ...> in HTTP response, attempting workaround",
00306 "eZSoapResponse::stripHTTPHeader" );
00307 $start = strpos( $data, "<E:Envelope" );
00308 $missingxml = true;
00309 }
00310 $data = substr( $data, $start, strlen( $data ) - $start );
00311
00312 if ( $missingxml == true )
00313 {
00314 $data = '<?xml version="1.0"?>' . $data;
00315 }
00316
00317 return $data;
00318 }
00319
00320
00321
00322
00323 function value()
00324 {
00325 return $this->Value;
00326 }
00327
00328
00329
00330
00331 function setValue( $value )
00332 {
00333 $this->Value = $value;
00334 }
00335
00336
00337
00338
00339 function isFault()
00340 {
00341 return $this->IsFault;
00342 }
00343
00344
00345
00346
00347 function faultCode()
00348 {
00349 return $this->FaultCode;
00350 }
00351
00352
00353
00354
00355 function faultString()
00356 {
00357 return $this->FaultString;
00358 }
00359
00360
00361 var $Value = false;
00362
00363 var $Type = false;
00364
00365 var $FaultString = false;
00366
00367 var $FaultCode = false;
00368
00369 var $IsFault = false;
00370
00371 var $Name;
00372
00373 var $Namespace;
00374
00375
00376 var $DOMDocument = false;
00377 }
00378
00379 ?>