@@ -2217,8 +2217,8 @@ discard block |
||
| 2217 | 2217 | public $persistentConnection = false; |
| 2218 | 2218 | public $ch = false; // cURL handle |
| 2219 | 2219 | public $ch_options = array(); // cURL custom options |
| 2220 | - public $use_curl = false; // force cURL use |
|
| 2221 | - public $proxy = null; // proxy information (associative array) |
|
| 2220 | + public $use_curl = false; // force cURL use |
|
| 2221 | + public $proxy = null; // proxy information (associative array) |
|
| 2222 | 2222 | public $username = ''; |
| 2223 | 2223 | public $password = ''; |
| 2224 | 2224 | public $authtype = ''; |
@@ -2654,7 +2654,7 @@ discard block |
||
| 2654 | 2654 | $this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password)); |
| 2655 | 2655 | } elseif ($authtype == 'digest') { |
| 2656 | 2656 | if (isset($digestRequest['nonce'])) { |
| 2657 | - $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc'] ++ : 1; |
|
| 2657 | + $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1; |
|
| 2658 | 2658 | |
| 2659 | 2659 | // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html) |
| 2660 | 2660 | // A1 = unq(username-value) ":" unq(realm-value) ":" passwd |
@@ -4104,7 +4104,7 @@ discard block |
||
| 4104 | 4104 | $call_arg = array($class, $method); |
| 4105 | 4105 | } else { |
| 4106 | 4106 | $this->debug('in invoke_method, calling instance method using call_user_func_array()'); |
| 4107 | - $instance = new $class (); |
|
| 4107 | + $instance = new $class(); |
|
| 4108 | 4108 | $call_arg = array(&$instance, $method); |
| 4109 | 4109 | } |
| 4110 | 4110 | if (is_array($this->methodparams)) { |
@@ -4660,12 +4660,12 @@ discard block |
||
| 4660 | 4660 | public $timeout = 0; |
| 4661 | 4661 | public $response_timeout = 30; |
| 4662 | 4662 | public $curl_options = array(); // User-specified cURL options |
| 4663 | - public $use_curl = false; // whether to always try to use cURL |
|
| 4663 | + public $use_curl = false; // whether to always try to use cURL |
|
| 4664 | 4664 | // for HTTP authentication |
| 4665 | 4665 | public $username = ''; // Username for HTTP authentication |
| 4666 | 4666 | public $password = ''; // Password for HTTP authentication |
| 4667 | 4667 | public $authtype = ''; // Type of HTTP authentication |
| 4668 | - public $certRequest = array(); // Certificate for HTTP SSL authentication |
|
| 4668 | + public $certRequest = array(); // Certificate for HTTP SSL authentication |
|
| 4669 | 4669 | |
| 4670 | 4670 | /** |
| 4671 | 4671 | * constructor |
@@ -4779,11 +4779,9 @@ discard block |
||
| 4779 | 4779 | foreach ($bindingData['operations'] as $operation => $data) { |
| 4780 | 4780 | $this->debug('post-parse data gathering for ' . $operation); |
| 4781 | 4781 | $this->bindings[$binding]['operations'][$operation]['input'] = isset($this->bindings[$binding]['operations'][$operation]['input']) ? |
| 4782 | - array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) : |
|
| 4783 | - $this->portTypes[$bindingData['portType']][$operation]['input']; |
|
| 4782 | + array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) : $this->portTypes[$bindingData['portType']][$operation]['input']; |
|
| 4784 | 4783 | $this->bindings[$binding]['operations'][$operation]['output'] = isset($this->bindings[$binding]['operations'][$operation]['output']) ? |
| 4785 | - array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) : |
|
| 4786 | - $this->portTypes[$bindingData['portType']][$operation]['output']; |
|
| 4784 | + array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) : $this->portTypes[$bindingData['portType']][$operation]['output']; |
|
| 4787 | 4785 | if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) { |
| 4788 | 4786 | $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']]; |
| 4789 | 4787 | } |
@@ -6303,7 +6301,7 @@ discard block |
||
| 6303 | 6301 | } |
| 6304 | 6302 | } |
| 6305 | 6303 | // if user took advantage of a minOccurs=0, then only serialize named parameters |
| 6306 | - if (isset($optionals) && (!isset($xvalue[$eName])) && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
| 6304 | + if (isset($optionals) && (!isset($xvalue[$eName])) && ((!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
| 6307 | 6305 | ) { |
| 6308 | 6306 | if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') { |
| 6309 | 6307 | $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']); |
@@ -6547,7 +6545,7 @@ discard block |
||
| 6547 | 6545 | public $root_struct_name = ''; |
| 6548 | 6546 | public $root_struct_namespace = ''; |
| 6549 | 6547 | public $root_header = ''; |
| 6550 | - public $document = ''; // incoming SOAP body (text) |
|
| 6548 | + public $document = ''; // incoming SOAP body (text) |
|
| 6551 | 6549 | // determines where in the message we are (envelope,header,body,method) |
| 6552 | 6550 | public $status = ''; |
| 6553 | 6551 | public $position = 0; |
@@ -6563,7 +6561,7 @@ discard block |
||
| 6563 | 6561 | public $depth_array = array(); |
| 6564 | 6562 | public $debug_flag = true; |
| 6565 | 6563 | public $soapresponse = NULL; // parsed SOAP Body |
| 6566 | - public $soapheader = NULL; // parsed SOAP Header |
|
| 6564 | + public $soapheader = NULL; // parsed SOAP Header |
|
| 6567 | 6565 | public $responseHeaders = ''; // incoming SOAP headers (text) |
| 6568 | 6566 | public $body_position = 0; |
| 6569 | 6567 | // for multiref parsing: |
@@ -29,18 +29,18 @@ discard block |
||
| 29 | 29 | public $incoming_cookies = array(); |
| 30 | 30 | public $outgoing_payload = ''; |
| 31 | 31 | public $incoming_payload = ''; |
| 32 | - public $response_status_line; // HTTP response status line |
|
| 32 | + public $response_status_line; // HTTP response status line |
|
| 33 | 33 | public $useSOAPAction = true; |
| 34 | 34 | public $persistentConnection = false; |
| 35 | - public $ch = false; // cURL handle |
|
| 36 | - public $ch_options = array(); // cURL custom options |
|
| 37 | - public $use_curl = false; // force cURL use |
|
| 38 | - public $proxy = null; // proxy information (associative array) |
|
| 35 | + public $ch = false; // cURL handle |
|
| 36 | + public $ch_options = array(); // cURL custom options |
|
| 37 | + public $use_curl = false; // force cURL use |
|
| 38 | + public $proxy = null; // proxy information (associative array) |
|
| 39 | 39 | public $username = ''; |
| 40 | 40 | public $password = ''; |
| 41 | 41 | public $authtype = ''; |
| 42 | 42 | public $digestRequest = array(); |
| 43 | - public $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional) |
|
| 43 | + public $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional) |
|
| 44 | 44 | // cainfofile: certificate authority file, e.g. '$pathToPemFiles/rootca.pem' |
| 45 | 45 | // sslcertfile: SSL certificate file, e.g. '$pathToPemFiles/mycert.pem' |
| 46 | 46 | // sslkeyfile: SSL key file, e.g. '$pathToPemFiles/mykey.pem' |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param boolean $use_curl Whether to try to force cURL use |
| 58 | 58 | * @access public |
| 59 | 59 | */ |
| 60 | - public function soap_transport_http($url, $curl_options = NULL, $use_curl = false){ |
|
| 60 | + public function soap_transport_http($url, $curl_options = NULL, $use_curl = false) { |
|
| 61 | 61 | parent::nusoap_base(); |
| 62 | 62 | $this->debug("ctor url=$url use_curl=$use_curl curl_options:"); |
| 63 | 63 | $this->appendDebug($this->varDump($curl_options)); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | } |
| 68 | 68 | $this->use_curl = $use_curl; |
| 69 | 69 | preg_match('/\$Revisio' . 'n: ([^ ]+)/', $this->revision, $rev); |
| 70 | - $this->setHeader('User-Agent', $this->title.'/'.$this->version.' ('.$rev[1].')'); |
|
| 70 | + $this->setHeader('User-Agent', $this->title . '/' . $this->version . ' (' . $rev[1] . ')'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -118,19 +118,19 @@ discard block |
||
| 118 | 118 | $this->url = $url; |
| 119 | 119 | |
| 120 | 120 | $u = parse_url($url); |
| 121 | - foreach($u as $k => $v){ |
|
| 121 | + foreach ($u as $k => $v) { |
|
| 122 | 122 | $this->debug("parsed URL $k = $v"); |
| 123 | 123 | $this->$k = $v; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // add any GET params to path |
| 127 | - if(isset($u['query']) && $u['query'] != ''){ |
|
| 127 | + if (isset($u['query']) && $u['query'] != '') { |
|
| 128 | 128 | $this->path .= '?' . $u['query']; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // set default port |
| 132 | - if(!isset($u['port'])){ |
|
| 133 | - if($u['scheme'] == 'https'){ |
|
| 132 | + if (!isset($u['port'])) { |
|
| 133 | + if ($u['scheme'] == 'https') { |
|
| 134 | 134 | $this->port = 443; |
| 135 | 135 | } else { |
| 136 | 136 | $this->port = 80; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | if (!isset($u['port'])) { |
| 145 | 145 | $this->setHeader('Host', $this->host); |
| 146 | 146 | } else { |
| 147 | - $this->setHeader('Host', $this->host.':'.$this->port); |
|
| 147 | + $this->setHeader('Host', $this->host . ':' . $this->port); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | if (isset($u['user']) && $u['user'] != '') { |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @return boolean true if connected, false if not |
| 175 | 175 | * @access private |
| 176 | 176 | */ |
| 177 | - public function connect($connection_timeout=0,$response_timeout=30){ |
|
| 177 | + public function connect($connection_timeout = 0, $response_timeout = 30) { |
|
| 178 | 178 | $this->debug("connect connection_timeout $connection_timeout, response_timeout $response_timeout, scheme $this->scheme, host $this->host, port $this->port"); |
| 179 | 179 | if ($this->io_method() == 'socket') { |
| 180 | 180 | if (!is_array($this->proxy)) { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // use persistent connection |
| 189 | - if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){ |
|
| 189 | + if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) { |
|
| 190 | 190 | if (!feof($this->fp)) { |
| 191 | 191 | $this->debug('Re-use persistent connection'); |
| 192 | 192 | return true; |
@@ -202,17 +202,17 @@ discard block |
||
| 202 | 202 | $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout); |
| 203 | 203 | |
| 204 | 204 | // open socket |
| 205 | - if($connection_timeout > 0){ |
|
| 206 | - $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout); |
|
| 205 | + if ($connection_timeout > 0) { |
|
| 206 | + $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout); |
|
| 207 | 207 | } else { |
| 208 | - $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str); |
|
| 208 | + $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str); |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | // test pointer |
| 212 | - if(!$this->fp) { |
|
| 212 | + if (!$this->fp) { |
|
| 213 | 213 | $msg = 'Couldn\'t open socket connection to server ' . $this->url; |
| 214 | 214 | if ($this->errno) { |
| 215 | - $msg .= ', Error ('.$this->errno.'): '.$this->error_str; |
|
| 215 | + $msg .= ', Error (' . $this->errno . '): ' . $this->error_str; |
|
| 216 | 216 | } else { |
| 217 | 217 | $msg .= ' prior to connect(). This is often a problem looking up the host name.'; |
| 218 | 218 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | // set response timeout |
| 225 | 225 | $this->debug('set response timeout to ' . $response_timeout); |
| 226 | - socket_set_timeout( $this->fp, $response_timeout); |
|
| 226 | + socket_set_timeout($this->fp, $response_timeout); |
|
| 227 | 227 | |
| 228 | 228 | $this->debug('socket connected'); |
| 229 | 229 | return true; |
@@ -362,13 +362,13 @@ discard block |
||
| 362 | 362 | if (is_array($this->proxy)) { |
| 363 | 363 | $this->debug('set cURL proxy options'); |
| 364 | 364 | if ($this->proxy['port'] != '') { |
| 365 | - $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']); |
|
| 365 | + $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'] . ':' . $this->proxy['port']); |
|
| 366 | 366 | } else { |
| 367 | 367 | $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']); |
| 368 | 368 | } |
| 369 | 369 | if ($this->proxy['username'] || $this->proxy['password']) { |
| 370 | 370 | $this->debug('set cURL proxy authentication options'); |
| 371 | - $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']); |
|
| 371 | + $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'] . ':' . $this->proxy['password']); |
|
| 372 | 372 | if ($this->proxy['authtype'] == 'basic') { |
| 373 | 373 | $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC); |
| 374 | 374 | } |
@@ -396,9 +396,9 @@ discard block |
||
| 396 | 396 | * @return string data |
| 397 | 397 | * @access public |
| 398 | 398 | */ |
| 399 | - public function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) { |
|
| 399 | + public function send($data, $timeout = 0, $response_timeout = 30, $cookies = NULL) { |
|
| 400 | 400 | |
| 401 | - $this->debug('entered send() with data of length: '.strlen($data)); |
|
| 401 | + $this->debug('entered send() with data of length: ' . strlen($data)); |
|
| 402 | 402 | |
| 403 | 403 | $this->tryagain = true; |
| 404 | 404 | $tries = 0; |
@@ -406,12 +406,12 @@ discard block |
||
| 406 | 406 | $this->tryagain = false; |
| 407 | 407 | if ($tries++ < 2) { |
| 408 | 408 | // make connnection |
| 409 | - if (!$this->connect($timeout, $response_timeout)){ |
|
| 409 | + if (!$this->connect($timeout, $response_timeout)) { |
|
| 410 | 410 | return false; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | // send request |
| 414 | - if (!$this->sendRequest($data, $cookies)){ |
|
| 414 | + if (!$this->sendRequest($data, $cookies)) { |
|
| 415 | 415 | return false; |
| 416 | 416 | } |
| 417 | 417 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | * @access public |
| 438 | 438 | * @deprecated |
| 439 | 439 | */ |
| 440 | - public function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) { |
|
| 440 | + public function sendHTTPS($data, $timeout = 0, $response_timeout = 30, $cookies) { |
|
| 441 | 441 | return $this->send($data, $timeout, $response_timeout, $cookies); |
| 442 | 442 | } |
| 443 | 443 | |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | $this->appendDebug($this->varDump($certRequest)); |
| 459 | 459 | // cf. RFC 2617 |
| 460 | 460 | if ($authtype == 'basic') { |
| 461 | - $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password)); |
|
| 461 | + $this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password)); |
|
| 462 | 462 | } elseif ($authtype == 'digest') { |
| 463 | 463 | if (isset($digestRequest['nonce'])) { |
| 464 | 464 | $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1; |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html) |
| 467 | 467 | |
| 468 | 468 | // A1 = unq(username-value) ":" unq(realm-value) ":" passwd |
| 469 | - $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; |
|
| 469 | + $A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; |
|
| 470 | 470 | |
| 471 | 471 | // H(A1) = MD5(A1) |
| 472 | 472 | $HA1 = md5($A1); |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | $A2 = $this->request_method . ':' . $this->digest_uri; |
| 476 | 476 | |
| 477 | 477 | // H(A2) |
| 478 | - $HA2 = md5($A2); |
|
| 478 | + $HA2 = md5($A2); |
|
| 479 | 479 | |
| 480 | 480 | // KD(secret, data) = H(concat(secret, ":", data)) |
| 481 | 481 | // if qop == auth: |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | * @param string $enc encoding style. supported values: gzip, deflate, or both |
| 536 | 536 | * @access public |
| 537 | 537 | */ |
| 538 | - public function setEncoding($enc='gzip, deflate') { |
|
| 538 | + public function setEncoding($enc = 'gzip, deflate') { |
|
| 539 | 539 | if (function_exists('gzdeflate')) { |
| 540 | 540 | $this->protocol_version = '1.1'; |
| 541 | 541 | $this->setHeader('Accept-Encoding', $enc); |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | 'authtype' => $proxyauthtype |
| 570 | 570 | ); |
| 571 | 571 | if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') { |
| 572 | - $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword)); |
|
| 572 | + $this->setHeader('Proxy-Authorization', ' Basic ' . base64_encode($proxyusername . ':' . $proxypassword)); |
|
| 573 | 573 | } |
| 574 | 574 | } else { |
| 575 | 575 | $this->debug('remove proxy'); |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | * @access private |
| 589 | 589 | */ |
| 590 | 590 | public function isSkippableCurlHeader(&$data) { |
| 591 | - $skipHeaders = array( 'HTTP/1.1 100', |
|
| 591 | + $skipHeaders = array('HTTP/1.1 100', |
|
| 592 | 592 | 'HTTP/1.0 301', |
| 593 | 593 | 'HTTP/1.1 301', |
| 594 | 594 | 'HTTP/1.0 302', |
@@ -614,7 +614,7 @@ discard block |
||
| 614 | 614 | * @access public |
| 615 | 615 | * @deprecated |
| 616 | 616 | */ |
| 617 | - public function decodeChunked($buffer, $lb){ |
|
| 617 | + public function decodeChunked($buffer, $lb) { |
|
| 618 | 618 | // length := 0 |
| 619 | 619 | $length = 0; |
| 620 | 620 | $new = ''; |
@@ -626,17 +626,17 @@ discard block |
||
| 626 | 626 | $this->debug('no linebreak found in decodeChunked'); |
| 627 | 627 | return $new; |
| 628 | 628 | } |
| 629 | - $temp = substr($buffer,0,$chunkend); |
|
| 630 | - $chunk_size = hexdec( trim($temp) ); |
|
| 629 | + $temp = substr($buffer, 0, $chunkend); |
|
| 630 | + $chunk_size = hexdec(trim($temp)); |
|
| 631 | 631 | $chunkstart = $chunkend + strlen($lb); |
| 632 | 632 | // while (chunk-size > 0) { |
| 633 | 633 | while ($chunk_size > 0) { |
| 634 | 634 | $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size"); |
| 635 | - $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size); |
|
| 635 | + $chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size); |
|
| 636 | 636 | |
| 637 | 637 | // Just in case we got a broken connection |
| 638 | 638 | if ($chunkend === false) { |
| 639 | - $chunk = substr($buffer,$chunkstart); |
|
| 639 | + $chunk = substr($buffer, $chunkstart); |
|
| 640 | 640 | // append chunk-data to entity-body |
| 641 | 641 | $new .= $chunk; |
| 642 | 642 | $length += strlen($chunk); |
@@ -644,7 +644,7 @@ discard block |
||
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | // read chunk-data and CRLF |
| 647 | - $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
| 647 | + $chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart); |
|
| 648 | 648 | // append chunk-data to entity-body |
| 649 | 649 | $new .= $chunk; |
| 650 | 650 | // length := length + chunk-size |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | if ($chunkend === false) { |
| 657 | 657 | break; //Just in case we got a broken connection |
| 658 | 658 | } |
| 659 | - $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
| 660 | - $chunk_size = hexdec( trim($temp) ); |
|
| 659 | + $temp = substr($buffer, $chunkstart, $chunkend - $chunkstart); |
|
| 660 | + $chunk_size = hexdec(trim($temp)); |
|
| 661 | 661 | $chunkstart = $chunkend; |
| 662 | 662 | } |
| 663 | 663 | return $new; |
@@ -692,15 +692,15 @@ discard block |
||
| 692 | 692 | $this->outgoing_payload = "$req\r\n"; |
| 693 | 693 | |
| 694 | 694 | // loop thru headers, serializing |
| 695 | - foreach($this->outgoing_headers as $k => $v){ |
|
| 696 | - $hdr = $k.': '.$v; |
|
| 695 | + foreach ($this->outgoing_headers as $k => $v) { |
|
| 696 | + $hdr = $k . ': ' . $v; |
|
| 697 | 697 | $this->debug("HTTP header: $hdr"); |
| 698 | 698 | $this->outgoing_payload .= "$hdr\r\n"; |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | 701 | // add any cookies |
| 702 | 702 | if ($cookie_str != '') { |
| 703 | - $hdr = 'Cookie: '.$cookie_str; |
|
| 703 | + $hdr = 'Cookie: ' . $cookie_str; |
|
| 704 | 704 | $this->debug("HTTP header: $hdr"); |
| 705 | 705 | $this->outgoing_payload .= "$hdr\r\n"; |
| 706 | 706 | } |
@@ -729,7 +729,7 @@ discard block |
||
| 729 | 729 | |
| 730 | 730 | if ($this->io_method() == 'socket') { |
| 731 | 731 | // send payload |
| 732 | - if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { |
|
| 732 | + if (!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { |
|
| 733 | 733 | $this->setError('couldn\'t write message data to socket'); |
| 734 | 734 | $this->debug('couldn\'t write message data to socket'); |
| 735 | 735 | return false; |
@@ -742,7 +742,7 @@ discard block |
||
| 742 | 742 | // turns out that the URI and HTTP version are appended to this, which |
| 743 | 743 | // some servers refuse to work with (so we no longer use this method!) |
| 744 | 744 | $curl_headers = array(); |
| 745 | - foreach($this->outgoing_headers as $k => $v){ |
|
| 745 | + foreach ($this->outgoing_headers as $k => $v) { |
|
| 746 | 746 | if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') { |
| 747 | 747 | $this->debug("Skip cURL header $k: $v"); |
| 748 | 748 | } else { |
@@ -776,16 +776,16 @@ discard block |
||
| 776 | 776 | * @return string the response (also sets member variables like incoming_payload) |
| 777 | 777 | * @access private |
| 778 | 778 | */ |
| 779 | - public function getResponse(){ |
|
| 779 | + public function getResponse() { |
|
| 780 | 780 | $this->incoming_payload = ''; |
| 781 | 781 | |
| 782 | 782 | if ($this->io_method() == 'socket') { |
| 783 | 783 | // loop until headers have been retrieved |
| 784 | 784 | $data = ''; |
| 785 | - while (!isset($lb)){ |
|
| 785 | + while (!isset($lb)) { |
|
| 786 | 786 | |
| 787 | 787 | // We might EOF during header read. |
| 788 | - if(feof($this->fp)) { |
|
| 788 | + if (feof($this->fp)) { |
|
| 789 | 789 | $this->incoming_payload = $data; |
| 790 | 790 | $this->debug('found no headers before EOF after length ' . strlen($data)); |
| 791 | 791 | $this->debug("received before EOF:\n" . $data); |
@@ -806,17 +806,17 @@ discard block |
||
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | $data .= $tmp; |
| 809 | - $pos = strpos($data,"\r\n\r\n"); |
|
| 810 | - if($pos > 1){ |
|
| 809 | + $pos = strpos($data, "\r\n\r\n"); |
|
| 810 | + if ($pos > 1) { |
|
| 811 | 811 | $lb = "\r\n"; |
| 812 | 812 | } else { |
| 813 | - $pos = strpos($data,"\n\n"); |
|
| 814 | - if($pos > 1){ |
|
| 813 | + $pos = strpos($data, "\n\n"); |
|
| 814 | + if ($pos > 1) { |
|
| 815 | 815 | $lb = "\n"; |
| 816 | 816 | } |
| 817 | 817 | } |
| 818 | 818 | // remove 100 headers |
| 819 | - if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) { |
|
| 819 | + if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) { |
|
| 820 | 820 | unset($lb); |
| 821 | 821 | $data = ''; |
| 822 | 822 | }// |
@@ -825,13 +825,13 @@ discard block |
||
| 825 | 825 | $this->incoming_payload .= $data; |
| 826 | 826 | $this->debug('found end of headers after length ' . strlen($data)); |
| 827 | 827 | // process headers |
| 828 | - $header_data = trim(substr($data,0,$pos)); |
|
| 829 | - $header_array = explode($lb,$header_data); |
|
| 828 | + $header_data = trim(substr($data, 0, $pos)); |
|
| 829 | + $header_array = explode($lb, $header_data); |
|
| 830 | 830 | $this->incoming_headers = array(); |
| 831 | 831 | $this->incoming_cookies = array(); |
| 832 | - foreach($header_array as $header_line){ |
|
| 833 | - $arr = explode(':',$header_line, 2); |
|
| 834 | - if(count($arr) > 1){ |
|
| 832 | + foreach ($header_array as $header_line) { |
|
| 833 | + $arr = explode(':', $header_line, 2); |
|
| 834 | + if (count($arr) > 1) { |
|
| 835 | 835 | $header_name = strtolower(trim($arr[0])); |
| 836 | 836 | $this->incoming_headers[$header_name] = trim($arr[1]); |
| 837 | 837 | if ($header_name == 'set-cookie') { |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | |
| 852 | 852 | // loop until msg has been received |
| 853 | 853 | if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') { |
| 854 | - $content_length = 2147483647; // ignore any content-length header |
|
| 854 | + $content_length = 2147483647; // ignore any content-length header |
|
| 855 | 855 | $chunked = true; |
| 856 | 856 | $this->debug("want to read chunked content"); |
| 857 | 857 | } elseif (isset($this->incoming_headers['content-length'])) { |
@@ -859,7 +859,7 @@ discard block |
||
| 859 | 859 | $chunked = false; |
| 860 | 860 | $this->debug("want to read content of length $content_length"); |
| 861 | 861 | } else { |
| 862 | - $content_length = 2147483647; |
|
| 862 | + $content_length = 2147483647; |
|
| 863 | 863 | $chunked = false; |
| 864 | 864 | $this->debug("want to read content to EOF"); |
| 865 | 865 | } |
@@ -913,19 +913,19 @@ discard block |
||
| 913 | 913 | } |
| 914 | 914 | $this->debug('read body of length ' . strlen($data)); |
| 915 | 915 | $this->incoming_payload .= $data; |
| 916 | - $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server'); |
|
| 916 | + $this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server'); |
|
| 917 | 917 | |
| 918 | 918 | // close filepointer |
| 919 | - if( |
|
| 919 | + if ( |
|
| 920 | 920 | (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') || |
| 921 | - (! $this->persistentConnection) || feof($this->fp)){ |
|
| 921 | + (!$this->persistentConnection) || feof($this->fp)) { |
|
| 922 | 922 | fclose($this->fp); |
| 923 | 923 | $this->fp = false; |
| 924 | 924 | $this->debug('closed socket'); |
| 925 | 925 | } |
| 926 | 926 | |
| 927 | 927 | // connection was closed unexpectedly |
| 928 | - if($this->incoming_payload == ''){ |
|
| 928 | + if ($this->incoming_payload == '') { |
|
| 929 | 929 | $this->setError('no response from server'); |
| 930 | 930 | return false; |
| 931 | 931 | } |
@@ -949,8 +949,8 @@ discard block |
||
| 949 | 949 | |
| 950 | 950 | $cErr = curl_error($this->ch); |
| 951 | 951 | if ($cErr != '') { |
| 952 | - $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>'; |
|
| 953 | - foreach(curl_getinfo($this->ch) as $k => $v){ |
|
| 952 | + $err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>'; |
|
| 953 | + foreach (curl_getinfo($this->ch) as $k => $v) { |
|
| 954 | 954 | $err .= "$k: $v<br>"; |
| 955 | 955 | } |
| 956 | 956 | $this->debug($err); |
@@ -970,44 +970,44 @@ discard block |
||
| 970 | 970 | $savedata = $data; |
| 971 | 971 | while ($this->isSkippableCurlHeader($data)) { |
| 972 | 972 | $this->debug("Found HTTP header to skip"); |
| 973 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
| 974 | - $data = ltrim(substr($data,$pos)); |
|
| 975 | - } elseif($pos = strpos($data,"\n\n") ) { |
|
| 976 | - $data = ltrim(substr($data,$pos)); |
|
| 973 | + if ($pos = strpos($data, "\r\n\r\n")) { |
|
| 974 | + $data = ltrim(substr($data, $pos)); |
|
| 975 | + } elseif ($pos = strpos($data, "\n\n")) { |
|
| 976 | + $data = ltrim(substr($data, $pos)); |
|
| 977 | 977 | } |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | if ($data == '') { |
| 981 | 981 | // have nothing left; just remove 100 header(s) |
| 982 | 982 | $data = $savedata; |
| 983 | - while (preg_match('/^HTTP\/1.1 100/',$data)) { |
|
| 984 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
| 985 | - $data = ltrim(substr($data,$pos)); |
|
| 986 | - } elseif($pos = strpos($data,"\n\n") ) { |
|
| 987 | - $data = ltrim(substr($data,$pos)); |
|
| 983 | + while (preg_match('/^HTTP\/1.1 100/', $data)) { |
|
| 984 | + if ($pos = strpos($data, "\r\n\r\n")) { |
|
| 985 | + $data = ltrim(substr($data, $pos)); |
|
| 986 | + } elseif ($pos = strpos($data, "\n\n")) { |
|
| 987 | + $data = ltrim(substr($data, $pos)); |
|
| 988 | 988 | } |
| 989 | 989 | } |
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | // separate content from HTTP headers |
| 993 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
| 993 | + if ($pos = strpos($data, "\r\n\r\n")) { |
|
| 994 | 994 | $lb = "\r\n"; |
| 995 | - } elseif( $pos = strpos($data,"\n\n")) { |
|
| 995 | + } elseif ($pos = strpos($data, "\n\n")) { |
|
| 996 | 996 | $lb = "\n"; |
| 997 | 997 | } else { |
| 998 | 998 | $this->debug('no proper separation of headers and document'); |
| 999 | 999 | $this->setError('no proper separation of headers and document'); |
| 1000 | 1000 | return false; |
| 1001 | 1001 | } |
| 1002 | - $header_data = trim(substr($data,0,$pos)); |
|
| 1003 | - $header_array = explode($lb,$header_data); |
|
| 1004 | - $data = ltrim(substr($data,$pos)); |
|
| 1002 | + $header_data = trim(substr($data, 0, $pos)); |
|
| 1003 | + $header_array = explode($lb, $header_data); |
|
| 1004 | + $data = ltrim(substr($data, $pos)); |
|
| 1005 | 1005 | $this->debug('found proper separation of headers and document'); |
| 1006 | - $this->debug('cleaned data, stringlen: '.strlen($data)); |
|
| 1006 | + $this->debug('cleaned data, stringlen: ' . strlen($data)); |
|
| 1007 | 1007 | // clean headers |
| 1008 | 1008 | foreach ($header_array as $header_line) { |
| 1009 | - $arr = explode(':',$header_line,2); |
|
| 1010 | - if(count($arr) > 1){ |
|
| 1009 | + $arr = explode(':', $header_line, 2); |
|
| 1010 | + if (count($arr) > 1) { |
|
| 1011 | 1011 | $header_name = strtolower(trim($arr[0])); |
| 1012 | 1012 | $this->incoming_headers[$header_name] = trim($arr[1]); |
| 1013 | 1013 | if ($header_name == 'set-cookie') { |
@@ -1077,10 +1077,10 @@ discard block |
||
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | // decode content-encoding |
| 1080 | - if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){ |
|
| 1081 | - if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){ |
|
| 1080 | + if (isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != '') { |
|
| 1081 | + if (strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip') { |
|
| 1082 | 1082 | // if decoding works, use it. else assume data wasn't gzencoded |
| 1083 | - if(function_exists('gzinflate')){ |
|
| 1083 | + if (function_exists('gzinflate')) { |
|
| 1084 | 1084 | // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress) |
| 1085 | 1085 | // this means there are no Zlib headers, although there should be |
| 1086 | 1086 | $this->debug('The gzinflate function exists'); |
@@ -1120,7 +1120,7 @@ discard block |
||
| 1120 | 1120 | } |
| 1121 | 1121 | //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; |
| 1122 | 1122 | // set decoded payload |
| 1123 | - $this->incoming_payload = $header_data.$lb.$lb.$data; |
|
| 1123 | + $this->incoming_payload = $header_data . $lb . $lb . $data; |
|
| 1124 | 1124 | } else { |
| 1125 | 1125 | $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
| 1126 | 1126 | $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
@@ -1133,7 +1133,7 @@ discard block |
||
| 1133 | 1133 | $this->debug('No Content-Encoding header'); |
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | - if(strlen($data) == 0){ |
|
| 1136 | + if (strlen($data) == 0) { |
|
| 1137 | 1137 | $this->debug('no data after headers!'); |
| 1138 | 1138 | $this->setError('no data present after HTTP headers'); |
| 1139 | 1139 | return false; |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | * @return boolean whether the request was honored by this method. |
| 1160 | 1160 | * @access public |
| 1161 | 1161 | */ |
| 1162 | - public function usePersistentConnection(){ |
|
| 1162 | + public function usePersistentConnection() { |
|
| 1163 | 1163 | if (isset($this->outgoing_headers['Accept-Encoding'])) { |
| 1164 | 1164 | return false; |
| 1165 | 1165 | } |
@@ -1202,7 +1202,7 @@ discard block |
||
| 1202 | 1202 | |
| 1203 | 1203 | $cookie_param = 'path='; |
| 1204 | 1204 | $start = strpos($cookie_str, $cookie_param); |
| 1205 | - if ( $start > 0 ) { |
|
| 1205 | + if ($start > 0) { |
|
| 1206 | 1206 | $path = substr($cookie_str, $start + strlen($cookie_param)); |
| 1207 | 1207 | $path = substr($path, 0, strpos($path, ';')); |
| 1208 | 1208 | } else { |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | if ($sep_pos) { |
| 1222 | 1222 | $name = substr($value_str, 0, $sep_pos); |
| 1223 | 1223 | $value = substr($value_str, $sep_pos + 1); |
| 1224 | - $cookie= array( 'name' => $name, |
|
| 1224 | + $cookie = array('name' => $name, |
|
| 1225 | 1225 | 'value' => $value, |
| 1226 | 1226 | 'domain' => $domain, |
| 1227 | 1227 | 'path' => $path, |
@@ -1241,35 +1241,35 @@ discard block |
||
| 1241 | 1241 | * @return string for Cookie-HTTP-Header |
| 1242 | 1242 | * @access private |
| 1243 | 1243 | */ |
| 1244 | - public function getCookiesForRequest($cookies, $secure=false) { |
|
| 1244 | + public function getCookiesForRequest($cookies, $secure = false) { |
|
| 1245 | 1245 | $cookie_str = ''; |
| 1246 | - if ((! is_null($cookies)) && (is_array($cookies))) { |
|
| 1246 | + if ((!is_null($cookies)) && (is_array($cookies))) { |
|
| 1247 | 1247 | foreach ($cookies as $cookie) { |
| 1248 | - if (! is_array($cookie)) { |
|
| 1248 | + if (!is_array($cookie)) { |
|
| 1249 | 1249 | continue; |
| 1250 | 1250 | } |
| 1251 | - $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']); |
|
| 1252 | - if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) { |
|
| 1251 | + $this->debug("check cookie for validity: " . $cookie['name'] . '=' . $cookie['value']); |
|
| 1252 | + if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) { |
|
| 1253 | 1253 | if (strtotime($cookie['expires']) <= time()) { |
| 1254 | 1254 | $this->debug('cookie has expired'); |
| 1255 | 1255 | continue; |
| 1256 | 1256 | } |
| 1257 | 1257 | } |
| 1258 | - if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) { |
|
| 1258 | + if ((isset($cookie['domain'])) && (!empty($cookie['domain']))) { |
|
| 1259 | 1259 | $domain = preg_quote($cookie['domain']); |
| 1260 | - if (! preg_match("'.*$domain$'i", $this->host)) { |
|
| 1260 | + if (!preg_match("'.*$domain$'i", $this->host)) { |
|
| 1261 | 1261 | $this->debug('cookie has different domain'); |
| 1262 | 1262 | continue; |
| 1263 | 1263 | } |
| 1264 | 1264 | } |
| 1265 | - if ((isset($cookie['path'])) && (! empty($cookie['path']))) { |
|
| 1265 | + if ((isset($cookie['path'])) && (!empty($cookie['path']))) { |
|
| 1266 | 1266 | $path = preg_quote($cookie['path']); |
| 1267 | - if (! preg_match("'^$path.*'i", $this->path)) { |
|
| 1267 | + if (!preg_match("'^$path.*'i", $this->path)) { |
|
| 1268 | 1268 | $this->debug('cookie is for a different path'); |
| 1269 | 1269 | continue; |
| 1270 | 1270 | } |
| 1271 | 1271 | } |
| 1272 | - if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) { |
|
| 1272 | + if ((!$secure) && (isset($cookie['secure'])) && ($cookie['secure'])) { |
|
| 1273 | 1273 | $this->debug('cookie is secure, transport is not'); |
| 1274 | 1274 | continue; |
| 1275 | 1275 | } |
@@ -104,21 +104,21 @@ discard block |
||
| 104 | 104 | * @access private |
| 105 | 105 | */ |
| 106 | 106 | public $revision = '$Revision: 1.57 $'; |
| 107 | - /** |
|
| 108 | - * Current error string (manipulated by getError/setError) |
|
| 107 | + /** |
|
| 108 | + * Current error string (manipulated by getError/setError) |
|
| 109 | 109 | * |
| 110 | 110 | * @var string |
| 111 | 111 | * @access private |
| 112 | 112 | */ |
| 113 | 113 | public $error_str = ''; |
| 114 | - /** |
|
| 115 | - * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment) |
|
| 114 | + /** |
|
| 115 | + * Current debug string (manipulated by debug/appendDebug/clearDebug/getDebug/getDebugAsXMLComment) |
|
| 116 | 116 | * |
| 117 | 117 | * @var string |
| 118 | 118 | * @access private |
| 119 | 119 | */ |
| 120 | - public $debug_str = ''; |
|
| 121 | - /** |
|
| 120 | + public $debug_str = ''; |
|
| 121 | + /** |
|
| 122 | 122 | * toggles automatic encoding of special characters as entities |
| 123 | 123 | * (should always be true, I think) |
| 124 | 124 | * |
@@ -134,31 +134,31 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public $debugLevel; |
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * set schema version |
|
| 139 | - * |
|
| 140 | - * @var string |
|
| 141 | - * @access public |
|
| 142 | - */ |
|
| 137 | + /** |
|
| 138 | + * set schema version |
|
| 139 | + * |
|
| 140 | + * @var string |
|
| 141 | + * @access public |
|
| 142 | + */ |
|
| 143 | 143 | public $XMLSchemaVersion = 'http://www.w3.org/2001/XMLSchema'; |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * charset encoding for outgoing messages |
|
| 147 | - * |
|
| 148 | - * @var string |
|
| 149 | - * @access public |
|
| 150 | - */ |
|
| 151 | - public $soap_defencoding = 'UTF-8'; |
|
| 145 | + /** |
|
| 146 | + * charset encoding for outgoing messages |
|
| 147 | + * |
|
| 148 | + * @var string |
|
| 149 | + * @access public |
|
| 150 | + */ |
|
| 151 | + public $soap_defencoding = 'UTF-8'; |
|
| 152 | 152 | //var $soap_defencoding = 'UTF-8'; |
| 153 | 153 | |
| 154 | 154 | /** |
| 155 | - * namespaces in an array of prefix => uri |
|
| 156 | - * |
|
| 157 | - * this is "seeded" by a set of constants, but it may be altered by code |
|
| 158 | - * |
|
| 159 | - * @var array |
|
| 160 | - * @access public |
|
| 161 | - */ |
|
| 155 | + * namespaces in an array of prefix => uri |
|
| 156 | + * |
|
| 157 | + * this is "seeded" by a set of constants, but it may be altered by code |
|
| 158 | + * |
|
| 159 | + * @var array |
|
| 160 | + * @access public |
|
| 161 | + */ |
|
| 162 | 162 | public $namespaces = array( |
| 163 | 163 | 'SOAP-ENV' => 'http://schemas.xmlsoap.org/soap/envelope/', |
| 164 | 164 | 'xsd' => 'http://www.w3.org/2001/XMLSchema', |
@@ -167,20 +167,20 @@ discard block |
||
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | - * namespaces used in the current context, e.g. during serialization |
|
| 171 | - * |
|
| 172 | - * @var array |
|
| 173 | - * @access private |
|
| 174 | - */ |
|
| 170 | + * namespaces used in the current context, e.g. during serialization |
|
| 171 | + * |
|
| 172 | + * @var array |
|
| 173 | + * @access private |
|
| 174 | + */ |
|
| 175 | 175 | public $usedNamespaces = array(); |
| 176 | 176 | |
| 177 | 177 | /** |
| 178 | - * XML Schema types in an array of uri => (array of xml type => php type) |
|
| 179 | - * is this legacy yet? |
|
| 180 | - * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings. |
|
| 181 | - * @var array |
|
| 182 | - * @access public |
|
| 183 | - */ |
|
| 178 | + * XML Schema types in an array of uri => (array of xml type => php type) |
|
| 179 | + * is this legacy yet? |
|
| 180 | + * no, this is used by the nusoap_xmlschema class to verify type => namespace mappings. |
|
| 181 | + * @var array |
|
| 182 | + * @access public |
|
| 183 | + */ |
|
| 184 | 184 | public $typemap = array( |
| 185 | 185 | 'http://www.w3.org/2001/XMLSchema' => array( |
| 186 | 186 | 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', |
@@ -203,75 +203,75 @@ discard block |
||
| 203 | 203 | 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
| 204 | 204 | 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), |
| 205 | 205 | 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), |
| 206 | - 'http://xml.apache.org/xml-soap' => array('Map') |
|
| 206 | + 'http://xml.apache.org/xml-soap' => array('Map') |
|
| 207 | 207 | ); |
| 208 | 208 | |
| 209 | 209 | /** |
| 210 | - * XML entities to convert |
|
| 211 | - * |
|
| 212 | - * @var array |
|
| 213 | - * @access public |
|
| 214 | - * @deprecated |
|
| 215 | - * @see expandEntities |
|
| 216 | - */ |
|
| 210 | + * XML entities to convert |
|
| 211 | + * |
|
| 212 | + * @var array |
|
| 213 | + * @access public |
|
| 214 | + * @deprecated |
|
| 215 | + * @see expandEntities |
|
| 216 | + */ |
|
| 217 | 217 | public $xmlEntities = array('quot' => '"','amp' => '&', |
| 218 | 218 | 'lt' => '<','gt' => '>','apos' => "'"); |
| 219 | 219 | |
| 220 | 220 | /** |
| 221 | - * constructor |
|
| 222 | - * |
|
| 223 | - * @access public |
|
| 224 | - */ |
|
| 221 | + * constructor |
|
| 222 | + * |
|
| 223 | + * @access public |
|
| 224 | + */ |
|
| 225 | 225 | public function nusoap_base() { |
| 226 | 226 | $this->debugLevel = $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
| 230 | - * gets the global debug level, which applies to future instances |
|
| 231 | - * |
|
| 232 | - * @return integer Debug level 0-9, where 0 turns off |
|
| 233 | - * @access public |
|
| 234 | - */ |
|
| 230 | + * gets the global debug level, which applies to future instances |
|
| 231 | + * |
|
| 232 | + * @return integer Debug level 0-9, where 0 turns off |
|
| 233 | + * @access public |
|
| 234 | + */ |
|
| 235 | 235 | public function getGlobalDebugLevel() { |
| 236 | 236 | return $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel']; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
| 240 | - * sets the global debug level, which applies to future instances |
|
| 241 | - * |
|
| 242 | - * @param int $level Debug level 0-9, where 0 turns off |
|
| 243 | - * @access public |
|
| 244 | - */ |
|
| 240 | + * sets the global debug level, which applies to future instances |
|
| 241 | + * |
|
| 242 | + * @param int $level Debug level 0-9, where 0 turns off |
|
| 243 | + * @access public |
|
| 244 | + */ |
|
| 245 | 245 | public function setGlobalDebugLevel($level) { |
| 246 | 246 | $GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = $level; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
| 250 | - * gets the debug level for this instance |
|
| 251 | - * |
|
| 252 | - * @return int Debug level 0-9, where 0 turns off |
|
| 253 | - * @access public |
|
| 254 | - */ |
|
| 250 | + * gets the debug level for this instance |
|
| 251 | + * |
|
| 252 | + * @return int Debug level 0-9, where 0 turns off |
|
| 253 | + * @access public |
|
| 254 | + */ |
|
| 255 | 255 | public function getDebugLevel() { |
| 256 | 256 | return $this->debugLevel; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
| 260 | - * sets the debug level for this instance |
|
| 261 | - * |
|
| 262 | - * @param int $level Debug level 0-9, where 0 turns off |
|
| 263 | - * @access public |
|
| 264 | - */ |
|
| 260 | + * sets the debug level for this instance |
|
| 261 | + * |
|
| 262 | + * @param int $level Debug level 0-9, where 0 turns off |
|
| 263 | + * @access public |
|
| 264 | + */ |
|
| 265 | 265 | public function setDebugLevel($level) { |
| 266 | 266 | $this->debugLevel = $level; |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
| 270 | - * adds debug data to the instance debug string with formatting |
|
| 271 | - * |
|
| 272 | - * @param string $string debug data |
|
| 273 | - * @access private |
|
| 274 | - */ |
|
| 270 | + * adds debug data to the instance debug string with formatting |
|
| 271 | + * |
|
| 272 | + * @param string $string debug data |
|
| 273 | + * @access private |
|
| 274 | + */ |
|
| 275 | 275 | public function debug($string){ |
| 276 | 276 | if ($this->debugLevel > 0) { |
| 277 | 277 | $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n"); |
@@ -279,11 +279,11 @@ discard block |
||
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | /** |
| 282 | - * adds debug data to the instance debug string without formatting |
|
| 283 | - * |
|
| 284 | - * @param string $string debug data |
|
| 285 | - * @access public |
|
| 286 | - */ |
|
| 282 | + * adds debug data to the instance debug string without formatting |
|
| 283 | + * |
|
| 284 | + * @param string $string debug data |
|
| 285 | + * @access public |
|
| 286 | + */ |
|
| 287 | 287 | public function appendDebug($string){ |
| 288 | 288 | if ($this->debugLevel > 0) { |
| 289 | 289 | // it would be nice to use a memory stream here to use |
@@ -293,10 +293,10 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
| 296 | - * clears the current debug data for this instance |
|
| 297 | - * |
|
| 298 | - * @access public |
|
| 299 | - */ |
|
| 296 | + * clears the current debug data for this instance |
|
| 297 | + * |
|
| 298 | + * @access public |
|
| 299 | + */ |
|
| 300 | 300 | public function clearDebug() { |
| 301 | 301 | // it would be nice to use a memory stream here to use |
| 302 | 302 | // memory more efficiently |
@@ -304,11 +304,11 @@ discard block |
||
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
| 307 | - * gets the current debug data for this instance |
|
| 308 | - * |
|
| 309 | - * @return debug data |
|
| 310 | - * @access public |
|
| 311 | - */ |
|
| 307 | + * gets the current debug data for this instance |
|
| 308 | + * |
|
| 309 | + * @return debug data |
|
| 310 | + * @access public |
|
| 311 | + */ |
|
| 312 | 312 | public function &getDebug() { |
| 313 | 313 | // it would be nice to use a memory stream here to use |
| 314 | 314 | // memory more efficiently |
@@ -316,12 +316,12 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
| 319 | - * gets the current debug data for this instance as an XML comment |
|
| 320 | - * this may change the contents of the debug data |
|
| 321 | - * |
|
| 322 | - * @return debug data as an XML comment |
|
| 323 | - * @access public |
|
| 324 | - */ |
|
| 319 | + * gets the current debug data for this instance as an XML comment |
|
| 320 | + * this may change the contents of the debug data |
|
| 321 | + * |
|
| 322 | + * @return debug data as an XML comment |
|
| 323 | + * @access public |
|
| 324 | + */ |
|
| 325 | 325 | public function &getDebugAsXMLComment() { |
| 326 | 326 | // it would be nice to use a memory stream here to use |
| 327 | 327 | // memory more efficiently |
@@ -329,32 +329,32 @@ discard block |
||
| 329 | 329 | $this->debug_str = str_replace('--', '- -', $this->debug_str); |
| 330 | 330 | } |
| 331 | 331 | $ret = "<!--\n" . $this->debug_str . "\n-->"; |
| 332 | - return $ret; |
|
| 332 | + return $ret; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
| 336 | - * expands entities, e.g. changes '<' to '<'. |
|
| 337 | - * |
|
| 338 | - * @param string $val The string in which to expand entities. |
|
| 339 | - * @access private |
|
| 340 | - */ |
|
| 336 | + * expands entities, e.g. changes '<' to '<'. |
|
| 337 | + * |
|
| 338 | + * @param string $val The string in which to expand entities. |
|
| 339 | + * @access private |
|
| 340 | + */ |
|
| 341 | 341 | public function expandEntities($val) { |
| 342 | 342 | if ($this->charencoding) { |
| 343 | - $val = str_replace('&', '&', $val); |
|
| 344 | - $val = str_replace("'", ''', $val); |
|
| 345 | - $val = str_replace('"', '"', $val); |
|
| 346 | - $val = str_replace('<', '<', $val); |
|
| 347 | - $val = str_replace('>', '>', $val); |
|
| 348 | - } |
|
| 349 | - return $val; |
|
| 343 | + $val = str_replace('&', '&', $val); |
|
| 344 | + $val = str_replace("'", ''', $val); |
|
| 345 | + $val = str_replace('"', '"', $val); |
|
| 346 | + $val = str_replace('<', '<', $val); |
|
| 347 | + $val = str_replace('>', '>', $val); |
|
| 348 | + } |
|
| 349 | + return $val; |
|
| 350 | 350 | } |
| 351 | 351 | |
| 352 | 352 | /** |
| 353 | - * returns error string if present |
|
| 354 | - * |
|
| 355 | - * @return mixed error string or false |
|
| 356 | - * @access public |
|
| 357 | - */ |
|
| 353 | + * returns error string if present |
|
| 354 | + * |
|
| 355 | + * @return mixed error string or false |
|
| 356 | + * @access public |
|
| 357 | + */ |
|
| 358 | 358 | public function getError(){ |
| 359 | 359 | if($this->error_str != ''){ |
| 360 | 360 | return $this->error_str; |
@@ -363,24 +363,24 @@ discard block |
||
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
| 366 | - * sets error string |
|
| 367 | - * |
|
| 368 | - * @return boolean $string error string |
|
| 369 | - * @access private |
|
| 370 | - */ |
|
| 366 | + * sets error string |
|
| 367 | + * |
|
| 368 | + * @return boolean $string error string |
|
| 369 | + * @access private |
|
| 370 | + */ |
|
| 371 | 371 | public function setError($str){ |
| 372 | 372 | $this->error_str = $str; |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
| 376 | - * detect if array is a simple array or a struct (associative array) |
|
| 377 | - * |
|
| 378 | - * @param mixed $val The PHP array |
|
| 379 | - * @return string (arraySimple|arrayStruct) |
|
| 380 | - * @access private |
|
| 381 | - */ |
|
| 376 | + * detect if array is a simple array or a struct (associative array) |
|
| 377 | + * |
|
| 378 | + * @param mixed $val The PHP array |
|
| 379 | + * @return string (arraySimple|arrayStruct) |
|
| 380 | + * @access private |
|
| 381 | + */ |
|
| 382 | 382 | public function isArraySimpleOrStruct($val) { |
| 383 | - $keyList = array_keys($val); |
|
| 383 | + $keyList = array_keys($val); |
|
| 384 | 384 | foreach ($keyList as $keyListValue) { |
| 385 | 385 | if (!is_int($keyListValue)) { |
| 386 | 386 | return 'arrayStruct'; |
@@ -390,33 +390,33 @@ discard block |
||
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
| 393 | - * serializes PHP values in accordance w/ section 5. Type information is |
|
| 394 | - * not serialized if $use == 'literal'. |
|
| 395 | - * |
|
| 396 | - * @param mixed $val The value to serialize |
|
| 397 | - * @param string $name The name (local part) of the XML element |
|
| 398 | - * @param string $type The XML schema type (local part) for the element |
|
| 399 | - * @param string $name_ns The namespace for the name of the XML element |
|
| 400 | - * @param string $type_ns The namespace for the type of the element |
|
| 401 | - * @param array $attributes The attributes to serialize as name=>value pairs |
|
| 402 | - * @param string $use The WSDL "use" (encoded|literal) |
|
| 403 | - * @param boolean $soapval Whether this is called from soapval. |
|
| 404 | - * @return string The serialized element, possibly with child elements |
|
| 405 | - * @access public |
|
| 406 | - */ |
|
| 393 | + * serializes PHP values in accordance w/ section 5. Type information is |
|
| 394 | + * not serialized if $use == 'literal'. |
|
| 395 | + * |
|
| 396 | + * @param mixed $val The value to serialize |
|
| 397 | + * @param string $name The name (local part) of the XML element |
|
| 398 | + * @param string $type The XML schema type (local part) for the element |
|
| 399 | + * @param string $name_ns The namespace for the name of the XML element |
|
| 400 | + * @param string $type_ns The namespace for the type of the element |
|
| 401 | + * @param array $attributes The attributes to serialize as name=>value pairs |
|
| 402 | + * @param string $use The WSDL "use" (encoded|literal) |
|
| 403 | + * @param boolean $soapval Whether this is called from soapval. |
|
| 404 | + * @return string The serialized element, possibly with child elements |
|
| 405 | + * @access public |
|
| 406 | + */ |
|
| 407 | 407 | public function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) { |
| 408 | 408 | $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval"); |
| 409 | 409 | $this->appendDebug('value=' . $this->varDump($val)); |
| 410 | 410 | $this->appendDebug('attributes=' . $this->varDump($attributes)); |
| 411 | 411 | |
| 412 | - if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
| 413 | - $this->debug("serialize_val: serialize soapval"); |
|
| 414 | - $xml = $val->serialize($use); |
|
| 412 | + if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
| 413 | + $this->debug("serialize_val: serialize soapval"); |
|
| 414 | + $xml = $val->serialize($use); |
|
| 415 | 415 | $this->appendDebug($val->getDebug()); |
| 416 | 416 | $val->clearDebug(); |
| 417 | 417 | $this->debug("serialize_val of soapval returning $xml"); |
| 418 | 418 | return $xml; |
| 419 | - } |
|
| 419 | + } |
|
| 420 | 420 | // force valid name if necessary |
| 421 | 421 | if (is_numeric($name)) { |
| 422 | 422 | $name = '__numeric_' . $name; |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | } |
| 426 | 426 | // if name has ns, add ns prefix to name |
| 427 | 427 | $xmlns = ''; |
| 428 | - if($name_ns){ |
|
| 428 | + if($name_ns){ |
|
| 429 | 429 | $prefix = 'nu'.rand(1000,9999); |
| 430 | 430 | $name = $prefix.':'.$name; |
| 431 | 431 | $xmlns .= " xmlns:$prefix=\"$name_ns\""; |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | // if type is prefixed, create type prefix |
| 434 | 434 | if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ |
| 435 | 435 | // need to fix this. shouldn't default to xsd if no ns specified |
| 436 | - // w/o checking against typemap |
|
| 436 | + // w/o checking against typemap |
|
| 437 | 437 | $type_prefix = 'xsd'; |
| 438 | 438 | } elseif($type_ns){ |
| 439 | 439 | $type_prefix = 'ns'.rand(1000,9999); |
@@ -448,12 +448,12 @@ discard block |
||
| 448 | 448 | } |
| 449 | 449 | // serialize null value |
| 450 | 450 | if (is_null($val)) { |
| 451 | - $this->debug("serialize_val: serialize null"); |
|
| 451 | + $this->debug("serialize_val: serialize null"); |
|
| 452 | 452 | if ($use == 'literal') { |
| 453 | 453 | $xml = "<$name$xmlns$atts/>"; |
| 454 | 454 | $this->debug("serialize_val returning $xml"); |
| 455 | - return $xml; |
|
| 456 | - } else { |
|
| 455 | + return $xml; |
|
| 456 | + } else { |
|
| 457 | 457 | if (isset($type) && isset($type_prefix)) { |
| 458 | 458 | $type_str = " xsi:type=\"$type_prefix:$type\""; |
| 459 | 459 | } else { |
@@ -461,41 +461,41 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | $xml = "<$name$xmlns$type_str$atts xsi:nil=\"true\"/>"; |
| 463 | 463 | $this->debug("serialize_val returning $xml"); |
| 464 | - return $xml; |
|
| 465 | - } |
|
| 464 | + return $xml; |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | - // serialize if an xsd built-in primitive type |
|
| 468 | - if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){ |
|
| 469 | - $this->debug("serialize_val: serialize xsd built-in primitive type"); |
|
| 470 | - if (is_bool($val)) { |
|
| 471 | - if ($type == 'boolean') { |
|
| 472 | - $val = $val ? 'true' : 'false'; |
|
| 473 | - } elseif (! $val) { |
|
| 474 | - $val = 0; |
|
| 475 | - } |
|
| 467 | + // serialize if an xsd built-in primitive type |
|
| 468 | + if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){ |
|
| 469 | + $this->debug("serialize_val: serialize xsd built-in primitive type"); |
|
| 470 | + if (is_bool($val)) { |
|
| 471 | + if ($type == 'boolean') { |
|
| 472 | + $val = $val ? 'true' : 'false'; |
|
| 473 | + } elseif (! $val) { |
|
| 474 | + $val = 0; |
|
| 475 | + } |
|
| 476 | 476 | } else if (is_string($val)) { |
| 477 | 477 | $val = $this->expandEntities($val); |
| 478 | 478 | } |
| 479 | 479 | if ($use == 'literal') { |
| 480 | 480 | $xml = "<$name$xmlns$atts>$val</$name>"; |
| 481 | 481 | $this->debug("serialize_val returning $xml"); |
| 482 | - return $xml; |
|
| 483 | - } else { |
|
| 482 | + return $xml; |
|
| 483 | + } else { |
|
| 484 | 484 | $xml = "<$name$xmlns xsi:type=\"xsd:$type\"$atts>$val</$name>"; |
| 485 | 485 | $this->debug("serialize_val returning $xml"); |
| 486 | - return $xml; |
|
| 487 | - } |
|
| 488 | - } |
|
| 486 | + return $xml; |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | 489 | // detect type and serialize |
| 490 | 490 | $xml = ''; |
| 491 | 491 | switch(true) { |
| 492 | 492 | case (is_bool($val) || $type == 'boolean'): |
| 493 | 493 | $this->debug("serialize_val: serialize boolean"); |
| 494 | - if ($type == 'boolean') { |
|
| 495 | - $val = $val ? 'true' : 'false'; |
|
| 496 | - } elseif (! $val) { |
|
| 497 | - $val = 0; |
|
| 498 | - } |
|
| 494 | + if ($type == 'boolean') { |
|
| 495 | + $val = $val ? 'true' : 'false'; |
|
| 496 | + } elseif (! $val) { |
|
| 497 | + $val = 0; |
|
| 498 | + } |
|
| 499 | 499 | if ($use == 'literal') { |
| 500 | 500 | $xml .= "<$name$xmlns$atts>$val</$name>"; |
| 501 | 501 | } else { |
@@ -529,12 +529,12 @@ discard block |
||
| 529 | 529 | break; |
| 530 | 530 | case is_object($val): |
| 531 | 531 | $this->debug("serialize_val: serialize object"); |
| 532 | - if (get_class($val) == 'soapval') { |
|
| 533 | - $this->debug("serialize_val: serialize soapval object"); |
|
| 534 | - $pXml = $val->serialize($use); |
|
| 532 | + if (get_class($val) == 'soapval') { |
|
| 533 | + $this->debug("serialize_val: serialize soapval object"); |
|
| 534 | + $pXml = $val->serialize($use); |
|
| 535 | 535 | $this->appendDebug($val->getDebug()); |
| 536 | 536 | $val->clearDebug(); |
| 537 | - } else { |
|
| 537 | + } else { |
|
| 538 | 538 | if (! $name) { |
| 539 | 539 | $name = get_class($val); |
| 540 | 540 | $this->debug("In serialize_val, used class name $name as element name"); |
@@ -560,19 +560,19 @@ discard block |
||
| 560 | 560 | case (is_array($val) || $type): |
| 561 | 561 | // detect if struct or array |
| 562 | 562 | $valueType = $this->isArraySimpleOrStruct($val); |
| 563 | - if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){ |
|
| 563 | + if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){ |
|
| 564 | 564 | $this->debug("serialize_val: serialize array"); |
| 565 | 565 | $i = 0; |
| 566 | 566 | if(is_array($val) && count($val)> 0){ |
| 567 | 567 | foreach($val as $v){ |
| 568 | - if(is_object($v) && get_class($v) == 'soapval'){ |
|
| 568 | + if(is_object($v) && get_class($v) == 'soapval'){ |
|
| 569 | 569 | $tt_ns = $v->type_ns; |
| 570 | 570 | $tt = $v->type; |
| 571 | 571 | } elseif (is_array($v)) { |
| 572 | 572 | $tt = $this->isArraySimpleOrStruct($v); |
| 573 | 573 | } else { |
| 574 | 574 | $tt = gettype($v); |
| 575 | - } |
|
| 575 | + } |
|
| 576 | 576 | $array_types[$tt] = 1; |
| 577 | 577 | $xml .= $this->serialize_val($v,'item',false,false,false,false,$use); |
| 578 | 578 | ++$i; |
@@ -655,19 +655,19 @@ discard block |
||
| 655 | 655 | return $xml; |
| 656 | 656 | } |
| 657 | 657 | |
| 658 | - /** |
|
| 659 | - * serializes a message |
|
| 660 | - * |
|
| 661 | - * @param string $body the XML of the SOAP body |
|
| 662 | - * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array |
|
| 663 | - * @param array $namespaces optional the namespaces used in generating the body and headers |
|
| 664 | - * @param string $style optional (rpc|document) |
|
| 665 | - * @param string $use optional (encoded|literal) |
|
| 666 | - * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
| 667 | - * @return string the message |
|
| 668 | - * @access public |
|
| 669 | - */ |
|
| 670 | - public function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){ |
|
| 658 | + /** |
|
| 659 | + * serializes a message |
|
| 660 | + * |
|
| 661 | + * @param string $body the XML of the SOAP body |
|
| 662 | + * @param mixed $headers optional string of XML with SOAP header content, or array of soapval objects for SOAP headers, or associative array |
|
| 663 | + * @param array $namespaces optional the namespaces used in generating the body and headers |
|
| 664 | + * @param string $style optional (rpc|document) |
|
| 665 | + * @param string $use optional (encoded|literal) |
|
| 666 | + * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
| 667 | + * @return string the message |
|
| 668 | + * @access public |
|
| 669 | + */ |
|
| 670 | + public function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){ |
|
| 671 | 671 | |
| 672 | 672 | $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle"); |
| 673 | 673 | $this->debug("headers:"); |
@@ -676,7 +676,7 @@ discard block |
||
| 676 | 676 | $this->appendDebug($this->varDump($namespaces)); |
| 677 | 677 | |
| 678 | 678 | // serialize namespaces |
| 679 | - $ns_string = ''; |
|
| 679 | + $ns_string = ''; |
|
| 680 | 680 | foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ |
| 681 | 681 | $ns_string .= " xmlns:$k=\"$v\""; |
| 682 | 682 | } |
@@ -709,7 +709,7 @@ discard block |
||
| 709 | 709 | $body. |
| 710 | 710 | "</SOAP-ENV:Body>". |
| 711 | 711 | "</SOAP-ENV:Envelope>"; |
| 712 | - } |
|
| 712 | + } |
|
| 713 | 713 | |
| 714 | 714 | /** |
| 715 | 715 | * formats a string to be inserted into an HTML stream |
@@ -719,18 +719,18 @@ discard block |
||
| 719 | 719 | * @access public |
| 720 | 720 | * @deprecated |
| 721 | 721 | */ |
| 722 | - public function formatDump($str){ |
|
| 722 | + public function formatDump($str){ |
|
| 723 | 723 | $str = htmlspecialchars($str); |
| 724 | 724 | return nl2br($str); |
| 725 | - } |
|
| 725 | + } |
|
| 726 | 726 | |
| 727 | 727 | /** |
| 728 | - * contracts (changes namespace to prefix) a qualified name |
|
| 729 | - * |
|
| 730 | - * @param string $qname qname |
|
| 731 | - * @return string contracted qname |
|
| 732 | - * @access private |
|
| 733 | - */ |
|
| 728 | + * contracts (changes namespace to prefix) a qualified name |
|
| 729 | + * |
|
| 730 | + * @param string $qname qname |
|
| 731 | + * @return string contracted qname |
|
| 732 | + * @access private |
|
| 733 | + */ |
|
| 734 | 734 | public function contractQname($qname){ |
| 735 | 735 | // get element namespace |
| 736 | 736 | if (strrpos($qname, ':')) { |
@@ -749,12 +749,12 @@ discard block |
||
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
| 752 | - * expands (changes prefix to namespace) a qualified name |
|
| 753 | - * |
|
| 754 | - * @param string $qname qname |
|
| 755 | - * @return string expanded qname |
|
| 756 | - * @access private |
|
| 757 | - */ |
|
| 752 | + * expands (changes prefix to namespace) a qualified name |
|
| 753 | + * |
|
| 754 | + * @param string $qname qname |
|
| 755 | + * @return string expanded qname |
|
| 756 | + * @access private |
|
| 757 | + */ |
|
| 758 | 758 | public function expandQname($qname){ |
| 759 | 759 | // get element prefix |
| 760 | 760 | if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ |
@@ -772,14 +772,14 @@ discard block |
||
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | - /** |
|
| 776 | - * returns the local part of a prefixed string |
|
| 777 | - * returns the original string, if not prefixed |
|
| 778 | - * |
|
| 779 | - * @param string $str The prefixed string |
|
| 780 | - * @return string The local part |
|
| 781 | - * @access public |
|
| 782 | - */ |
|
| 775 | + /** |
|
| 776 | + * returns the local part of a prefixed string |
|
| 777 | + * returns the original string, if not prefixed |
|
| 778 | + * |
|
| 779 | + * @param string $str The prefixed string |
|
| 780 | + * @return string The local part |
|
| 781 | + * @access public |
|
| 782 | + */ |
|
| 783 | 783 | public function getLocalPart($str){ |
| 784 | 784 | if($sstr = strrchr($str,':')){ |
| 785 | 785 | // get unqualified name |
@@ -790,13 +790,13 @@ discard block |
||
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
| 793 | - * returns the prefix part of a prefixed string |
|
| 794 | - * returns false, if not prefixed |
|
| 795 | - * |
|
| 796 | - * @param string $str The prefixed string |
|
| 797 | - * @return mixed The prefix or false if there is no prefix |
|
| 798 | - * @access public |
|
| 799 | - */ |
|
| 793 | + * returns the prefix part of a prefixed string |
|
| 794 | + * returns false, if not prefixed |
|
| 795 | + * |
|
| 796 | + * @param string $str The prefixed string |
|
| 797 | + * @return mixed The prefix or false if there is no prefix |
|
| 798 | + * @access public |
|
| 799 | + */ |
|
| 800 | 800 | public function getPrefix($str){ |
| 801 | 801 | if($pos = strrpos($str,':')){ |
| 802 | 802 | // get prefix |
@@ -806,12 +806,12 @@ discard block |
||
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | /** |
| 809 | - * pass it a prefix, it returns a namespace |
|
| 810 | - * |
|
| 811 | - * @param string $prefix The prefix |
|
| 812 | - * @return mixed The namespace, false if no namespace has the specified prefix |
|
| 813 | - * @access public |
|
| 814 | - */ |
|
| 809 | + * pass it a prefix, it returns a namespace |
|
| 810 | + * |
|
| 811 | + * @param string $prefix The prefix |
|
| 812 | + * @return mixed The namespace, false if no namespace has the specified prefix |
|
| 813 | + * @access public |
|
| 814 | + */ |
|
| 815 | 815 | public function getNamespaceFromPrefix($prefix){ |
| 816 | 816 | if (isset($this->namespaces[$prefix])) { |
| 817 | 817 | return $this->namespaces[$prefix]; |
@@ -820,17 +820,17 @@ discard block |
||
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
| 823 | - * returns the prefix for a given namespace (or prefix) |
|
| 824 | - * or false if no prefixes registered for the given namespace |
|
| 825 | - * |
|
| 826 | - * @param string $ns The namespace |
|
| 827 | - * @return mixed The prefix, false if the namespace has no prefixes |
|
| 828 | - * @access public |
|
| 829 | - */ |
|
| 823 | + * returns the prefix for a given namespace (or prefix) |
|
| 824 | + * or false if no prefixes registered for the given namespace |
|
| 825 | + * |
|
| 826 | + * @param string $ns The namespace |
|
| 827 | + * @return mixed The prefix, false if the namespace has no prefixes |
|
| 828 | + * @access public |
|
| 829 | + */ |
|
| 830 | 830 | public function getPrefixFromNamespace($ns) { |
| 831 | 831 | foreach ($this->namespaces as $p => $n) { |
| 832 | 832 | if ($ns == $n || $ns == $p) { |
| 833 | - $this->usedNamespaces[$p] = $n; |
|
| 833 | + $this->usedNamespaces[$p] = $n; |
|
| 834 | 834 | return $p; |
| 835 | 835 | } |
| 836 | 836 | } |
@@ -838,11 +838,11 @@ discard block |
||
| 838 | 838 | } |
| 839 | 839 | |
| 840 | 840 | /** |
| 841 | - * returns the time in ODBC canonical form with microseconds |
|
| 842 | - * |
|
| 843 | - * @return string The time in ODBC canonical form with microseconds |
|
| 844 | - * @access public |
|
| 845 | - */ |
|
| 841 | + * returns the time in ODBC canonical form with microseconds |
|
| 842 | + * |
|
| 843 | + * @return string The time in ODBC canonical form with microseconds |
|
| 844 | + * @access public |
|
| 845 | + */ |
|
| 846 | 846 | public function getmicrotime() { |
| 847 | 847 | if (function_exists('gettimeofday')) { |
| 848 | 848 | $tod = gettimeofday(); |
@@ -862,17 +862,17 @@ discard block |
||
| 862 | 862 | * @return string The output of var_dump |
| 863 | 863 | * @access public |
| 864 | 864 | */ |
| 865 | - public function varDump($data) { |
|
| 865 | + public function varDump($data) { |
|
| 866 | 866 | $ret_val = var_export($data, true); |
| 867 | 867 | return $ret_val; |
| 868 | 868 | } |
| 869 | 869 | |
| 870 | 870 | /** |
| 871 | - * represents the object as a string |
|
| 872 | - * |
|
| 873 | - * @return string |
|
| 874 | - * @access public |
|
| 875 | - */ |
|
| 871 | + * represents the object as a string |
|
| 872 | + * |
|
| 873 | + * @return string |
|
| 874 | + * @access public |
|
| 875 | + */ |
|
| 876 | 876 | public function __toString() { |
| 877 | 877 | return $this->varDump($this); |
| 878 | 878 | } |
@@ -183,26 +183,26 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public $typemap = array( |
| 185 | 185 | 'http://www.w3.org/2001/XMLSchema' => array( |
| 186 | - 'string'=>'string','boolean'=>'boolean','float'=>'double','double'=>'double','decimal'=>'double', |
|
| 187 | - 'duration'=>'','dateTime'=>'string','time'=>'string','date'=>'string','gYearMonth'=>'', |
|
| 188 | - 'gYear'=>'','gMonthDay'=>'','gDay'=>'','gMonth'=>'','hexBinary'=>'string','base64Binary'=>'string', |
|
| 186 | + 'string'=>'string', 'boolean'=>'boolean', 'float'=>'double', 'double'=>'double', 'decimal'=>'double', |
|
| 187 | + 'duration'=>'', 'dateTime'=>'string', 'time'=>'string', 'date'=>'string', 'gYearMonth'=>'', |
|
| 188 | + 'gYear'=>'', 'gMonthDay'=>'', 'gDay'=>'', 'gMonth'=>'', 'hexBinary'=>'string', 'base64Binary'=>'string', |
|
| 189 | 189 | // abstract "any" types |
| 190 | - 'anyType'=>'string','anySimpleType'=>'string', |
|
| 190 | + 'anyType'=>'string', 'anySimpleType'=>'string', |
|
| 191 | 191 | // derived datatypes |
| 192 | - 'normalizedString'=>'string','token'=>'string','language'=>'','NMTOKEN'=>'','NMTOKENS'=>'','Name'=>'','NCName'=>'','ID'=>'', |
|
| 193 | - 'IDREF'=>'','IDREFS'=>'','ENTITY'=>'','ENTITIES'=>'','integer'=>'integer','nonPositiveInteger'=>'integer', |
|
| 194 | - 'negativeInteger'=>'integer','long'=>'integer','int'=>'integer','short'=>'integer','byte'=>'integer','nonNegativeInteger'=>'integer', |
|
| 195 | - 'unsignedLong'=>'','unsignedInt'=>'','unsignedShort'=>'','unsignedByte'=>'','positiveInteger'=>''), |
|
| 192 | + 'normalizedString'=>'string', 'token'=>'string', 'language'=>'', 'NMTOKEN'=>'', 'NMTOKENS'=>'', 'Name'=>'', 'NCName'=>'', 'ID'=>'', |
|
| 193 | + 'IDREF'=>'', 'IDREFS'=>'', 'ENTITY'=>'', 'ENTITIES'=>'', 'integer'=>'integer', 'nonPositiveInteger'=>'integer', |
|
| 194 | + 'negativeInteger'=>'integer', 'long'=>'integer', 'int'=>'integer', 'short'=>'integer', 'byte'=>'integer', 'nonNegativeInteger'=>'integer', |
|
| 195 | + 'unsignedLong'=>'', 'unsignedInt'=>'', 'unsignedShort'=>'', 'unsignedByte'=>'', 'positiveInteger'=>''), |
|
| 196 | 196 | 'http://www.w3.org/2000/10/XMLSchema' => array( |
| 197 | - 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
| 198 | - 'float'=>'double','dateTime'=>'string', |
|
| 199 | - 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
| 197 | + 'i4'=>'', 'int'=>'integer', 'boolean'=>'boolean', 'string'=>'string', 'double'=>'double', |
|
| 198 | + 'float'=>'double', 'dateTime'=>'string', |
|
| 199 | + 'timeInstant'=>'string', 'base64Binary'=>'string', 'base64'=>'string', 'ur-type'=>'array'), |
|
| 200 | 200 | 'http://www.w3.org/1999/XMLSchema' => array( |
| 201 | - 'i4'=>'','int'=>'integer','boolean'=>'boolean','string'=>'string','double'=>'double', |
|
| 202 | - 'float'=>'double','dateTime'=>'string', |
|
| 203 | - 'timeInstant'=>'string','base64Binary'=>'string','base64'=>'string','ur-type'=>'array'), |
|
| 201 | + 'i4'=>'', 'int'=>'integer', 'boolean'=>'boolean', 'string'=>'string', 'double'=>'double', |
|
| 202 | + 'float'=>'double', 'dateTime'=>'string', |
|
| 203 | + 'timeInstant'=>'string', 'base64Binary'=>'string', 'base64'=>'string', 'ur-type'=>'array'), |
|
| 204 | 204 | 'http://soapinterop.org/xsd' => array('SOAPStruct'=>'struct'), |
| 205 | - 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string','array'=>'array','Array'=>'array'), |
|
| 205 | + 'http://schemas.xmlsoap.org/soap/encoding/' => array('base64'=>'string', 'array'=>'array', 'Array'=>'array'), |
|
| 206 | 206 | 'http://xml.apache.org/xml-soap' => array('Map') |
| 207 | 207 | ); |
| 208 | 208 | |
@@ -214,8 +214,8 @@ discard block |
||
| 214 | 214 | * @deprecated |
| 215 | 215 | * @see expandEntities |
| 216 | 216 | */ |
| 217 | - public $xmlEntities = array('quot' => '"','amp' => '&', |
|
| 218 | - 'lt' => '<','gt' => '>','apos' => "'"); |
|
| 217 | + public $xmlEntities = array('quot' => '"', 'amp' => '&', |
|
| 218 | + 'lt' => '<', 'gt' => '>', 'apos' => "'"); |
|
| 219 | 219 | |
| 220 | 220 | /** |
| 221 | 221 | * constructor |
@@ -272,9 +272,9 @@ discard block |
||
| 272 | 272 | * @param string $string debug data |
| 273 | 273 | * @access private |
| 274 | 274 | */ |
| 275 | - public function debug($string){ |
|
| 275 | + public function debug($string) { |
|
| 276 | 276 | if ($this->debugLevel > 0) { |
| 277 | - $this->appendDebug($this->getmicrotime().' '.get_class($this).": $string\n"); |
|
| 277 | + $this->appendDebug($this->getmicrotime() . ' ' . get_class($this) . ": $string\n"); |
|
| 278 | 278 | } |
| 279 | 279 | } |
| 280 | 280 | |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * @param string $string debug data |
| 285 | 285 | * @access public |
| 286 | 286 | */ |
| 287 | - public function appendDebug($string){ |
|
| 287 | + public function appendDebug($string) { |
|
| 288 | 288 | if ($this->debugLevel > 0) { |
| 289 | 289 | // it would be nice to use a memory stream here to use |
| 290 | 290 | // memory more efficiently |
@@ -355,8 +355,8 @@ discard block |
||
| 355 | 355 | * @return mixed error string or false |
| 356 | 356 | * @access public |
| 357 | 357 | */ |
| 358 | - public function getError(){ |
|
| 359 | - if($this->error_str != ''){ |
|
| 358 | + public function getError() { |
|
| 359 | + if ($this->error_str != '') { |
|
| 360 | 360 | return $this->error_str; |
| 361 | 361 | } |
| 362 | 362 | return false; |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * @return boolean $string error string |
| 369 | 369 | * @access private |
| 370 | 370 | */ |
| 371 | - public function setError($str){ |
|
| 371 | + public function setError($str) { |
|
| 372 | 372 | $this->error_str = $str; |
| 373 | 373 | } |
| 374 | 374 | |
@@ -404,12 +404,12 @@ discard block |
||
| 404 | 404 | * @return string The serialized element, possibly with child elements |
| 405 | 405 | * @access public |
| 406 | 406 | */ |
| 407 | - public function serialize_val($val,$name=false,$type=false,$name_ns=false,$type_ns=false,$attributes=false,$use='encoded',$soapval=false) { |
|
| 407 | + public function serialize_val($val, $name = false, $type = false, $name_ns = false, $type_ns = false, $attributes = false, $use = 'encoded', $soapval = false) { |
|
| 408 | 408 | $this->debug("in serialize_val: name=$name, type=$type, name_ns=$name_ns, type_ns=$type_ns, use=$use, soapval=$soapval"); |
| 409 | 409 | $this->appendDebug('value=' . $this->varDump($val)); |
| 410 | 410 | $this->appendDebug('attributes=' . $this->varDump($attributes)); |
| 411 | 411 | |
| 412 | - if (is_object($val) && get_class($val) == 'soapval' && (! $soapval)) { |
|
| 412 | + if (is_object($val) && get_class($val) == 'soapval' && (!$soapval)) { |
|
| 413 | 413 | $this->debug("serialize_val: serialize soapval"); |
| 414 | 414 | $xml = $val->serialize($use); |
| 415 | 415 | $this->appendDebug($val->getDebug()); |
@@ -420,30 +420,30 @@ discard block |
||
| 420 | 420 | // force valid name if necessary |
| 421 | 421 | if (is_numeric($name)) { |
| 422 | 422 | $name = '__numeric_' . $name; |
| 423 | - } elseif (! $name) { |
|
| 423 | + } elseif (!$name) { |
|
| 424 | 424 | $name = 'noname'; |
| 425 | 425 | } |
| 426 | 426 | // if name has ns, add ns prefix to name |
| 427 | 427 | $xmlns = ''; |
| 428 | - if($name_ns){ |
|
| 429 | - $prefix = 'nu'.rand(1000,9999); |
|
| 430 | - $name = $prefix.':'.$name; |
|
| 428 | + if ($name_ns) { |
|
| 429 | + $prefix = 'nu' . rand(1000, 9999); |
|
| 430 | + $name = $prefix . ':' . $name; |
|
| 431 | 431 | $xmlns .= " xmlns:$prefix=\"$name_ns\""; |
| 432 | 432 | } |
| 433 | 433 | // if type is prefixed, create type prefix |
| 434 | - if($type_ns != '' && $type_ns == $this->namespaces['xsd']){ |
|
| 434 | + if ($type_ns != '' && $type_ns == $this->namespaces['xsd']) { |
|
| 435 | 435 | // need to fix this. shouldn't default to xsd if no ns specified |
| 436 | 436 | // w/o checking against typemap |
| 437 | 437 | $type_prefix = 'xsd'; |
| 438 | - } elseif($type_ns){ |
|
| 439 | - $type_prefix = 'ns'.rand(1000,9999); |
|
| 438 | + } elseif ($type_ns) { |
|
| 439 | + $type_prefix = 'ns' . rand(1000, 9999); |
|
| 440 | 440 | $xmlns .= " xmlns:$type_prefix=\"$type_ns\""; |
| 441 | 441 | } |
| 442 | 442 | // serialize attributes if present |
| 443 | 443 | $atts = ''; |
| 444 | - if($attributes){ |
|
| 445 | - foreach($attributes as $k => $v){ |
|
| 446 | - $atts .= " $k=\"".$this->expandEntities($v).'"'; |
|
| 444 | + if ($attributes) { |
|
| 445 | + foreach ($attributes as $k => $v) { |
|
| 446 | + $atts .= " $k=\"" . $this->expandEntities($v) . '"'; |
|
| 447 | 447 | } |
| 448 | 448 | } |
| 449 | 449 | // serialize null value |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | // serialize if an xsd built-in primitive type |
| 468 | - if($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])){ |
|
| 468 | + if ($type != '' && isset($this->typemap[$this->XMLSchemaVersion][$type])) { |
|
| 469 | 469 | $this->debug("serialize_val: serialize xsd built-in primitive type"); |
| 470 | 470 | if (is_bool($val)) { |
| 471 | 471 | if ($type == 'boolean') { |
| 472 | 472 | $val = $val ? 'true' : 'false'; |
| 473 | - } elseif (! $val) { |
|
| 473 | + } elseif (!$val) { |
|
| 474 | 474 | $val = 0; |
| 475 | 475 | } |
| 476 | 476 | } else if (is_string($val)) { |
@@ -488,12 +488,12 @@ discard block |
||
| 488 | 488 | } |
| 489 | 489 | // detect type and serialize |
| 490 | 490 | $xml = ''; |
| 491 | - switch(true) { |
|
| 491 | + switch (true) { |
|
| 492 | 492 | case (is_bool($val) || $type == 'boolean'): |
| 493 | 493 | $this->debug("serialize_val: serialize boolean"); |
| 494 | 494 | if ($type == 'boolean') { |
| 495 | 495 | $val = $val ? 'true' : 'false'; |
| 496 | - } elseif (! $val) { |
|
| 496 | + } elseif (!$val) { |
|
| 497 | 497 | $val = 0; |
| 498 | 498 | } |
| 499 | 499 | if ($use == 'literal') { |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | $xml .= "<$name$xmlns xsi:type=\"xsd:int\"$atts>$val</$name>"; |
| 511 | 511 | } |
| 512 | 512 | break; |
| 513 | - case (is_float($val)|| is_double($val) || $type == 'float'): |
|
| 513 | + case (is_float($val) || is_double($val) || $type == 'float'): |
|
| 514 | 514 | $this->debug("serialize_val: serialize float"); |
| 515 | 515 | if ($use == 'literal') { |
| 516 | 516 | $xml .= "<$name$xmlns$atts>$val</$name>"; |
@@ -535,17 +535,17 @@ discard block |
||
| 535 | 535 | $this->appendDebug($val->getDebug()); |
| 536 | 536 | $val->clearDebug(); |
| 537 | 537 | } else { |
| 538 | - if (! $name) { |
|
| 538 | + if (!$name) { |
|
| 539 | 539 | $name = get_class($val); |
| 540 | 540 | $this->debug("In serialize_val, used class name $name as element name"); |
| 541 | 541 | } else { |
| 542 | 542 | $this->debug("In serialize_val, do not override name $name for element name for class " . get_class($val)); |
| 543 | 543 | } |
| 544 | - foreach(get_object_vars($val) as $k => $v){ |
|
| 545 | - $pXml = isset($pXml) ? $pXml.$this->serialize_val($v,$k,false,false,false,false,$use) : $this->serialize_val($v,$k,false,false,false,false,$use); |
|
| 544 | + foreach (get_object_vars($val) as $k => $v) { |
|
| 545 | + $pXml = isset($pXml) ? $pXml . $this->serialize_val($v, $k, false, false, false, false, $use) : $this->serialize_val($v, $k, false, false, false, false, $use); |
|
| 546 | 546 | } |
| 547 | 547 | } |
| 548 | - if(isset($type) && isset($type_prefix)){ |
|
| 548 | + if (isset($type) && isset($type_prefix)) { |
|
| 549 | 549 | $type_str = " xsi:type=\"$type_prefix:$type\""; |
| 550 | 550 | } else { |
| 551 | 551 | $type_str = ''; |
@@ -560,12 +560,12 @@ discard block |
||
| 560 | 560 | case (is_array($val) || $type): |
| 561 | 561 | // detect if struct or array |
| 562 | 562 | $valueType = $this->isArraySimpleOrStruct($val); |
| 563 | - if($valueType=='arraySimple' || preg_match('/^ArrayOf/',$type)){ |
|
| 563 | + if ($valueType == 'arraySimple' || preg_match('/^ArrayOf/', $type)) { |
|
| 564 | 564 | $this->debug("serialize_val: serialize array"); |
| 565 | 565 | $i = 0; |
| 566 | - if(is_array($val) && count($val)> 0){ |
|
| 567 | - foreach($val as $v){ |
|
| 568 | - if(is_object($v) && get_class($v) == 'soapval'){ |
|
| 566 | + if (is_array($val) && count($val) > 0) { |
|
| 567 | + foreach ($val as $v) { |
|
| 568 | + if (is_object($v) && get_class($v) == 'soapval') { |
|
| 569 | 569 | $tt_ns = $v->type_ns; |
| 570 | 570 | $tt = $v->type; |
| 571 | 571 | } elseif (is_array($v)) { |
@@ -574,23 +574,23 @@ discard block |
||
| 574 | 574 | $tt = gettype($v); |
| 575 | 575 | } |
| 576 | 576 | $array_types[$tt] = 1; |
| 577 | - $xml .= $this->serialize_val($v,'item',false,false,false,false,$use); |
|
| 577 | + $xml .= $this->serialize_val($v, 'item', false, false, false, false, $use); |
|
| 578 | 578 | ++$i; |
| 579 | 579 | } |
| 580 | - if(count($array_types) > 1){ |
|
| 580 | + if (count($array_types) > 1) { |
|
| 581 | 581 | $array_typename = 'xsd:anyType'; |
| 582 | - } elseif(isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) { |
|
| 582 | + } elseif (isset($tt) && isset($this->typemap[$this->XMLSchemaVersion][$tt])) { |
|
| 583 | 583 | if ($tt == 'integer') { |
| 584 | 584 | $tt = 'int'; |
| 585 | 585 | } |
| 586 | - $array_typename = 'xsd:'.$tt; |
|
| 587 | - } elseif(isset($tt) && $tt == 'arraySimple'){ |
|
| 586 | + $array_typename = 'xsd:' . $tt; |
|
| 587 | + } elseif (isset($tt) && $tt == 'arraySimple') { |
|
| 588 | 588 | $array_typename = 'SOAP-ENC:Array'; |
| 589 | - } elseif(isset($tt) && $tt == 'arrayStruct'){ |
|
| 589 | + } elseif (isset($tt) && $tt == 'arrayStruct') { |
|
| 590 | 590 | $array_typename = 'unnamed_struct_use_soapval'; |
| 591 | 591 | } else { |
| 592 | 592 | // if type is prefixed, create type prefix |
| 593 | - if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']){ |
|
| 593 | + if ($tt_ns != '' && $tt_ns == $this->namespaces['xsd']) { |
|
| 594 | 594 | $array_typename = 'xsd:' . $tt; |
| 595 | 595 | } elseif ($tt_ns) { |
| 596 | 596 | $tt_prefix = 'ns' . rand(1000, 9999); |
@@ -606,7 +606,7 @@ discard block |
||
| 606 | 606 | } else if (isset($type) && isset($type_prefix)) { |
| 607 | 607 | $type_str = " xsi:type=\"$type_prefix:$type\""; |
| 608 | 608 | } else { |
| 609 | - $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"".$array_typename."[$array_type]\""; |
|
| 609 | + $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"" . $array_typename . "[$array_type]\""; |
|
| 610 | 610 | } |
| 611 | 611 | // empty array |
| 612 | 612 | } else { |
@@ -618,11 +618,11 @@ discard block |
||
| 618 | 618 | $type_str = " xsi:type=\"SOAP-ENC:Array\" SOAP-ENC:arrayType=\"xsd:anyType[0]\""; |
| 619 | 619 | } |
| 620 | 620 | } |
| 621 | - $xml = "<$name$xmlns$type_str$atts>".$xml."</$name>"; |
|
| 621 | + $xml = "<$name$xmlns$type_str$atts>" . $xml . "</$name>"; |
|
| 622 | 622 | } else { |
| 623 | 623 | // got a struct |
| 624 | 624 | $this->debug("serialize_val: serialize struct"); |
| 625 | - if(isset($type) && isset($type_prefix)){ |
|
| 625 | + if (isset($type) && isset($type_prefix)) { |
|
| 626 | 626 | $type_str = " xsi:type=\"$type_prefix:$type\""; |
| 627 | 627 | } else { |
| 628 | 628 | $type_str = ''; |
@@ -632,15 +632,15 @@ discard block |
||
| 632 | 632 | } else { |
| 633 | 633 | $xml .= "<$name$xmlns$type_str$atts>"; |
| 634 | 634 | } |
| 635 | - foreach($val as $k => $v){ |
|
| 635 | + foreach ($val as $k => $v) { |
|
| 636 | 636 | // Apache Map |
| 637 | 637 | if ($type == 'Map' && $type_ns == 'http://xml.apache.org/xml-soap') { |
| 638 | 638 | $xml .= '<item>'; |
| 639 | - $xml .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
| 640 | - $xml .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
| 639 | + $xml .= $this->serialize_val($k, 'key', false, false, false, false, $use); |
|
| 640 | + $xml .= $this->serialize_val($v, 'value', false, false, false, false, $use); |
|
| 641 | 641 | $xml .= '</item>'; |
| 642 | 642 | } else { |
| 643 | - $xml .= $this->serialize_val($v,$k,false,false,false,false,$use); |
|
| 643 | + $xml .= $this->serialize_val($v, $k, false, false, false, false, $use); |
|
| 644 | 644 | } |
| 645 | 645 | } |
| 646 | 646 | $xml .= "</$name>"; |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | break; |
| 649 | 649 | default: |
| 650 | 650 | $this->debug("serialize_val: serialize unknown"); |
| 651 | - $xml .= 'not detected, got '.gettype($val).' for '.$val; |
|
| 651 | + $xml .= 'not detected, got ' . gettype($val) . ' for ' . $val; |
|
| 652 | 652 | break; |
| 653 | 653 | } |
| 654 | 654 | $this->debug("serialize_val returning $xml"); |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | * @return string the message |
| 668 | 668 | * @access public |
| 669 | 669 | */ |
| 670 | - public function serializeEnvelope($body,$headers=false,$namespaces=array(),$style='rpc',$use='encoded',$encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'){ |
|
| 670 | + public function serializeEnvelope($body, $headers = false, $namespaces = array(), $style = 'rpc', $use = 'encoded', $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/') { |
|
| 671 | 671 | |
| 672 | 672 | $this->debug("In serializeEnvelope length=" . strlen($body) . " body (max 1000 characters)=" . substr($body, 0, 1000) . " style=$style use=$use encodingStyle=$encodingStyle"); |
| 673 | 673 | $this->debug("headers:"); |
@@ -677,15 +677,15 @@ discard block |
||
| 677 | 677 | |
| 678 | 678 | // serialize namespaces |
| 679 | 679 | $ns_string = ''; |
| 680 | - foreach(array_merge($this->namespaces,$namespaces) as $k => $v){ |
|
| 680 | + foreach (array_merge($this->namespaces, $namespaces) as $k => $v) { |
|
| 681 | 681 | $ns_string .= " xmlns:$k=\"$v\""; |
| 682 | 682 | } |
| 683 | - if($encodingStyle) { |
|
| 683 | + if ($encodingStyle) { |
|
| 684 | 684 | $ns_string = " SOAP-ENV:encodingStyle=\"$encodingStyle\"$ns_string"; |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | // serialize headers |
| 688 | - if($headers){ |
|
| 688 | + if ($headers) { |
|
| 689 | 689 | if (is_array($headers)) { |
| 690 | 690 | $xml = ''; |
| 691 | 691 | foreach ($headers as $k => $v) { |
@@ -698,16 +698,16 @@ discard block |
||
| 698 | 698 | $headers = $xml; |
| 699 | 699 | $this->debug("In serializeEnvelope, serialized array of headers to $headers"); |
| 700 | 700 | } |
| 701 | - $headers = "<SOAP-ENV:Header>".$headers."</SOAP-ENV:Header>"; |
|
| 701 | + $headers = "<SOAP-ENV:Header>" . $headers . "</SOAP-ENV:Header>"; |
|
| 702 | 702 | } |
| 703 | 703 | // serialize envelope |
| 704 | 704 | return |
| 705 | - '<?xml version="1.0" encoding="'.$this->soap_defencoding .'"?'.">". |
|
| 706 | - '<SOAP-ENV:Envelope'.$ns_string.">". |
|
| 707 | - $headers. |
|
| 708 | - "<SOAP-ENV:Body>". |
|
| 709 | - $body. |
|
| 710 | - "</SOAP-ENV:Body>". |
|
| 705 | + '<?xml version="1.0" encoding="' . $this->soap_defencoding . '"?' . ">" . |
|
| 706 | + '<SOAP-ENV:Envelope' . $ns_string . ">" . |
|
| 707 | + $headers . |
|
| 708 | + "<SOAP-ENV:Body>" . |
|
| 709 | + $body . |
|
| 710 | + "</SOAP-ENV:Body>" . |
|
| 711 | 711 | "</SOAP-ENV:Envelope>"; |
| 712 | 712 | } |
| 713 | 713 | |
@@ -719,7 +719,7 @@ discard block |
||
| 719 | 719 | * @access public |
| 720 | 720 | * @deprecated |
| 721 | 721 | */ |
| 722 | - public function formatDump($str){ |
|
| 722 | + public function formatDump($str) { |
|
| 723 | 723 | $str = htmlspecialchars($str); |
| 724 | 724 | return nl2br($str); |
| 725 | 725 | } |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | * @return string contracted qname |
| 732 | 732 | * @access private |
| 733 | 733 | */ |
| 734 | - public function contractQname($qname){ |
|
| 734 | + public function contractQname($qname) { |
|
| 735 | 735 | // get element namespace |
| 736 | 736 | if (strrpos($qname, ':')) { |
| 737 | 737 | // get unqualified name |
@@ -755,15 +755,15 @@ discard block |
||
| 755 | 755 | * @return string expanded qname |
| 756 | 756 | * @access private |
| 757 | 757 | */ |
| 758 | - public function expandQname($qname){ |
|
| 758 | + public function expandQname($qname) { |
|
| 759 | 759 | // get element prefix |
| 760 | - if(strpos($qname,':') && !preg_match('/^http:\/\//',$qname)){ |
|
| 760 | + if (strpos($qname, ':') && !preg_match('/^http:\/\//', $qname)) { |
|
| 761 | 761 | // get unqualified name |
| 762 | - $name = substr(strstr($qname,':'),1); |
|
| 762 | + $name = substr(strstr($qname, ':'), 1); |
|
| 763 | 763 | // get ns prefix |
| 764 | - $prefix = substr($qname,0,strpos($qname,':')); |
|
| 765 | - if(isset($this->namespaces[$prefix])){ |
|
| 766 | - return $this->namespaces[$prefix].':'.$name; |
|
| 764 | + $prefix = substr($qname, 0, strpos($qname, ':')); |
|
| 765 | + if (isset($this->namespaces[$prefix])) { |
|
| 766 | + return $this->namespaces[$prefix] . ':' . $name; |
|
| 767 | 767 | } else { |
| 768 | 768 | return $qname; |
| 769 | 769 | } |
@@ -780,10 +780,10 @@ discard block |
||
| 780 | 780 | * @return string The local part |
| 781 | 781 | * @access public |
| 782 | 782 | */ |
| 783 | - public function getLocalPart($str){ |
|
| 784 | - if($sstr = strrchr($str,':')){ |
|
| 783 | + public function getLocalPart($str) { |
|
| 784 | + if ($sstr = strrchr($str, ':')) { |
|
| 785 | 785 | // get unqualified name |
| 786 | - return substr( $sstr, 1 ); |
|
| 786 | + return substr($sstr, 1); |
|
| 787 | 787 | } else { |
| 788 | 788 | return $str; |
| 789 | 789 | } |
@@ -797,10 +797,10 @@ discard block |
||
| 797 | 797 | * @return mixed The prefix or false if there is no prefix |
| 798 | 798 | * @access public |
| 799 | 799 | */ |
| 800 | - public function getPrefix($str){ |
|
| 801 | - if($pos = strrpos($str,':')){ |
|
| 800 | + public function getPrefix($str) { |
|
| 801 | + if ($pos = strrpos($str, ':')) { |
|
| 802 | 802 | // get prefix |
| 803 | - return substr($str,0,$pos); |
|
| 803 | + return substr($str, 0, $pos); |
|
| 804 | 804 | } |
| 805 | 805 | return false; |
| 806 | 806 | } |
@@ -812,7 +812,7 @@ discard block |
||
| 812 | 812 | * @return mixed The namespace, false if no namespace has the specified prefix |
| 813 | 813 | * @access public |
| 814 | 814 | */ |
| 815 | - public function getNamespaceFromPrefix($prefix){ |
|
| 815 | + public function getNamespaceFromPrefix($prefix) { |
|
| 816 | 816 | if (isset($this->namespaces[$prefix])) { |
| 817 | 817 | return $this->namespaces[$prefix]; |
| 818 | 818 | } |
@@ -890,8 +890,8 @@ discard block |
||
| 890 | 890 | * @return mixed ISO 8601 date string or false |
| 891 | 891 | * @access public |
| 892 | 892 | */ |
| 893 | -function timestamp_to_iso8601($timestamp,$utc=true){ |
|
| 894 | - $datestr = date('Y-m-d\TH:i:sO',$timestamp); |
|
| 893 | +function timestamp_to_iso8601($timestamp, $utc = true) { |
|
| 894 | + $datestr = date('Y-m-d\TH:i:sO', $timestamp); |
|
| 895 | 895 | $pos = strrpos($datestr, "+"); |
| 896 | 896 | if ($pos === false) { |
| 897 | 897 | $pos = strrpos($datestr, "-"); |
@@ -901,20 +901,20 @@ discard block |
||
| 901 | 901 | $datestr = substr($datestr, 0, $pos + 3) . ':' . substr($datestr, -2); |
| 902 | 902 | } |
| 903 | 903 | } |
| 904 | - if($utc){ |
|
| 905 | - $pattern = '/'. |
|
| 906 | - '([0-9]{4})-'. // centuries & years CCYY- |
|
| 907 | - '([0-9]{2})-'. // months MM- |
|
| 908 | - '([0-9]{2})'. // days DD |
|
| 909 | - 'T'. // separator T |
|
| 910 | - '([0-9]{2}):'. // hours hh: |
|
| 911 | - '([0-9]{2}):'. // minutes mm: |
|
| 912 | - '([0-9]{2})(\.[0-9]*)?'. // seconds ss.ss... |
|
| 913 | - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
| 904 | + if ($utc) { |
|
| 905 | + $pattern = '/' . |
|
| 906 | + '([0-9]{4})-' . // centuries & years CCYY- |
|
| 907 | + '([0-9]{2})-' . // months MM- |
|
| 908 | + '([0-9]{2})' . // days DD |
|
| 909 | + 'T' . // separator T |
|
| 910 | + '([0-9]{2}):' . // hours hh: |
|
| 911 | + '([0-9]{2}):' . // minutes mm: |
|
| 912 | + '([0-9]{2})(\.[0-9]*)?' . // seconds ss.ss... |
|
| 913 | + '(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
| 914 | 914 | '/'; |
| 915 | 915 | |
| 916 | - if(preg_match($pattern,$datestr,$regs)){ |
|
| 917 | - return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$regs[1],$regs[2],$regs[3],$regs[4],$regs[5],$regs[6]); |
|
| 916 | + if (preg_match($pattern, $datestr, $regs)) { |
|
| 917 | + return sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $regs[1], $regs[2], $regs[3], $regs[4], $regs[5], $regs[6]); |
|
| 918 | 918 | } |
| 919 | 919 | return false; |
| 920 | 920 | } else { |
@@ -929,27 +929,27 @@ discard block |
||
| 929 | 929 | * @return mixed Unix timestamp (int) or false |
| 930 | 930 | * @access public |
| 931 | 931 | */ |
| 932 | -function iso8601_to_timestamp($datestr){ |
|
| 933 | - $pattern = '/'. |
|
| 934 | - '([0-9]{4})-'. // centuries & years CCYY- |
|
| 935 | - '([0-9]{2})-'. // months MM- |
|
| 936 | - '([0-9]{2})'. // days DD |
|
| 937 | - 'T'. // separator T |
|
| 938 | - '([0-9]{2}):'. // hours hh: |
|
| 939 | - '([0-9]{2}):'. // minutes mm: |
|
| 940 | - '([0-9]{2})(\.[0-9]+)?'. // seconds ss.ss... |
|
| 941 | - '(Z|[+\-][0-9]{2}:?[0-9]{2})?'. // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
| 932 | +function iso8601_to_timestamp($datestr) { |
|
| 933 | + $pattern = '/' . |
|
| 934 | + '([0-9]{4})-' . // centuries & years CCYY- |
|
| 935 | + '([0-9]{2})-' . // months MM- |
|
| 936 | + '([0-9]{2})' . // days DD |
|
| 937 | + 'T' . // separator T |
|
| 938 | + '([0-9]{2}):' . // hours hh: |
|
| 939 | + '([0-9]{2}):' . // minutes mm: |
|
| 940 | + '([0-9]{2})(\.[0-9]+)?' . // seconds ss.ss... |
|
| 941 | + '(Z|[+\-][0-9]{2}:?[0-9]{2})?' . // Z to indicate UTC, -/+HH:MM:SS.SS... for local tz's |
|
| 942 | 942 | '/'; |
| 943 | - if(preg_match($pattern,$datestr,$regs)){ |
|
| 943 | + if (preg_match($pattern, $datestr, $regs)) { |
|
| 944 | 944 | // not utc |
| 945 | - if($regs[8] != 'Z'){ |
|
| 946 | - $op = substr($regs[8],0,1); |
|
| 947 | - $h = substr($regs[8],1,2); |
|
| 948 | - $m = substr($regs[8],strlen($regs[8])-2,2); |
|
| 949 | - if($op == '-'){ |
|
| 945 | + if ($regs[8] != 'Z') { |
|
| 946 | + $op = substr($regs[8], 0, 1); |
|
| 947 | + $h = substr($regs[8], 1, 2); |
|
| 948 | + $m = substr($regs[8], strlen($regs[8]) - 2, 2); |
|
| 949 | + if ($op == '-') { |
|
| 950 | 950 | $regs[4] = $regs[4] + $h; |
| 951 | 951 | $regs[5] = $regs[5] + $m; |
| 952 | - } elseif($op == '+'){ |
|
| 952 | + } elseif ($op == '+') { |
|
| 953 | 953 | $regs[4] = $regs[4] - $h; |
| 954 | 954 | $regs[5] = $regs[5] - $m; |
| 955 | 955 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public $fileName; |
| 81 | 81 | public $compressedList; // You will problably use only this one! |
| 82 | 82 | public $centralDirList; // Central dir list... It's a kind of 'extra attributes' for a set of files |
| 83 | - public $endOfCentral; // End of central dir, contains ZIP Comments |
|
| 83 | + public $endOfCentral; // End of central dir, contains ZIP Comments |
|
| 84 | 84 | public $debug; |
| 85 | 85 | // Private |
| 86 | 86 | public $fh; |
@@ -188,15 +188,13 @@ discard block |
||
| 188 | 188 | { |
| 189 | 189 | return |
| 190 | 190 | isset($this->centralDirList[$compressedFileName]) ? |
| 191 | - $this->centralDirList[$compressedFileName] : |
|
| 192 | - false; |
|
| 191 | + $this->centralDirList[$compressedFileName] : false; |
|
| 193 | 192 | } |
| 194 | 193 | |
| 195 | 194 | public function getZipInfo($detail = false) |
| 196 | 195 | { |
| 197 | 196 | return $detail ? |
| 198 | - $this->endOfCentral[$detail] : |
|
| 199 | - $this->endOfCentral; |
|
| 197 | + $this->endOfCentral[$detail] : $this->endOfCentral; |
|
| 200 | 198 | } |
| 201 | 199 | |
| 202 | 200 | public function unzip($compressedFileName, $targetFileName = false, $applyChmod = 0644) |
@@ -218,8 +216,7 @@ discard block |
||
| 218 | 216 | if (!$fdetails['uncompressed_size']) { |
| 219 | 217 | $this->debugMsg(1, "File '<b>$compressedFileName</b>' is empty."); |
| 220 | 218 | return $targetFileName ? |
| 221 | - file_put_contents($targetFileName, "") : |
|
| 222 | - ""; |
|
| 219 | + file_put_contents($targetFileName, "") : ""; |
|
| 223 | 220 | } |
| 224 | 221 | |
| 225 | 222 | fseek($this->fh, $fdetails['contents-startOffset']); |
@@ -263,8 +260,7 @@ discard block |
||
| 263 | 260 | continue; |
| 264 | 261 | |
| 265 | 262 | $maintainStructure ? |
| 266 | - $this->unzip($fileName, "$targetDir/$fileName", $applyChmod) : |
|
| 267 | - $this->unzip($fileName, "$targetDir/" . basename($fileName), $applyChmod); |
|
| 263 | + $this->unzip($fileName, "$targetDir/$fileName", $applyChmod) : $this->unzip($fileName, "$targetDir/" . basename($fileName), $applyChmod); |
|
| 268 | 264 | } |
| 269 | 265 | } |
| 270 | 266 | |
@@ -286,8 +282,7 @@ discard block |
||
| 286 | 282 | case 0: |
| 287 | 283 | // Not compressed |
| 288 | 284 | return $targetFileName ? |
| 289 | - file_put_contents($targetFileName, $content) : |
|
| 290 | - $content; |
|
| 285 | + file_put_contents($targetFileName, $content) : $content; |
|
| 291 | 286 | case 1: |
| 292 | 287 | $this->debugMsg(2, "Shrunk mode is not supported... yet?"); |
| 293 | 288 | return false; |
@@ -306,8 +301,7 @@ discard block |
||
| 306 | 301 | case 8: |
| 307 | 302 | // Deflate |
| 308 | 303 | return $targetFileName ? |
| 309 | - file_put_contents($targetFileName, gzinflate($content, $uncompressedSize)) : |
|
| 310 | - gzinflate($content, $uncompressedSize); |
|
| 304 | + file_put_contents($targetFileName, gzinflate($content, $uncompressedSize)) : gzinflate($content, $uncompressedSize); |
|
| 311 | 305 | case 9: |
| 312 | 306 | $this->debugMsg(2, "Enhanced Deflating is not supported... yet?"); |
| 313 | 307 | return false; |
@@ -317,8 +311,7 @@ discard block |
||
| 317 | 311 | case 12: |
| 318 | 312 | // Bzip2 |
| 319 | 313 | return $targetFileName ? |
| 320 | - file_put_contents($targetFileName, bzdecompress($content)) : |
|
| 321 | - bzdecompress($content); |
|
| 314 | + file_put_contents($targetFileName, bzdecompress($content)) : bzdecompress($content); |
|
| 322 | 315 | case 18: |
| 323 | 316 | $this->debugMsg(2, "IBM TERSE is not supported... yet?"); |
| 324 | 317 | return false; |
@@ -378,7 +371,7 @@ discard block |
||
| 378 | 371 | $dir['compression_method'] = unpack("v", fread($fh, 2)); // compression method |
| 379 | 372 | $dir['lastmod_time'] = unpack("v", fread($fh, 2)); // last mod file time |
| 380 | 373 | $dir['lastmod_date'] = unpack("v", fread($fh, 2)); // last mod file date |
| 381 | - $dir['crc-32'] = fread($fh, 4); // crc-32 |
|
| 374 | + $dir['crc-32'] = fread($fh, 4); // crc-32 |
|
| 382 | 375 | $dir['compressed_size'] = unpack("V", fread($fh, 4)); // compressed size |
| 383 | 376 | $dir['uncompressed_size'] = unpack("V", fread($fh, 4)); // uncompressed size |
| 384 | 377 | $fileNameLength = unpack("v", fread($fh, 2)); // filename length |
@@ -389,7 +382,7 @@ discard block |
||
| 389 | 382 | $dir['external_attributes1'] = unpack("v", fread($fh, 2)); // external file attributes-byte2 |
| 390 | 383 | $dir['external_attributes2'] = unpack("v", fread($fh, 2)); // external file attributes |
| 391 | 384 | $dir['relative_offset'] = unpack("V", fread($fh, 4)); // relative offset of local header |
| 392 | - $dir['file_name'] = fread($fh, $fileNameLength[1]); // filename |
|
| 385 | + $dir['file_name'] = fread($fh, $fileNameLength[1]); // filename |
|
| 393 | 386 | $dir['extra_field'] = $extraFieldLength[1] ? fread($fh, $extraFieldLength[1]) : ''; // extra field |
| 394 | 387 | $dir['file_comment'] = $fileCommentLength[1] ? fread($fh, $fileCommentLength[1]) : ''; // file comment |
| 395 | 388 | // Convert the date and time, from MS-DOS format to UNIX Timestamp |
@@ -489,7 +482,7 @@ discard block |
||
| 489 | 482 | $file['compression_method'] = unpack("v", fread($fh, 2)); // compression method |
| 490 | 483 | $file['lastmod_time'] = unpack("v", fread($fh, 2)); // last mod file time |
| 491 | 484 | $file['lastmod_date'] = unpack("v", fread($fh, 2)); // last mod file date |
| 492 | - $file['crc-32'] = fread($fh, 4); // crc-32 |
|
| 485 | + $file['crc-32'] = fread($fh, 4); // crc-32 |
|
| 493 | 486 | $file['compressed_size'] = unpack("V", fread($fh, 4)); // compressed size |
| 494 | 487 | $file['uncompressed_size'] = unpack("V", fread($fh, 4)); // uncompressed size |
| 495 | 488 | $fileNameLength = unpack("v", fread($fh, 2)); // filename length |
@@ -34,559 +34,559 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class Net_Socket extends PEAR { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Socket file pointer. |
|
| 39 | - * @var resource $fp |
|
| 40 | - */ |
|
| 41 | - public $fp = null; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Whether the socket is blocking. Defaults to true. |
|
| 45 | - * @var boolean $blocking |
|
| 46 | - */ |
|
| 47 | - public $blocking = true; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Whether the socket is persistent. Defaults to false. |
|
| 51 | - * @var boolean $persistent |
|
| 52 | - */ |
|
| 53 | - public $persistent = false; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The IP address to connect to. |
|
| 57 | - * @var string $addr |
|
| 58 | - */ |
|
| 59 | - public $addr = ''; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * The port number to connect to. |
|
| 63 | - * @var integer $port |
|
| 64 | - */ |
|
| 65 | - public $port = 0; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Number of seconds to wait on socket connections before assuming |
|
| 69 | - * there's no more data. Defaults to no timeout. |
|
| 70 | - * @var integer $timeout |
|
| 71 | - */ |
|
| 72 | - public $timeout = false; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Number of bytes to read at a time in readLine() and |
|
| 76 | - * readAll(). Defaults to 2048. |
|
| 77 | - * @var integer $lineLength |
|
| 78 | - */ |
|
| 79 | - public $lineLength = 2048; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Connect to the specified port. If called when the socket is |
|
| 83 | - * already connected, it disconnects and connects again. |
|
| 84 | - * |
|
| 85 | - * @param string $addr IP address or host name. |
|
| 86 | - * @param integer $port TCP port number. |
|
| 87 | - * @param boolean $persistent (optional) Whether the connection is |
|
| 88 | - * persistent (kept open between requests |
|
| 89 | - * by the web server). |
|
| 90 | - * @param integer $timeout (optional) How long to wait for data. |
|
| 91 | - * @param array $options See options for stream_context_create. |
|
| 92 | - * |
|
| 93 | - * @access public |
|
| 94 | - * |
|
| 95 | - * @return boolean | PEAR_Error True on success or a PEAR_Error on failure. |
|
| 96 | - */ |
|
| 97 | - public function connect($addr, $port = 0, $persistent = null, $timeout = null, $options = null) |
|
| 98 | - { |
|
| 99 | - if (is_resource($this->fp)) { |
|
| 100 | - @fclose($this->fp); |
|
| 101 | - $this->fp = null; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - if (!$addr) { |
|
| 105 | - return $this->raiseError('$addr cannot be empty'); |
|
| 106 | - } elseif (strspn($addr, '.0123456789') == strlen($addr) || |
|
| 107 | - strstr($addr, '/') !== false) { |
|
| 108 | - $this->addr = $addr; |
|
| 109 | - } else { |
|
| 110 | - $this->addr = @gethostbyname($addr); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $this->port = $port % 65536; |
|
| 114 | - |
|
| 115 | - if ($persistent !== null) { |
|
| 116 | - $this->persistent = $persistent; |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($timeout !== null) { |
|
| 120 | - $this->timeout = $timeout; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - $openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen'; |
|
| 124 | - $errno = 0; |
|
| 125 | - $errstr = ''; |
|
| 126 | - $old_track_errors = @ini_set('track_errors', 1); |
|
| 127 | - if ($options && function_exists('stream_context_create')) { |
|
| 128 | - if ($this->timeout) { |
|
| 129 | - $timeout = $this->timeout; |
|
| 130 | - } else { |
|
| 131 | - $timeout = 0; |
|
| 132 | - } |
|
| 133 | - $context = stream_context_create($options); |
|
| 134 | - |
|
| 135 | - // Since PHP 5 fsockopen doesn't allow context specification |
|
| 136 | - if (function_exists('stream_socket_client')) { |
|
| 137 | - $flags = $this->persistent ? STREAM_CLIENT_PERSISTENT : STREAM_CLIENT_CONNECT; |
|
| 138 | - $addr = $this->addr . ':' . $this->port; |
|
| 139 | - $fp = stream_socket_client($addr, $errno, $errstr, $timeout, $flags, $context); |
|
| 140 | - } else { |
|
| 141 | - $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context); |
|
| 142 | - } |
|
| 143 | - } else { |
|
| 144 | - if ($this->timeout) { |
|
| 145 | - $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout); |
|
| 146 | - } else { |
|
| 147 | - $fp = @$openfunc($this->addr, $this->port, $errno, $errstr); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if (!$fp) { |
|
| 152 | - if ($errno == 0 && isset($php_errormsg)) { |
|
| 153 | - $errstr = $php_errormsg; |
|
| 154 | - } |
|
| 155 | - @ini_set('track_errors', $old_track_errors); |
|
| 156 | - return $this->raiseError($errstr, $errno); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - @ini_set('track_errors', $old_track_errors); |
|
| 160 | - $this->fp = $fp; |
|
| 161 | - |
|
| 162 | - return $this->setBlocking($this->blocking); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Disconnects from the peer, closes the socket. |
|
| 167 | - * |
|
| 168 | - * @access public |
|
| 169 | - * @return mixed true on success or a PEAR_Error instance otherwise |
|
| 170 | - */ |
|
| 171 | - public function disconnect() |
|
| 172 | - { |
|
| 173 | - if (!is_resource($this->fp)) { |
|
| 174 | - return $this->raiseError('not connected'); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - @fclose($this->fp); |
|
| 178 | - $this->fp = null; |
|
| 179 | - return true; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Find out if the socket is in blocking mode. |
|
| 184 | - * |
|
| 185 | - * @access public |
|
| 186 | - * @return boolean The current blocking mode. |
|
| 187 | - */ |
|
| 188 | - public function isBlocking() |
|
| 189 | - { |
|
| 190 | - return $this->blocking; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Sets whether the socket connection should be blocking or |
|
| 195 | - * not. A read call to a non-blocking socket will return immediately |
|
| 196 | - * if there is no data available, whereas it will block until there |
|
| 197 | - * is data for blocking sockets. |
|
| 198 | - * |
|
| 199 | - * @param boolean $mode True for blocking sockets, false for nonblocking. |
|
| 200 | - * @access public |
|
| 201 | - * @return mixed true on success or a PEAR_Error instance otherwise |
|
| 202 | - */ |
|
| 203 | - public function setBlocking($mode) |
|
| 204 | - { |
|
| 205 | - if (!is_resource($this->fp)) { |
|
| 206 | - return $this->raiseError('not connected'); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - $this->blocking = $mode; |
|
| 210 | - socket_set_blocking($this->fp, $this->blocking); |
|
| 211 | - return true; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Sets the timeout value on socket descriptor, |
|
| 216 | - * expressed in the sum of seconds and microseconds |
|
| 217 | - * |
|
| 218 | - * @param integer $seconds Seconds. |
|
| 219 | - * @param integer $microseconds Microseconds. |
|
| 220 | - * @access public |
|
| 221 | - * @return mixed true on success or a PEAR_Error instance otherwise |
|
| 222 | - */ |
|
| 223 | - public function setTimeout($seconds, $microseconds) |
|
| 224 | - { |
|
| 225 | - if (!is_resource($this->fp)) { |
|
| 226 | - return $this->raiseError('not connected'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return socket_set_timeout($this->fp, $seconds, $microseconds); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Sets the file buffering size on the stream. |
|
| 234 | - * See php's stream_set_write_buffer for more information. |
|
| 235 | - * |
|
| 236 | - * @param integer $size Write buffer size. |
|
| 237 | - * @access public |
|
| 238 | - * @return mixed on success or an PEAR_Error object otherwise |
|
| 239 | - */ |
|
| 240 | - public function setWriteBuffer($size) |
|
| 241 | - { |
|
| 242 | - if (!is_resource($this->fp)) { |
|
| 243 | - return $this->raiseError('not connected'); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $returned = stream_set_write_buffer($this->fp, $size); |
|
| 247 | - if ($returned == 0) { |
|
| 248 | - return true; |
|
| 249 | - } |
|
| 250 | - return $this->raiseError('Cannot set write buffer.'); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Returns information about an existing socket resource. |
|
| 255 | - * Currently returns four entries in the result array: |
|
| 256 | - * |
|
| 257 | - * <p> |
|
| 258 | - * timed_out (bool) - The socket timed out waiting for data<br> |
|
| 259 | - * blocked (bool) - The socket was blocked<br> |
|
| 260 | - * eof (bool) - Indicates EOF event<br> |
|
| 261 | - * unread_bytes (int) - Number of bytes left in the socket buffer<br> |
|
| 262 | - * </p> |
|
| 263 | - * |
|
| 264 | - * @access public |
|
| 265 | - * @return mixed Array containing information about existing socket resource or a PEAR_Error instance otherwise |
|
| 266 | - */ |
|
| 267 | - public function getStatus() |
|
| 268 | - { |
|
| 269 | - if (!is_resource($this->fp)) { |
|
| 270 | - return $this->raiseError('not connected'); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - return socket_get_status($this->fp); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Get a specified line of data |
|
| 278 | - * |
|
| 279 | - * @access public |
|
| 280 | - * @return $size bytes of data from the socket, or a PEAR_Error if |
|
| 281 | - * not connected. |
|
| 282 | - */ |
|
| 283 | - public function gets($size) |
|
| 284 | - { |
|
| 285 | - if (!is_resource($this->fp)) { |
|
| 286 | - return $this->raiseError('not connected'); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return @fgets($this->fp, $size); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Read a specified amount of data. This is guaranteed to return, |
|
| 294 | - * and has the added benefit of getting everything in one fread() |
|
| 295 | - * chunk; if you know the size of the data you're getting |
|
| 296 | - * beforehand, this is definitely the way to go. |
|
| 297 | - * |
|
| 298 | - * @param integer $size The number of bytes to read from the socket. |
|
| 299 | - * @access public |
|
| 300 | - * @return $size bytes of data from the socket, or a PEAR_Error if |
|
| 301 | - * not connected. |
|
| 302 | - */ |
|
| 303 | - public function read($size) |
|
| 304 | - { |
|
| 305 | - if (!is_resource($this->fp)) { |
|
| 306 | - return $this->raiseError('not connected'); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - return @fread($this->fp, $size); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Write a specified amount of data. |
|
| 314 | - * |
|
| 315 | - * @param string $data Data to write. |
|
| 316 | - * @param integer $blocksize Amount of data to write at once. |
|
| 317 | - * NULL means all at once. |
|
| 318 | - * |
|
| 319 | - * @access public |
|
| 320 | - * @return mixed If the socket is not connected, returns an instance of PEAR_Error |
|
| 321 | - * If the write succeeds, returns the number of bytes written |
|
| 322 | - * If the write fails, returns false. |
|
| 323 | - */ |
|
| 324 | - public function write($data, $blocksize = null) |
|
| 325 | - { |
|
| 326 | - if (!is_resource($this->fp)) { |
|
| 327 | - return $this->raiseError('not connected'); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - if (is_null($blocksize) && !OS_WINDOWS) { |
|
| 331 | - return @fwrite($this->fp, $data); |
|
| 332 | - } else { |
|
| 333 | - if (is_null($blocksize)) { |
|
| 334 | - $blocksize = 1024; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $pos = 0; |
|
| 338 | - $size = strlen($data); |
|
| 339 | - while ($pos < $size) { |
|
| 340 | - $written = @fwrite($this->fp, substr($data, $pos, $blocksize)); |
|
| 341 | - if ($written === false) { |
|
| 342 | - return false; |
|
| 343 | - } |
|
| 344 | - $pos += $written; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - return $pos; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Write a line of data to the socket, followed by a trailing "\r\n". |
|
| 353 | - * |
|
| 354 | - * @access public |
|
| 355 | - * @return mixed fputs result, or an error |
|
| 356 | - */ |
|
| 357 | - public function writeLine($data) |
|
| 358 | - { |
|
| 359 | - if (!is_resource($this->fp)) { |
|
| 360 | - return $this->raiseError('not connected'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - return fwrite($this->fp, $data . "\r\n"); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * Tests for end-of-file on a socket descriptor. |
|
| 368 | - * |
|
| 369 | - * Also returns true if the socket is disconnected. |
|
| 370 | - * |
|
| 371 | - * @access public |
|
| 372 | - * @return bool |
|
| 373 | - */ |
|
| 374 | - public function eof() |
|
| 375 | - { |
|
| 376 | - return (!is_resource($this->fp) || feof($this->fp)); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Reads a byte of data |
|
| 381 | - * |
|
| 382 | - * @access public |
|
| 383 | - * @return 1 byte of data from the socket, or a PEAR_Error if |
|
| 384 | - * not connected. |
|
| 385 | - */ |
|
| 386 | - public function readByte() |
|
| 387 | - { |
|
| 388 | - if (!is_resource($this->fp)) { |
|
| 389 | - return $this->raiseError('not connected'); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return ord(@fread($this->fp, 1)); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Reads a word of data |
|
| 397 | - * |
|
| 398 | - * @access public |
|
| 399 | - * @return 1 word of data from the socket, or a PEAR_Error if |
|
| 400 | - * not connected. |
|
| 401 | - */ |
|
| 402 | - public function readWord() |
|
| 403 | - { |
|
| 404 | - if (!is_resource($this->fp)) { |
|
| 405 | - return $this->raiseError('not connected'); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - $buf = @fread($this->fp, 2); |
|
| 409 | - return (ord($buf[0]) + (ord($buf[1]) << 8)); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Reads an int of data |
|
| 414 | - * |
|
| 415 | - * @access public |
|
| 416 | - * @return integer 1 int of data from the socket, or a PEAR_Error if |
|
| 417 | - * not connected. |
|
| 418 | - */ |
|
| 419 | - public function readInt() |
|
| 420 | - { |
|
| 421 | - if (!is_resource($this->fp)) { |
|
| 422 | - return $this->raiseError('not connected'); |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - $buf = @fread($this->fp, 4); |
|
| 426 | - return (ord($buf[0]) + (ord($buf[1]) << 8) + |
|
| 427 | - (ord($buf[2]) << 16) + (ord($buf[3]) << 24)); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Reads a zero-terminated string of data |
|
| 432 | - * |
|
| 433 | - * @access public |
|
| 434 | - * @return string, or a PEAR_Error if |
|
| 435 | - * not connected. |
|
| 436 | - */ |
|
| 437 | - public function readString() |
|
| 438 | - { |
|
| 439 | - if (!is_resource($this->fp)) { |
|
| 440 | - return $this->raiseError('not connected'); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $string = ''; |
|
| 444 | - while (($char = @fread($this->fp, 1)) != "\x00") { |
|
| 445 | - $string .= $char; |
|
| 446 | - } |
|
| 447 | - return $string; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Reads an IP Address and returns it in a dot formatted string |
|
| 452 | - * |
|
| 453 | - * @access public |
|
| 454 | - * @return Dot formatted string, or a PEAR_Error if |
|
| 455 | - * not connected. |
|
| 456 | - */ |
|
| 457 | - public function readIPAddress() |
|
| 458 | - { |
|
| 459 | - if (!is_resource($this->fp)) { |
|
| 460 | - return $this->raiseError('not connected'); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - $buf = @fread($this->fp, 4); |
|
| 464 | - return sprintf('%d.%d.%d.%d', ord($buf[0]), ord($buf[1]), |
|
| 465 | - ord($buf[2]), ord($buf[3])); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Read until either the end of the socket or a newline, whichever |
|
| 470 | - * comes first. Strips the trailing newline from the returned data. |
|
| 471 | - * |
|
| 472 | - * @access public |
|
| 473 | - * @return All available data up to a newline, without that |
|
| 474 | - * newline, or until the end of the socket, or a PEAR_Error if |
|
| 475 | - * not connected. |
|
| 476 | - */ |
|
| 477 | - public function readLine() |
|
| 478 | - { |
|
| 479 | - if (!is_resource($this->fp)) { |
|
| 480 | - return $this->raiseError('not connected'); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - $line = ''; |
|
| 484 | - $timeout = time() + $this->timeout; |
|
| 485 | - while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) { |
|
| 486 | - $line .= @fgets($this->fp, $this->lineLength); |
|
| 487 | - if (substr($line, -1) == "\n") { |
|
| 488 | - return rtrim($line, "\r\n"); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - return $line; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Read until the socket closes, or until there is no more data in |
|
| 496 | - * the inner PHP buffer. If the inner buffer is empty, in blocking |
|
| 497 | - * mode we wait for at least 1 byte of data. Therefore, in |
|
| 498 | - * blocking mode, if there is no data at all to be read, this |
|
| 499 | - * function will never exit (unless the socket is closed on the |
|
| 500 | - * remote end). |
|
| 501 | - * |
|
| 502 | - * @access public |
|
| 503 | - * |
|
| 504 | - * @return string All data until the socket closes, or a PEAR_Error if |
|
| 505 | - * not connected. |
|
| 506 | - */ |
|
| 507 | - public function readAll() |
|
| 508 | - { |
|
| 509 | - if (!is_resource($this->fp)) { |
|
| 510 | - return $this->raiseError('not connected'); |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - $data = ''; |
|
| 514 | - while (!feof($this->fp)) { |
|
| 515 | - $data .= @fread($this->fp, $this->lineLength); |
|
| 516 | - } |
|
| 517 | - return $data; |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - /** |
|
| 521 | - * Runs the equivalent of the select() system call on the socket |
|
| 522 | - * with a timeout specified by tv_sec and tv_usec. |
|
| 523 | - * |
|
| 524 | - * @param integer $state Which of read/write/error to check for. |
|
| 525 | - * @param integer $tv_sec Number of seconds for timeout. |
|
| 526 | - * @param integer $tv_usec Number of microseconds for timeout. |
|
| 527 | - * |
|
| 528 | - * @access public |
|
| 529 | - * @return False if select fails, integer describing which of read/write/error |
|
| 530 | - * are ready, or PEAR_Error if not connected. |
|
| 531 | - */ |
|
| 532 | - public function select($state, $tv_sec, $tv_usec = 0) |
|
| 533 | - { |
|
| 534 | - if (!is_resource($this->fp)) { |
|
| 535 | - return $this->raiseError('not connected'); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - $read = null; |
|
| 539 | - $write = null; |
|
| 540 | - $except = null; |
|
| 541 | - if ($state & NET_SOCKET_READ) { |
|
| 542 | - $read[] = $this->fp; |
|
| 543 | - } |
|
| 544 | - if ($state & NET_SOCKET_WRITE) { |
|
| 545 | - $write[] = $this->fp; |
|
| 546 | - } |
|
| 547 | - if ($state & NET_SOCKET_ERROR) { |
|
| 548 | - $except[] = $this->fp; |
|
| 549 | - } |
|
| 550 | - if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) { |
|
| 551 | - return false; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - $result = 0; |
|
| 555 | - if (count($read)) { |
|
| 556 | - $result |= NET_SOCKET_READ; |
|
| 557 | - } |
|
| 558 | - if (count($write)) { |
|
| 559 | - $result |= NET_SOCKET_WRITE; |
|
| 560 | - } |
|
| 561 | - if (count($except)) { |
|
| 562 | - $result |= NET_SOCKET_ERROR; |
|
| 563 | - } |
|
| 564 | - return $result; |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Turns encryption on/off on a connected socket. |
|
| 569 | - * |
|
| 570 | - * @param bool $enabled Set this parameter to true to enable encryption |
|
| 571 | - * and false to disable encryption. |
|
| 572 | - * @param integer $type Type of encryption. See |
|
| 573 | - * http://se.php.net/manual/en/function.stream-socket-enable-crypto.php for values. |
|
| 574 | - * |
|
| 575 | - * @access public |
|
| 576 | - * @return false on error, true on success and 0 if there isn't enough data and the |
|
| 577 | - * user should try again (non-blocking sockets only). A PEAR_Error object |
|
| 578 | - * is returned if the socket is not connected |
|
| 579 | - */ |
|
| 580 | - public function enableCrypto($enabled, $type) |
|
| 581 | - { |
|
| 582 | - if (version_compare(phpversion(), "5.1.0", ">=")) { |
|
| 583 | - if (!is_resource($this->fp)) { |
|
| 584 | - return $this->raiseError('not connected'); |
|
| 585 | - } |
|
| 586 | - return @stream_socket_enable_crypto($this->fp, $enabled, $type); |
|
| 587 | - } else { |
|
| 588 | - return $this->raiseError('Net_Socket::enableCrypto() requires php version >= 5.1.0'); |
|
| 589 | - } |
|
| 590 | - } |
|
| 37 | + /** |
|
| 38 | + * Socket file pointer. |
|
| 39 | + * @var resource $fp |
|
| 40 | + */ |
|
| 41 | + public $fp = null; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Whether the socket is blocking. Defaults to true. |
|
| 45 | + * @var boolean $blocking |
|
| 46 | + */ |
|
| 47 | + public $blocking = true; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Whether the socket is persistent. Defaults to false. |
|
| 51 | + * @var boolean $persistent |
|
| 52 | + */ |
|
| 53 | + public $persistent = false; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The IP address to connect to. |
|
| 57 | + * @var string $addr |
|
| 58 | + */ |
|
| 59 | + public $addr = ''; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * The port number to connect to. |
|
| 63 | + * @var integer $port |
|
| 64 | + */ |
|
| 65 | + public $port = 0; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Number of seconds to wait on socket connections before assuming |
|
| 69 | + * there's no more data. Defaults to no timeout. |
|
| 70 | + * @var integer $timeout |
|
| 71 | + */ |
|
| 72 | + public $timeout = false; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Number of bytes to read at a time in readLine() and |
|
| 76 | + * readAll(). Defaults to 2048. |
|
| 77 | + * @var integer $lineLength |
|
| 78 | + */ |
|
| 79 | + public $lineLength = 2048; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Connect to the specified port. If called when the socket is |
|
| 83 | + * already connected, it disconnects and connects again. |
|
| 84 | + * |
|
| 85 | + * @param string $addr IP address or host name. |
|
| 86 | + * @param integer $port TCP port number. |
|
| 87 | + * @param boolean $persistent (optional) Whether the connection is |
|
| 88 | + * persistent (kept open between requests |
|
| 89 | + * by the web server). |
|
| 90 | + * @param integer $timeout (optional) How long to wait for data. |
|
| 91 | + * @param array $options See options for stream_context_create. |
|
| 92 | + * |
|
| 93 | + * @access public |
|
| 94 | + * |
|
| 95 | + * @return boolean | PEAR_Error True on success or a PEAR_Error on failure. |
|
| 96 | + */ |
|
| 97 | + public function connect($addr, $port = 0, $persistent = null, $timeout = null, $options = null) |
|
| 98 | + { |
|
| 99 | + if (is_resource($this->fp)) { |
|
| 100 | + @fclose($this->fp); |
|
| 101 | + $this->fp = null; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + if (!$addr) { |
|
| 105 | + return $this->raiseError('$addr cannot be empty'); |
|
| 106 | + } elseif (strspn($addr, '.0123456789') == strlen($addr) || |
|
| 107 | + strstr($addr, '/') !== false) { |
|
| 108 | + $this->addr = $addr; |
|
| 109 | + } else { |
|
| 110 | + $this->addr = @gethostbyname($addr); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $this->port = $port % 65536; |
|
| 114 | + |
|
| 115 | + if ($persistent !== null) { |
|
| 116 | + $this->persistent = $persistent; |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($timeout !== null) { |
|
| 120 | + $this->timeout = $timeout; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + $openfunc = $this->persistent ? 'pfsockopen' : 'fsockopen'; |
|
| 124 | + $errno = 0; |
|
| 125 | + $errstr = ''; |
|
| 126 | + $old_track_errors = @ini_set('track_errors', 1); |
|
| 127 | + if ($options && function_exists('stream_context_create')) { |
|
| 128 | + if ($this->timeout) { |
|
| 129 | + $timeout = $this->timeout; |
|
| 130 | + } else { |
|
| 131 | + $timeout = 0; |
|
| 132 | + } |
|
| 133 | + $context = stream_context_create($options); |
|
| 134 | + |
|
| 135 | + // Since PHP 5 fsockopen doesn't allow context specification |
|
| 136 | + if (function_exists('stream_socket_client')) { |
|
| 137 | + $flags = $this->persistent ? STREAM_CLIENT_PERSISTENT : STREAM_CLIENT_CONNECT; |
|
| 138 | + $addr = $this->addr . ':' . $this->port; |
|
| 139 | + $fp = stream_socket_client($addr, $errno, $errstr, $timeout, $flags, $context); |
|
| 140 | + } else { |
|
| 141 | + $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $timeout, $context); |
|
| 142 | + } |
|
| 143 | + } else { |
|
| 144 | + if ($this->timeout) { |
|
| 145 | + $fp = @$openfunc($this->addr, $this->port, $errno, $errstr, $this->timeout); |
|
| 146 | + } else { |
|
| 147 | + $fp = @$openfunc($this->addr, $this->port, $errno, $errstr); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if (!$fp) { |
|
| 152 | + if ($errno == 0 && isset($php_errormsg)) { |
|
| 153 | + $errstr = $php_errormsg; |
|
| 154 | + } |
|
| 155 | + @ini_set('track_errors', $old_track_errors); |
|
| 156 | + return $this->raiseError($errstr, $errno); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + @ini_set('track_errors', $old_track_errors); |
|
| 160 | + $this->fp = $fp; |
|
| 161 | + |
|
| 162 | + return $this->setBlocking($this->blocking); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Disconnects from the peer, closes the socket. |
|
| 167 | + * |
|
| 168 | + * @access public |
|
| 169 | + * @return mixed true on success or a PEAR_Error instance otherwise |
|
| 170 | + */ |
|
| 171 | + public function disconnect() |
|
| 172 | + { |
|
| 173 | + if (!is_resource($this->fp)) { |
|
| 174 | + return $this->raiseError('not connected'); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + @fclose($this->fp); |
|
| 178 | + $this->fp = null; |
|
| 179 | + return true; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Find out if the socket is in blocking mode. |
|
| 184 | + * |
|
| 185 | + * @access public |
|
| 186 | + * @return boolean The current blocking mode. |
|
| 187 | + */ |
|
| 188 | + public function isBlocking() |
|
| 189 | + { |
|
| 190 | + return $this->blocking; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Sets whether the socket connection should be blocking or |
|
| 195 | + * not. A read call to a non-blocking socket will return immediately |
|
| 196 | + * if there is no data available, whereas it will block until there |
|
| 197 | + * is data for blocking sockets. |
|
| 198 | + * |
|
| 199 | + * @param boolean $mode True for blocking sockets, false for nonblocking. |
|
| 200 | + * @access public |
|
| 201 | + * @return mixed true on success or a PEAR_Error instance otherwise |
|
| 202 | + */ |
|
| 203 | + public function setBlocking($mode) |
|
| 204 | + { |
|
| 205 | + if (!is_resource($this->fp)) { |
|
| 206 | + return $this->raiseError('not connected'); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + $this->blocking = $mode; |
|
| 210 | + socket_set_blocking($this->fp, $this->blocking); |
|
| 211 | + return true; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Sets the timeout value on socket descriptor, |
|
| 216 | + * expressed in the sum of seconds and microseconds |
|
| 217 | + * |
|
| 218 | + * @param integer $seconds Seconds. |
|
| 219 | + * @param integer $microseconds Microseconds. |
|
| 220 | + * @access public |
|
| 221 | + * @return mixed true on success or a PEAR_Error instance otherwise |
|
| 222 | + */ |
|
| 223 | + public function setTimeout($seconds, $microseconds) |
|
| 224 | + { |
|
| 225 | + if (!is_resource($this->fp)) { |
|
| 226 | + return $this->raiseError('not connected'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return socket_set_timeout($this->fp, $seconds, $microseconds); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Sets the file buffering size on the stream. |
|
| 234 | + * See php's stream_set_write_buffer for more information. |
|
| 235 | + * |
|
| 236 | + * @param integer $size Write buffer size. |
|
| 237 | + * @access public |
|
| 238 | + * @return mixed on success or an PEAR_Error object otherwise |
|
| 239 | + */ |
|
| 240 | + public function setWriteBuffer($size) |
|
| 241 | + { |
|
| 242 | + if (!is_resource($this->fp)) { |
|
| 243 | + return $this->raiseError('not connected'); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $returned = stream_set_write_buffer($this->fp, $size); |
|
| 247 | + if ($returned == 0) { |
|
| 248 | + return true; |
|
| 249 | + } |
|
| 250 | + return $this->raiseError('Cannot set write buffer.'); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Returns information about an existing socket resource. |
|
| 255 | + * Currently returns four entries in the result array: |
|
| 256 | + * |
|
| 257 | + * <p> |
|
| 258 | + * timed_out (bool) - The socket timed out waiting for data<br> |
|
| 259 | + * blocked (bool) - The socket was blocked<br> |
|
| 260 | + * eof (bool) - Indicates EOF event<br> |
|
| 261 | + * unread_bytes (int) - Number of bytes left in the socket buffer<br> |
|
| 262 | + * </p> |
|
| 263 | + * |
|
| 264 | + * @access public |
|
| 265 | + * @return mixed Array containing information about existing socket resource or a PEAR_Error instance otherwise |
|
| 266 | + */ |
|
| 267 | + public function getStatus() |
|
| 268 | + { |
|
| 269 | + if (!is_resource($this->fp)) { |
|
| 270 | + return $this->raiseError('not connected'); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + return socket_get_status($this->fp); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Get a specified line of data |
|
| 278 | + * |
|
| 279 | + * @access public |
|
| 280 | + * @return $size bytes of data from the socket, or a PEAR_Error if |
|
| 281 | + * not connected. |
|
| 282 | + */ |
|
| 283 | + public function gets($size) |
|
| 284 | + { |
|
| 285 | + if (!is_resource($this->fp)) { |
|
| 286 | + return $this->raiseError('not connected'); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return @fgets($this->fp, $size); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Read a specified amount of data. This is guaranteed to return, |
|
| 294 | + * and has the added benefit of getting everything in one fread() |
|
| 295 | + * chunk; if you know the size of the data you're getting |
|
| 296 | + * beforehand, this is definitely the way to go. |
|
| 297 | + * |
|
| 298 | + * @param integer $size The number of bytes to read from the socket. |
|
| 299 | + * @access public |
|
| 300 | + * @return $size bytes of data from the socket, or a PEAR_Error if |
|
| 301 | + * not connected. |
|
| 302 | + */ |
|
| 303 | + public function read($size) |
|
| 304 | + { |
|
| 305 | + if (!is_resource($this->fp)) { |
|
| 306 | + return $this->raiseError('not connected'); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + return @fread($this->fp, $size); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Write a specified amount of data. |
|
| 314 | + * |
|
| 315 | + * @param string $data Data to write. |
|
| 316 | + * @param integer $blocksize Amount of data to write at once. |
|
| 317 | + * NULL means all at once. |
|
| 318 | + * |
|
| 319 | + * @access public |
|
| 320 | + * @return mixed If the socket is not connected, returns an instance of PEAR_Error |
|
| 321 | + * If the write succeeds, returns the number of bytes written |
|
| 322 | + * If the write fails, returns false. |
|
| 323 | + */ |
|
| 324 | + public function write($data, $blocksize = null) |
|
| 325 | + { |
|
| 326 | + if (!is_resource($this->fp)) { |
|
| 327 | + return $this->raiseError('not connected'); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + if (is_null($blocksize) && !OS_WINDOWS) { |
|
| 331 | + return @fwrite($this->fp, $data); |
|
| 332 | + } else { |
|
| 333 | + if (is_null($blocksize)) { |
|
| 334 | + $blocksize = 1024; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $pos = 0; |
|
| 338 | + $size = strlen($data); |
|
| 339 | + while ($pos < $size) { |
|
| 340 | + $written = @fwrite($this->fp, substr($data, $pos, $blocksize)); |
|
| 341 | + if ($written === false) { |
|
| 342 | + return false; |
|
| 343 | + } |
|
| 344 | + $pos += $written; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + return $pos; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Write a line of data to the socket, followed by a trailing "\r\n". |
|
| 353 | + * |
|
| 354 | + * @access public |
|
| 355 | + * @return mixed fputs result, or an error |
|
| 356 | + */ |
|
| 357 | + public function writeLine($data) |
|
| 358 | + { |
|
| 359 | + if (!is_resource($this->fp)) { |
|
| 360 | + return $this->raiseError('not connected'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + return fwrite($this->fp, $data . "\r\n"); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + /** |
|
| 367 | + * Tests for end-of-file on a socket descriptor. |
|
| 368 | + * |
|
| 369 | + * Also returns true if the socket is disconnected. |
|
| 370 | + * |
|
| 371 | + * @access public |
|
| 372 | + * @return bool |
|
| 373 | + */ |
|
| 374 | + public function eof() |
|
| 375 | + { |
|
| 376 | + return (!is_resource($this->fp) || feof($this->fp)); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Reads a byte of data |
|
| 381 | + * |
|
| 382 | + * @access public |
|
| 383 | + * @return 1 byte of data from the socket, or a PEAR_Error if |
|
| 384 | + * not connected. |
|
| 385 | + */ |
|
| 386 | + public function readByte() |
|
| 387 | + { |
|
| 388 | + if (!is_resource($this->fp)) { |
|
| 389 | + return $this->raiseError('not connected'); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return ord(@fread($this->fp, 1)); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Reads a word of data |
|
| 397 | + * |
|
| 398 | + * @access public |
|
| 399 | + * @return 1 word of data from the socket, or a PEAR_Error if |
|
| 400 | + * not connected. |
|
| 401 | + */ |
|
| 402 | + public function readWord() |
|
| 403 | + { |
|
| 404 | + if (!is_resource($this->fp)) { |
|
| 405 | + return $this->raiseError('not connected'); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + $buf = @fread($this->fp, 2); |
|
| 409 | + return (ord($buf[0]) + (ord($buf[1]) << 8)); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Reads an int of data |
|
| 414 | + * |
|
| 415 | + * @access public |
|
| 416 | + * @return integer 1 int of data from the socket, or a PEAR_Error if |
|
| 417 | + * not connected. |
|
| 418 | + */ |
|
| 419 | + public function readInt() |
|
| 420 | + { |
|
| 421 | + if (!is_resource($this->fp)) { |
|
| 422 | + return $this->raiseError('not connected'); |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + $buf = @fread($this->fp, 4); |
|
| 426 | + return (ord($buf[0]) + (ord($buf[1]) << 8) + |
|
| 427 | + (ord($buf[2]) << 16) + (ord($buf[3]) << 24)); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Reads a zero-terminated string of data |
|
| 432 | + * |
|
| 433 | + * @access public |
|
| 434 | + * @return string, or a PEAR_Error if |
|
| 435 | + * not connected. |
|
| 436 | + */ |
|
| 437 | + public function readString() |
|
| 438 | + { |
|
| 439 | + if (!is_resource($this->fp)) { |
|
| 440 | + return $this->raiseError('not connected'); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $string = ''; |
|
| 444 | + while (($char = @fread($this->fp, 1)) != "\x00") { |
|
| 445 | + $string .= $char; |
|
| 446 | + } |
|
| 447 | + return $string; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Reads an IP Address and returns it in a dot formatted string |
|
| 452 | + * |
|
| 453 | + * @access public |
|
| 454 | + * @return Dot formatted string, or a PEAR_Error if |
|
| 455 | + * not connected. |
|
| 456 | + */ |
|
| 457 | + public function readIPAddress() |
|
| 458 | + { |
|
| 459 | + if (!is_resource($this->fp)) { |
|
| 460 | + return $this->raiseError('not connected'); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + $buf = @fread($this->fp, 4); |
|
| 464 | + return sprintf('%d.%d.%d.%d', ord($buf[0]), ord($buf[1]), |
|
| 465 | + ord($buf[2]), ord($buf[3])); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Read until either the end of the socket or a newline, whichever |
|
| 470 | + * comes first. Strips the trailing newline from the returned data. |
|
| 471 | + * |
|
| 472 | + * @access public |
|
| 473 | + * @return All available data up to a newline, without that |
|
| 474 | + * newline, or until the end of the socket, or a PEAR_Error if |
|
| 475 | + * not connected. |
|
| 476 | + */ |
|
| 477 | + public function readLine() |
|
| 478 | + { |
|
| 479 | + if (!is_resource($this->fp)) { |
|
| 480 | + return $this->raiseError('not connected'); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + $line = ''; |
|
| 484 | + $timeout = time() + $this->timeout; |
|
| 485 | + while (!feof($this->fp) && (!$this->timeout || time() < $timeout)) { |
|
| 486 | + $line .= @fgets($this->fp, $this->lineLength); |
|
| 487 | + if (substr($line, -1) == "\n") { |
|
| 488 | + return rtrim($line, "\r\n"); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + return $line; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Read until the socket closes, or until there is no more data in |
|
| 496 | + * the inner PHP buffer. If the inner buffer is empty, in blocking |
|
| 497 | + * mode we wait for at least 1 byte of data. Therefore, in |
|
| 498 | + * blocking mode, if there is no data at all to be read, this |
|
| 499 | + * function will never exit (unless the socket is closed on the |
|
| 500 | + * remote end). |
|
| 501 | + * |
|
| 502 | + * @access public |
|
| 503 | + * |
|
| 504 | + * @return string All data until the socket closes, or a PEAR_Error if |
|
| 505 | + * not connected. |
|
| 506 | + */ |
|
| 507 | + public function readAll() |
|
| 508 | + { |
|
| 509 | + if (!is_resource($this->fp)) { |
|
| 510 | + return $this->raiseError('not connected'); |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + $data = ''; |
|
| 514 | + while (!feof($this->fp)) { |
|
| 515 | + $data .= @fread($this->fp, $this->lineLength); |
|
| 516 | + } |
|
| 517 | + return $data; |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + /** |
|
| 521 | + * Runs the equivalent of the select() system call on the socket |
|
| 522 | + * with a timeout specified by tv_sec and tv_usec. |
|
| 523 | + * |
|
| 524 | + * @param integer $state Which of read/write/error to check for. |
|
| 525 | + * @param integer $tv_sec Number of seconds for timeout. |
|
| 526 | + * @param integer $tv_usec Number of microseconds for timeout. |
|
| 527 | + * |
|
| 528 | + * @access public |
|
| 529 | + * @return False if select fails, integer describing which of read/write/error |
|
| 530 | + * are ready, or PEAR_Error if not connected. |
|
| 531 | + */ |
|
| 532 | + public function select($state, $tv_sec, $tv_usec = 0) |
|
| 533 | + { |
|
| 534 | + if (!is_resource($this->fp)) { |
|
| 535 | + return $this->raiseError('not connected'); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + $read = null; |
|
| 539 | + $write = null; |
|
| 540 | + $except = null; |
|
| 541 | + if ($state & NET_SOCKET_READ) { |
|
| 542 | + $read[] = $this->fp; |
|
| 543 | + } |
|
| 544 | + if ($state & NET_SOCKET_WRITE) { |
|
| 545 | + $write[] = $this->fp; |
|
| 546 | + } |
|
| 547 | + if ($state & NET_SOCKET_ERROR) { |
|
| 548 | + $except[] = $this->fp; |
|
| 549 | + } |
|
| 550 | + if (false === ($sr = stream_select($read, $write, $except, $tv_sec, $tv_usec))) { |
|
| 551 | + return false; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + $result = 0; |
|
| 555 | + if (count($read)) { |
|
| 556 | + $result |= NET_SOCKET_READ; |
|
| 557 | + } |
|
| 558 | + if (count($write)) { |
|
| 559 | + $result |= NET_SOCKET_WRITE; |
|
| 560 | + } |
|
| 561 | + if (count($except)) { |
|
| 562 | + $result |= NET_SOCKET_ERROR; |
|
| 563 | + } |
|
| 564 | + return $result; |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Turns encryption on/off on a connected socket. |
|
| 569 | + * |
|
| 570 | + * @param bool $enabled Set this parameter to true to enable encryption |
|
| 571 | + * and false to disable encryption. |
|
| 572 | + * @param integer $type Type of encryption. See |
|
| 573 | + * http://se.php.net/manual/en/function.stream-socket-enable-crypto.php for values. |
|
| 574 | + * |
|
| 575 | + * @access public |
|
| 576 | + * @return false on error, true on success and 0 if there isn't enough data and the |
|
| 577 | + * user should try again (non-blocking sockets only). A PEAR_Error object |
|
| 578 | + * is returned if the socket is not connected |
|
| 579 | + */ |
|
| 580 | + public function enableCrypto($enabled, $type) |
|
| 581 | + { |
|
| 582 | + if (version_compare(phpversion(), "5.1.0", ">=")) { |
|
| 583 | + if (!is_resource($this->fp)) { |
|
| 584 | + return $this->raiseError('not connected'); |
|
| 585 | + } |
|
| 586 | + return @stream_socket_enable_crypto($this->fp, $enabled, $type); |
|
| 587 | + } else { |
|
| 588 | + return $this->raiseError('Net_Socket::enableCrypto() requires php version >= 5.1.0'); |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | 591 | |
| 592 | 592 | } |