[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 3 4 5 6 /** 7 * 8 * nu_soapclient higher level class for easy usage. 9 * 10 * usage: 11 * 12 * // instantiate client with server info 13 * $nu_soapclient = new nu_soapclient( string path [ ,boolean wsdl] ); 14 * 15 * // call method, get results 16 * echo $nu_soapclient->call( string methodname [ ,array parameters] ); 17 * 18 * // bye bye client 19 * unset($nu_soapclient); 20 * 21 * @author Dietrich Ayala <dietrich@ganx4.com> 22 * @version $Id: class.nu_soapclient.php,v 1.52 2005/07/27 19:24:42 snichol Exp $ 23 * @access public 24 */ 25 class nu_soapclient extends nusoap_base { 26 27 var $username = ''; 28 var $password = ''; 29 var $authtype = ''; 30 var $certRequest = array(); 31 var $requestHeaders = false; // SOAP headers in request (text) 32 var $responseHeaders = ''; // SOAP headers from response (incomplete namespace resolution) (text) 33 var $document = ''; // SOAP body response portion (incomplete namespace resolution) (text) 34 var $endpoint; 35 var $forceEndpoint = ''; // overrides WSDL endpoint 36 var $proxyhost = ''; 37 var $proxyport = ''; 38 var $proxyusername = ''; 39 var $proxypassword = ''; 40 var $xml_encoding = ''; // character set encoding of incoming (response) messages 41 var $http_encoding = false; 42 var $timeout = 0; // HTTP connection timeout 43 var $response_timeout = 30; // HTTP response timeout 44 var $endpointType = ''; // soap|wsdl, empty for WSDL initialization error 45 var $persistentConnection = false; 46 var $defaultRpcParams = false; // This is no longer used 47 var $request = ''; // HTTP request 48 var $response = ''; // HTTP response 49 var $responseData = ''; // SOAP payload of response 50 var $cookies = array(); // Cookies from response or for request 51 var $decode_utf8 = true; // toggles whether the parser decodes element content w/ utf8_decode() 52 var $operations = array(); // WSDL operations, empty for WSDL initialization error 53 54 /* 55 * fault related variables 56 */ 57 /** 58 * @var fault 59 * @access public 60 */ 61 var $fault; 62 /** 63 * @var faultcode 64 * @access public 65 */ 66 var $faultcode; 67 /** 68 * @var faultstring 69 * @access public 70 */ 71 var $faultstring; 72 /** 73 * @var faultdetail 74 * @access public 75 */ 76 var $faultdetail; 77 78 /** 79 * constructor 80 * 81 * @param mixed $endpoint SOAP server or WSDL URL (string), or wsdl instance (object) 82 * @param bool $wsdl optional, set to true if using WSDL 83 * @param int $portName optional portName in WSDL document 84 * @param string $proxyhost 85 * @param string $proxyport 86 * @param string $proxyusername 87 * @param string $proxypassword 88 * @param integer $timeout set the connection timeout 89 * @param integer $response_timeout set the response timeout 90 * @access public 91 */ 92 function nu_soapclient($endpoint,$wsdl = false,$proxyhost = false,$proxyport = false,$proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30){ 93 parent::nusoap_base(); 94 $this->endpoint = $endpoint; 95 $this->proxyhost = $proxyhost; 96 $this->proxyport = $proxyport; 97 $this->proxyusername = $proxyusername; 98 $this->proxypassword = $proxypassword; 99 $this->timeout = $timeout; 100 $this->response_timeout = $response_timeout; 101 102 // make values 103 if($wsdl){ 104 if (is_object($endpoint) && (get_class($endpoint) == 'wsdl')) { 105 $this->wsdl = $endpoint; 106 $this->endpoint = $this->wsdl->wsdl; 107 $this->wsdlFile = $this->endpoint; 108 $this->debug('existing wsdl instance created from ' . $this->endpoint); 109 } else { 110 $this->wsdlFile = $this->endpoint; 111 112 // instantiate wsdl object and parse wsdl file 113 $this->debug('instantiating wsdl class with doc: '.$endpoint); 114 $this->wsdl =& new wsdl($this->wsdlFile,$this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword,$this->timeout,$this->response_timeout); 115 } 116 $this->appendDebug($this->wsdl->getDebug()); 117 $this->wsdl->clearDebug(); 118 // catch errors 119 if($errstr = $this->wsdl->getError()){ 120 $this->debug('got wsdl error: '.$errstr); 121 $this->setError('wsdl error: '.$errstr); 122 } elseif($this->operations = $this->wsdl->getOperations()){ 123 $this->debug( 'got '.count($this->operations).' operations from wsdl '.$this->wsdlFile); 124 $this->endpointType = 'wsdl'; 125 } else { 126 $this->debug( 'getOperations returned false'); 127 $this->setError('no operations defined in the WSDL document!'); 128 } 129 } else { 130 $this->debug("instantiate SOAP with endpoint at $endpoint"); 131 $this->endpointType = 'soap'; 132 } 133 } 134 135 /** 136 * calls method, returns PHP native type 137 * 138 * @param string $method SOAP server URL or path 139 * @param mixed $params An array, associative or simple, of the parameters 140 * for the method call, or a string that is the XML 141 * for the call. For rpc style, this call will 142 * wrap the XML in a tag named after the method, as 143 * well as the SOAP Envelope and Body. For document 144 * style, this will only wrap with the Envelope and Body. 145 * IMPORTANT: when using an array with document style, 146 * in which case there 147 * is really one parameter, the root of the fragment 148 * used in the call, which encloses what programmers 149 * normally think of parameters. A parameter array 150 * *must* include the wrapper. 151 * @param string $namespace optional method namespace (WSDL can override) 152 * @param string $soapAction optional SOAPAction value (WSDL can override) 153 * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers 154 * @param boolean $rpcParams optional (no longer used) 155 * @param string $style optional (rpc|document) the style to use when serializing parameters (WSDL can override) 156 * @param string $use optional (encoded|literal) the use when serializing parameters (WSDL can override) 157 * @return mixed response from SOAP call 158 * @access public 159 */ 160 function call($operation,$params=array(),$namespace='http://tempuri.org',$soapAction='',$headers=false,$rpcParams=null,$style='rpc',$use='encoded'){ 161 $this->operation = $operation; 162 $this->fault = false; 163 $this->setError(''); 164 $this->request = ''; 165 $this->response = ''; 166 $this->responseData = ''; 167 $this->faultstring = ''; 168 $this->faultcode = ''; 169 $this->opData = array(); 170 171 $this->debug("call: operation=$operation, namespace=$namespace, soapAction=$soapAction, rpcParams=$rpcParams, style=$style, use=$use, endpointType=$this->endpointType"); 172 $this->appendDebug('params=' . $this->varDump($params)); 173 $this->appendDebug('headers=' . $this->varDump($headers)); 174 if ($headers) { 175 $this->requestHeaders = $headers; 176 } 177 // serialize parameters 178 if($this->endpointType == 'wsdl' && $opData = $this->getOperationData($operation)){ 179 // use WSDL for operation 180 $this->opData = $opData; 181 $this->debug("found operation"); 182 $this->appendDebug('opData=' . $this->varDump($opData)); 183 if (isset($opData['soapAction'])) { 184 $soapAction = $opData['soapAction']; 185 } 186 if (! $this->forceEndpoint) { 187 $this->endpoint = $opData['endpoint']; 188 } else { 189 $this->endpoint = $this->forceEndpoint; 190 } 191 $namespace = isset($opData['input']['namespace']) ? $opData['input']['namespace'] : $namespace; 192 $style = $opData['style']; 193 $use = $opData['input']['use']; 194 // add ns to ns array 195 if($namespace != '' && !isset($this->wsdl->namespaces[$namespace])){ 196 $nsPrefix = 'ns' . rand(1000, 9999); 197 $this->wsdl->namespaces[$nsPrefix] = $namespace; 198 } 199 $nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace); 200 // serialize payload 201 if (is_string($params)) { 202 $this->debug("serializing param string for WSDL operation $operation"); 203 $payload = $params; 204 } elseif (is_array($params)) { 205 $this->debug("serializing param array for WSDL operation $operation"); 206 $payload = $this->wsdl->serializeRPCParameters($operation,'input',$params); 207 } else { 208 $this->debug('params must be array or string'); 209 $this->setError('params must be array or string'); 210 return false; 211 } 212 $usedNamespaces = $this->wsdl->usedNamespaces; 213 if (isset($opData['input']['encodingStyle'])) { 214 $encodingStyle = $opData['input']['encodingStyle']; 215 } else { 216 $encodingStyle = ''; 217 } 218 $this->appendDebug($this->wsdl->getDebug()); 219 $this->wsdl->clearDebug(); 220 if ($errstr = $this->wsdl->getError()) { 221 $this->debug('got wsdl error: '.$errstr); 222 $this->setError('wsdl error: '.$errstr); 223 return false; 224 } 225 } elseif($this->endpointType == 'wsdl') { 226 // operation not in WSDL 227 $this->appendDebug($this->wsdl->getDebug()); 228 $this->wsdl->clearDebug(); 229 $this->setError( 'operation '.$operation.' not present.'); 230 $this->debug("operation '$operation' not present."); 231 return false; 232 } else { 233 // no WSDL 234 //$this->namespaces['ns1'] = $namespace; 235 $nsPrefix = 'ns' . rand(1000, 9999); 236 // serialize 237 $payload = ''; 238 if (is_string($params)) { 239 $this->debug("serializing param string for operation $operation"); 240 $payload = $params; 241 } elseif (is_array($params)) { 242 $this->debug("serializing param array for operation $operation"); 243 foreach($params as $k => $v){ 244 $payload .= $this->serialize_val($v,$k,false,false,false,false,$use); 245 } 246 } else { 247 $this->debug('params must be array or string'); 248 $this->setError('params must be array or string'); 249 return false; 250 } 251 $usedNamespaces = array(); 252 if ($use == 'encoded') { 253 $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; 254 } else { 255 $encodingStyle = ''; 256 } 257 } 258 // wrap RPC calls with method element 259 if ($style == 'rpc') { 260 if ($use == 'literal') { 261 $this->debug("wrapping RPC request with literal method element"); 262 if ($namespace) { 263 $payload = "<$operation xmlns=\"$namespace\">" . $payload . "</$operation>"; 264 } else { 265 $payload = "<$operation>" . $payload . "</$operation>"; 266 } 267 } else { 268 $this->debug("wrapping RPC request with encoded method element"); 269 if ($namespace) { 270 $payload = "<$nsPrefix:$operation xmlns:$nsPrefix=\"$namespace\">" . 271 $payload . 272 "</$nsPrefix:$operation>"; 273 } else { 274 $payload = "<$operation>" . 275 $payload . 276 "</$operation>"; 277 } 278 } 279 } 280 // serialize envelope 281 $soapmsg = $this->serializeEnvelope($payload,$this->requestHeaders,$usedNamespaces,$style,$use,$encodingStyle); 282 $this->debug("endpoint=$this->endpoint, soapAction=$soapAction, namespace=$namespace, style=$style, use=$use, encodingStyle=$encodingStyle"); 283 $this->debug('SOAP message length=' . strlen($soapmsg) . ' contents (max 1000 bytes)=' . substr($soapmsg, 0, 1000)); 284 // send 285 $return = $this->send($this->getHTTPBody($soapmsg),$soapAction,$this->timeout,$this->response_timeout); 286 if($errstr = $this->getError()){ 287 $this->debug('Error: '.$errstr); 288 return false; 289 } else { 290 $this->return = $return; 291 $this->debug('sent message successfully and got a(n) '.gettype($return)); 292 $this->appendDebug('return=' . $this->varDump($return)); 293 294 // fault? 295 if(is_array($return) && isset($return['faultcode'])){ 296 $this->debug('got fault'); 297 $this->setError($return['faultcode'].': '.$return['faultstring']); 298 $this->fault = true; 299 foreach($return as $k => $v){ 300 $this->$k = $v; 301 $this->debug("$k = $v<br>"); 302 } 303 return $return; 304 } elseif ($style == 'document') { 305 // NOTE: if the response is defined to have multiple parts (i.e. unwrapped), 306 // we are only going to return the first part here...sorry about that 307 return $return; 308 } else { 309 // array of return values 310 if(is_array($return)){ 311 // multiple 'out' parameters, which we return wrapped up 312 // in the array 313 if(sizeof($return) > 1){ 314 return $return; 315 } 316 // single 'out' parameter (normally the return value) 317 $return = array_shift($return); 318 $this->debug('return shifted value: '); 319 $this->appendDebug($this->varDump($return)); 320 return $return; 321 // nothing returned (ie, echoVoid) 322 } else { 323 return ""; 324 } 325 } 326 } 327 } 328 329 /** 330 * get available data pertaining to an operation 331 * 332 * @param string $operation operation name 333 * @return array array of data pertaining to the operation 334 * @access public 335 */ 336 function getOperationData($operation){ 337 if(isset($this->operations[$operation])){ 338 return $this->operations[$operation]; 339 } 340 $this->debug("No data for operation: $operation"); 341 } 342 343 /** 344 * send the SOAP message 345 * 346 * Note: if the operation has multiple return values 347 * the return value of this method will be an array 348 * of those values. 349 * 350 * @param string $msg a SOAPx4 soapmsg object 351 * @param string $soapaction SOAPAction value 352 * @param integer $timeout set connection timeout in seconds 353 * @param integer $response_timeout set response timeout in seconds 354 * @return mixed native PHP types. 355 * @access private 356 */ 357 function send($msg, $soapaction = '', $timeout=0, $response_timeout=30) { 358 $this->checkCookies(); 359 // detect transport 360 switch(true){ 361 // http(s) 362 case ereg('^http',$this->endpoint): 363 $this->debug('transporting via HTTP'); 364 if($this->persistentConnection == true && is_object($this->persistentConnection)){ 365 $http =& $this->persistentConnection; 366 } else { 367 $http = new soap_transport_http($this->endpoint); 368 if ($this->persistentConnection) { 369 $http->usePersistentConnection(); 370 } 371 } 372 $http->setContentType($this->getHTTPContentType(), $this->getHTTPContentTypeCharset()); 373 $http->setSOAPAction($soapaction); 374 if($this->proxyhost && $this->proxyport){ 375 $http->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword); 376 } 377 if($this->authtype != '') { 378 $http->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest); 379 } 380 if($this->http_encoding != ''){ 381 $http->setEncoding($this->http_encoding); 382 } 383 $this->debug('sending message, length='.strlen($msg)); 384 if(ereg('^http:',$this->endpoint)){ 385 //if(strpos($this->endpoint,'http:')){ 386 $this->responseData = $http->send($msg,$timeout,$response_timeout,$this->cookies); 387 } elseif(ereg('^https',$this->endpoint)){ 388 //} elseif(strpos($this->endpoint,'https:')){ 389 //if(phpversion() == '4.3.0-dev'){ 390 //$response = $http->send($msg,$timeout,$response_timeout); 391 //$this->request = $http->outgoing_payload; 392 //$this->response = $http->incoming_payload; 393 //} else 394 $this->responseData = $http->sendHTTPS($msg,$timeout,$response_timeout,$this->cookies); 395 } else { 396 $this->setError('no http/s in endpoint url'); 397 } 398 $this->request = $http->outgoing_payload; 399 $this->response = $http->incoming_payload; 400 $this->appendDebug($http->getDebug()); 401 $this->UpdateCookies($http->incoming_cookies); 402 403 // save transport object if using persistent connections 404 if ($this->persistentConnection) { 405 $http->clearDebug(); 406 if (!is_object($this->persistentConnection)) { 407 $this->persistentConnection = $http; 408 } 409 } 410 411 if($err = $http->getError()){ 412 $this->setError('HTTP Error: '.$err); 413 return false; 414 } elseif($this->getError()){ 415 return false; 416 } else { 417 $this->debug('got response, length='. strlen($this->responseData).' type='.$http->incoming_headers['content-type']); 418 return $this->parseResponse($http->incoming_headers, $this->responseData); 419 } 420 break; 421 default: 422 $this->setError('no transport found, or selected transport is not yet supported!'); 423 return false; 424 break; 425 } 426 } 427 428 /** 429 * processes SOAP message returned from server 430 * 431 * @param array $headers The HTTP headers 432 * @param string $data unprocessed response data from server 433 * @return mixed value of the message, decoded into a PHP type 434 * @access private 435 */ 436 function parseResponse($headers, $data) { 437 $this->debug('Entering parseResponse() for data of length ' . strlen($data) . ' and type ' . $headers['content-type']); 438 if (!strstr($headers['content-type'], 'text/xml')) { 439 $this->setError('Response not of type text/xml'); 440 return false; 441 } 442 if (strpos($headers['content-type'], '=')) { 443 $enc = str_replace('"', '', substr(strstr($headers["content-type"], '='), 1)); 444 $this->debug('Got response encoding: ' . $enc); 445 if(eregi('^(ISO-8859-1|US-ASCII|UTF-8)$',$enc)){ 446 $this->xml_encoding = strtoupper($enc); 447 } else { 448 $this->xml_encoding = 'US-ASCII'; 449 } 450 } else { 451 // should be US-ASCII for HTTP 1.0 or ISO-8859-1 for HTTP 1.1 452 $this->xml_encoding = 'ISO-8859-1'; 453 } 454 $this->debug('Use encoding: ' . $this->xml_encoding . ' when creating soap_parser'); 455 $parser = new soap_parser($data,$this->xml_encoding,$this->operation,$this->decode_utf8); 456 // add parser debug data to our debug 457 $this->appendDebug($parser->getDebug()); 458 // if parse errors 459 if($errstr = $parser->getError()){ 460 $this->setError( $errstr); 461 // destroy the parser object 462 unset($parser); 463 return false; 464 } else { 465 // get SOAP headers 466 $this->responseHeaders = $parser->getHeaders(); 467 // get decoded message 468 $return = $parser->get_response(); 469 // add document for doclit support 470 $this->document = $parser->document; 471 // destroy the parser object 472 unset($parser); 473 // return decode message 474 return $return; 475 } 476 } 477 478 /** 479 * sets the SOAP endpoint, which can override WSDL 480 * 481 * @param $endpoint string The endpoint URL to use, or empty string or false to prevent override 482 * @access public 483 */ 484 function setEndpoint($endpoint) { 485 $this->forceEndpoint = $endpoint; 486 } 487 488 /** 489 * set the SOAP headers 490 * 491 * @param $headers mixed String of XML with SOAP header content, or array of soapval objects for SOAP headers 492 * @access public 493 */ 494 function setHeaders($headers){ 495 $this->requestHeaders = $headers; 496 } 497 498 /** 499 * get the SOAP response headers (namespace resolution incomplete) 500 * 501 * @return string 502 * @access public 503 */ 504 function getHeaders(){ 505 return $this->responseHeaders; 506 } 507 508 /** 509 * set proxy info here 510 * 511 * @param string $proxyhost 512 * @param string $proxyport 513 * @param string $proxyusername 514 * @param string $proxypassword 515 * @access public 516 */ 517 function setHTTPProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '') { 518 $this->proxyhost = $proxyhost; 519 $this->proxyport = $proxyport; 520 $this->proxyusername = $proxyusername; 521 $this->proxypassword = $proxypassword; 522 } 523 524 /** 525 * if authenticating, set user credentials here 526 * 527 * @param string $username 528 * @param string $password 529 * @param string $authtype (basic|digest|certificate) 530 * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) 531 * @access public 532 */ 533 function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) { 534 $this->username = $username; 535 $this->password = $password; 536 $this->authtype = $authtype; 537 $this->certRequest = $certRequest; 538 } 539 540 /** 541 * use HTTP encoding 542 * 543 * @param string $enc 544 * @access public 545 */ 546 function setHTTPEncoding($enc='gzip, deflate'){ 547 $this->http_encoding = $enc; 548 } 549 550 /** 551 * use HTTP persistent connections if possible 552 * 553 * @access public 554 */ 555 function useHTTPPersistentConnection(){ 556 $this->persistentConnection = true; 557 } 558 559 /** 560 * gets the default RPC parameter setting. 561 * If true, default is that call params are like RPC even for document style. 562 * Each call() can override this value. 563 * 564 * This is no longer used. 565 * 566 * @return boolean 567 * @access public 568 * @deprecated 569 */ 570 function getDefaultRpcParams() { 571 return $this->defaultRpcParams; 572 } 573 574 /** 575 * sets the default RPC parameter setting. 576 * If true, default is that call params are like RPC even for document style 577 * Each call() can override this value. 578 * 579 * This is no longer used. 580 * 581 * @param boolean $rpcParams 582 * @access public 583 * @deprecated 584 */ 585 function setDefaultRpcParams($rpcParams) { 586 $this->defaultRpcParams = $rpcParams; 587 } 588 589 /** 590 * dynamically creates an instance of a proxy class, 591 * allowing user to directly call methods from wsdl 592 * 593 * @return object soap_proxy object 594 * @access public 595 */ 596 function getProxy(){ 597 $r = rand(); 598 $evalStr = $this->_getProxyClassCode($r); 599 //$this->debug("proxy class: $evalStr"; 600 // eval the class 601 eval($evalStr); 602 // instantiate proxy object 603 eval("\$proxy = new soap_proxy_$r('');"); 604 // transfer current wsdl data to the proxy thereby avoiding parsing the wsdl twice 605 $proxy->endpointType = 'wsdl'; 606 $proxy->wsdlFile = $this->wsdlFile; 607 $proxy->wsdl = $this->wsdl; 608 $proxy->operations = $this->operations; 609 $proxy->defaultRpcParams = $this->defaultRpcParams; 610 // transfer other state 611 $proxy->username = $this->username; 612 $proxy->password = $this->password; 613 $proxy->authtype = $this->authtype; 614 $proxy->proxyhost = $this->proxyhost; 615 $proxy->proxyport = $this->proxyport; 616 $proxy->proxyusername = $this->proxyusername; 617 $proxy->proxypassword = $this->proxypassword; 618 $proxy->timeout = $this->timeout; 619 $proxy->response_timeout = $this->response_timeout; 620 $proxy->http_encoding = $this->http_encoding; 621 $proxy->persistentConnection = $this->persistentConnection; 622 $proxy->requestHeaders = $this->requestHeaders; 623 $proxy->soap_defencoding = $this->soap_defencoding; 624 $proxy->endpoint = $this->endpoint; 625 $proxy->forceEndpoint = $this->forceEndpoint; 626 return $proxy; 627 } 628 629 /** 630 * dynamically creates proxy class code 631 * 632 * @return string PHP/NuSOAP code for the proxy class 633 * @access private 634 */ 635 function _getProxyClassCode($r) { 636 if ($this->endpointType != 'wsdl') { 637 $evalStr = 'A proxy can only be created for a WSDL client'; 638 $this->setError($evalStr); 639 return $evalStr; 640 } 641 $evalStr = ''; 642 foreach ($this->operations as $operation => $opData) { 643 if ($operation != '') { 644 // create param string and param comment string 645 if (sizeof($opData['input']['parts']) > 0) { 646 $paramStr = ''; 647 $paramArrayStr = ''; 648 $paramCommentStr = ''; 649 foreach ($opData['input']['parts'] as $name => $type) { 650 $paramStr .= "\$$name, "; 651 $paramArrayStr .= "'$name' => \$$name, "; 652 $paramCommentStr .= "$type \$$name, "; 653 } 654 $paramStr = substr($paramStr, 0, strlen($paramStr)-2); 655 $paramArrayStr = substr($paramArrayStr, 0, strlen($paramArrayStr)-2); 656 $paramCommentStr = substr($paramCommentStr, 0, strlen($paramCommentStr)-2); 657 } else { 658 $paramStr = ''; 659 $paramCommentStr = 'void'; 660 } 661 $opData['namespace'] = !isset($opData['namespace']) ? 'http://testuri.com' : $opData['namespace']; 662 $evalStr .= "// $paramCommentStr 663 function " . str_replace('.', '__', $operation) . "($paramStr) { 664 \$params = array($paramArrayStr); 665 return \$this->call('$operation', \$params, '".$opData['namespace']."', '".(isset($opData['soapAction']) ? $opData['soapAction'] : '')."'); 666 } 667 "; 668 unset($paramStr); 669 unset($paramCommentStr); 670 } 671 } 672 $evalStr = 'class soap_proxy_'.$r.' extends nu_soapclient { 673 '.$evalStr.' 674 }'; 675 return $evalStr; 676 } 677 678 /** 679 * dynamically creates proxy class code 680 * 681 * @return string PHP/NuSOAP code for the proxy class 682 * @access public 683 */ 684 function getProxyClassCode() { 685 $r = rand(); 686 return $this->_getProxyClassCode($r); 687 } 688 689 /** 690 * gets the HTTP body for the current request. 691 * 692 * @param string $soapmsg The SOAP payload 693 * @return string The HTTP body, which includes the SOAP payload 694 * @access private 695 */ 696 function getHTTPBody($soapmsg) { 697 return $soapmsg; 698 } 699 700 /** 701 * gets the HTTP content type for the current request. 702 * 703 * Note: getHTTPBody must be called before this. 704 * 705 * @return string the HTTP content type for the current request. 706 * @access private 707 */ 708 function getHTTPContentType() { 709 return 'text/xml'; 710 } 711 712 /** 713 * gets the HTTP content type charset for the current request. 714 * returns false for non-text content types. 715 * 716 * Note: getHTTPBody must be called before this. 717 * 718 * @return string the HTTP content type charset for the current request. 719 * @access private 720 */ 721 function getHTTPContentTypeCharset() { 722 return $this->soap_defencoding; 723 } 724 725 /* 726 * whether or not parser should decode utf8 element content 727 * 728 * @return always returns true 729 * @access public 730 */ 731 function decodeUTF8($bool){ 732 $this->decode_utf8 = $bool; 733 return true; 734 } 735 736 /** 737 * adds a new Cookie into $this->cookies array 738 * 739 * @param string $name Cookie Name 740 * @param string $value Cookie Value 741 * @return if cookie-set was successful returns true, else false 742 * @access public 743 */ 744 function setCookie($name, $value) { 745 if (strlen($name) == 0) { 746 return false; 747 } 748 $this->cookies[] = array('name' => $name, 'value' => $value); 749 return true; 750 } 751 752 /** 753 * gets all Cookies 754 * 755 * @return array with all internal cookies 756 * @access public 757 */ 758 function getCookies() { 759 return $this->cookies; 760 } 761 762 /** 763 * checks all Cookies and delete those which are expired 764 * 765 * @return always return true 766 * @access private 767 */ 768 function checkCookies() { 769 if (sizeof($this->cookies) == 0) { 770 return true; 771 } 772 $this->debug('checkCookie: check ' . sizeof($this->cookies) . ' cookies'); 773 $curr_cookies = $this->cookies; 774 $this->cookies = array(); 775 foreach ($curr_cookies as $cookie) { 776 if (! is_array($cookie)) { 777 $this->debug('Remove cookie that is not an array'); 778 continue; 779 } 780 if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) { 781 if (strtotime($cookie['expires']) > time()) { 782 $this->cookies[] = $cookie; 783 } else { 784 $this->debug('Remove expired cookie ' . $cookie['name']); 785 } 786 } else { 787 $this->cookies[] = $cookie; 788 } 789 } 790 $this->debug('checkCookie: '.sizeof($this->cookies).' cookies left in array'); 791 return true; 792 } 793 794 /** 795 * updates the current cookies with a new set 796 * 797 * @param array $cookies new cookies with which to update current ones 798 * @return always return true 799 * @access private 800 */ 801 function UpdateCookies($cookies) { 802 if (sizeof($this->cookies) == 0) { 803 // no existing cookies: take whatever is new 804 if (sizeof($cookies) > 0) { 805 $this->debug('Setting new cookie(s)'); 806 $this->cookies = $cookies; 807 } 808 return true; 809 } 810 if (sizeof($cookies) == 0) { 811 // no new cookies: keep what we've got 812 return true; 813 } 814 // merge 815 foreach ($cookies as $newCookie) { 816 if (!is_array($newCookie)) { 817 continue; 818 } 819 if ((!isset($newCookie['name'])) || (!isset($newCookie['value']))) { 820 continue; 821 } 822 $newName = $newCookie['name']; 823 824 $found = false; 825 for ($i = 0; $i < count($this->cookies); $i++) { 826 $cookie = $this->cookies[$i]; 827 if (!is_array($cookie)) { 828 continue; 829 } 830 if (!isset($cookie['name'])) { 831 continue; 832 } 833 if ($newName != $cookie['name']) { 834 continue; 835 } 836 $newDomain = isset($newCookie['domain']) ? $newCookie['domain'] : 'NODOMAIN'; 837 $domain = isset($cookie['domain']) ? $cookie['domain'] : 'NODOMAIN'; 838 if ($newDomain != $domain) { 839 continue; 840 } 841 $newPath = isset($newCookie['path']) ? $newCookie['path'] : 'NOPATH'; 842 $path = isset($cookie['path']) ? $cookie['path'] : 'NOPATH'; 843 if ($newPath != $path) { 844 continue; 845 } 846 $this->cookies[$i] = $newCookie; 847 $found = true; 848 $this->debug('Update cookie ' . $newName . '=' . $newCookie['value']); 849 break; 850 } 851 if (! $found) { 852 $this->debug('Add cookie ' . $newName . '=' . $newCookie['value']); 853 $this->cookies[] = $newCookie; 854 } 855 } 856 return true; 857 } 858 } 859 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |