@@ -839,7 +839,7 @@ |
||
| 839 | 839 | * |
| 840 | 840 | * @param array $headers The HTTP headers |
| 841 | 841 | * @param string $data unprocessed request data from client |
| 842 | - * @return mixed value of the message, decoded into a PHP type |
|
| 842 | + * @return false|null value of the message, decoded into a PHP type |
|
| 843 | 843 | * @access private |
| 844 | 844 | */ |
| 845 | 845 | public function parseRequest($headers, $data) |
@@ -619,7 +619,7 @@ |
||
| 619 | 619 | $call_arg = array($class, $method); |
| 620 | 620 | } else { |
| 621 | 621 | $this->debug('in invoke_method, calling instance method using call_user_func_array()'); |
| 622 | - $instance = new $class (); |
|
| 622 | + $instance = new $class(); |
|
| 623 | 623 | $call_arg = array(&$instance, $method); |
| 624 | 624 | } |
| 625 | 625 | if (is_array($this->methodparams)) { |
@@ -169,10 +169,6 @@ discard block |
||
| 169 | 169 | /** |
| 170 | 170 | * establish an HTTP connection |
| 171 | 171 | * |
| 172 | - * @param integer $timeout set connection timeout in seconds |
|
| 173 | - * @param integer $response_timeout set response timeout in seconds |
|
| 174 | - * @return boolean true if connected, false if not |
|
| 175 | - * @access private |
|
| 176 | 172 | */ |
| 177 | 173 | public function connect($connection_timeout=0,$response_timeout=30){ |
| 178 | 174 | // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like |
@@ -729,7 +725,7 @@ discard block |
||
| 729 | 725 | * |
| 730 | 726 | * @param string $data message data |
| 731 | 727 | * @param array $cookies cookies to send |
| 732 | - * @return boolean true if OK, false if problem |
|
| 728 | + * @return boolean|null true if OK, false if problem |
|
| 733 | 729 | * @access private |
| 734 | 730 | */ |
| 735 | 731 | public function sendRequest($data, $cookies = NULL) { |
@@ -1194,6 +1190,10 @@ discard block |
||
| 1194 | 1190 | /* |
| 1195 | 1191 | * TODO: allow a Set-Cookie string to be parsed into multiple cookies |
| 1196 | 1192 | */ |
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * @param string $cookie_str |
|
| 1196 | + */ |
|
| 1197 | 1197 | public function parseCookie($cookie_str) { |
| 1198 | 1198 | $cookie_str = str_replace('; ', ';', $cookie_str) . ';'; |
| 1199 | 1199 | $data = preg_split('/;/', $cookie_str); |
@@ -50,13 +50,13 @@ discard block |
||
| 50 | 50 | // verifyhost: default is 1 |
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | - * constructor |
|
| 54 | - * |
|
| 55 | - * @param string $url The URL to which to connect |
|
| 56 | - * @param array $curl_options User-specified cURL options |
|
| 57 | - * @param boolean $use_curl Whether to try to force cURL use |
|
| 58 | - * @access public |
|
| 59 | - */ |
|
| 53 | + * constructor |
|
| 54 | + * |
|
| 55 | + * @param string $url The URL to which to connect |
|
| 56 | + * @param array $curl_options User-specified cURL options |
|
| 57 | + * @param boolean $use_curl Whether to try to force cURL use |
|
| 58 | + * @access public |
|
| 59 | + */ |
|
| 60 | 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:"); |
@@ -71,12 +71,12 @@ discard block |
||
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | - * sets a cURL option |
|
| 75 | - * |
|
| 76 | - * @param mixed $option The cURL option (always integer?) |
|
| 77 | - * @param mixed $value The cURL option value |
|
| 78 | - * @access private |
|
| 79 | - */ |
|
| 74 | + * sets a cURL option |
|
| 75 | + * |
|
| 76 | + * @param mixed $option The cURL option (always integer?) |
|
| 77 | + * @param mixed $value The cURL option value |
|
| 78 | + * @access private |
|
| 79 | + */ |
|
| 80 | 80 | public function setCurlOption($option, $value) { |
| 81 | 81 | $this->debug("setCurlOption option=$option, value="); |
| 82 | 82 | $this->appendDebug($this->varDump($value)); |
@@ -84,23 +84,23 @@ discard block |
||
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | - * sets an HTTP header |
|
| 88 | - * |
|
| 89 | - * @param string $name The name of the header |
|
| 90 | - * @param string $value The value of the header |
|
| 91 | - * @access private |
|
| 92 | - */ |
|
| 87 | + * sets an HTTP header |
|
| 88 | + * |
|
| 89 | + * @param string $name The name of the header |
|
| 90 | + * @param string $value The value of the header |
|
| 91 | + * @access private |
|
| 92 | + */ |
|
| 93 | 93 | public function setHeader($name, $value) { |
| 94 | 94 | $this->outgoing_headers[$name] = $value; |
| 95 | 95 | $this->debug("set header $name: $value"); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
| 99 | - * unsets an HTTP header |
|
| 100 | - * |
|
| 101 | - * @param string $name The name of the header |
|
| 102 | - * @access private |
|
| 103 | - */ |
|
| 99 | + * unsets an HTTP header |
|
| 100 | + * |
|
| 101 | + * @param string $name The name of the header |
|
| 102 | + * @access private |
|
| 103 | + */ |
|
| 104 | 104 | public function unsetHeader($name) { |
| 105 | 105 | if (isset($this->outgoing_headers[$name])) { |
| 106 | 106 | $this->debug("unset header $name"); |
@@ -109,11 +109,11 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
| 112 | - * sets the URL to which to connect |
|
| 113 | - * |
|
| 114 | - * @param string $url The URL to which to connect |
|
| 115 | - * @access private |
|
| 116 | - */ |
|
| 112 | + * sets the URL to which to connect |
|
| 113 | + * |
|
| 114 | + * @param string $url The URL to which to connect |
|
| 115 | + * @access private |
|
| 116 | + */ |
|
| 117 | 117 | public function setURL($url) { |
| 118 | 118 | $this->url = $url; |
| 119 | 119 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | // add any GET params to path |
| 127 | 127 | if(isset($u['query']) && $u['query'] != ''){ |
| 128 | - $this->path .= '?' . $u['query']; |
|
| 128 | + $this->path .= '?' . $u['query']; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // set default port |
@@ -153,11 +153,11 @@ discard block |
||
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
| 156 | - * gets the I/O method to use |
|
| 157 | - * |
|
| 158 | - * @return string I/O method to use (socket|curl|unknown) |
|
| 159 | - * @access private |
|
| 160 | - */ |
|
| 156 | + * gets the I/O method to use |
|
| 157 | + * |
|
| 158 | + * @return string I/O method to use (socket|curl|unknown) |
|
| 159 | + * @access private |
|
| 160 | + */ |
|
| 161 | 161 | public function io_method() { |
| 162 | 162 | if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) |
| 163 | 163 | return 'curl'; |
@@ -167,13 +167,13 @@ discard block |
||
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
| 170 | - * establish an HTTP connection |
|
| 171 | - * |
|
| 172 | - * @param integer $timeout set connection timeout in seconds |
|
| 173 | - * @param integer $response_timeout set response timeout in seconds |
|
| 174 | - * @return boolean true if connected, false if not |
|
| 175 | - * @access private |
|
| 176 | - */ |
|
| 170 | + * establish an HTTP connection |
|
| 171 | + * |
|
| 172 | + * @param integer $timeout set connection timeout in seconds |
|
| 173 | + * @param integer $response_timeout set response timeout in seconds |
|
| 174 | + * @return boolean true if connected, false if not |
|
| 175 | + * @access private |
|
| 176 | + */ |
|
| 177 | 177 | public function connect($connection_timeout=0,$response_timeout=30){ |
| 178 | 178 | // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like |
| 179 | 179 | // "regular" socket. |
@@ -399,15 +399,15 @@ discard block |
||
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | /** |
| 402 | - * sends the SOAP request and gets the SOAP response via HTTP[S] |
|
| 403 | - * |
|
| 404 | - * @param string $data message data |
|
| 405 | - * @param integer $timeout set connection timeout in seconds |
|
| 406 | - * @param integer $response_timeout set response timeout in seconds |
|
| 407 | - * @param array $cookies cookies to send |
|
| 408 | - * @return string data |
|
| 409 | - * @access public |
|
| 410 | - */ |
|
| 402 | + * sends the SOAP request and gets the SOAP response via HTTP[S] |
|
| 403 | + * |
|
| 404 | + * @param string $data message data |
|
| 405 | + * @param integer $timeout set connection timeout in seconds |
|
| 406 | + * @param integer $response_timeout set response timeout in seconds |
|
| 407 | + * @param array $cookies cookies to send |
|
| 408 | + * @return string data |
|
| 409 | + * @access public |
|
| 410 | + */ |
|
| 411 | 411 | public function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) { |
| 412 | 412 | |
| 413 | 413 | $this->debug('entered send() with data of length: '.strlen($data)); |
@@ -439,30 +439,30 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | |
| 441 | 441 | /** |
| 442 | - * sends the SOAP request and gets the SOAP response via HTTPS using CURL |
|
| 443 | - * |
|
| 444 | - * @param string $data message data |
|
| 445 | - * @param integer $timeout set connection timeout in seconds |
|
| 446 | - * @param integer $response_timeout set response timeout in seconds |
|
| 447 | - * @param array $cookies cookies to send |
|
| 448 | - * @return string data |
|
| 449 | - * @access public |
|
| 450 | - * @deprecated |
|
| 451 | - */ |
|
| 442 | + * sends the SOAP request and gets the SOAP response via HTTPS using CURL |
|
| 443 | + * |
|
| 444 | + * @param string $data message data |
|
| 445 | + * @param integer $timeout set connection timeout in seconds |
|
| 446 | + * @param integer $response_timeout set response timeout in seconds |
|
| 447 | + * @param array $cookies cookies to send |
|
| 448 | + * @return string data |
|
| 449 | + * @access public |
|
| 450 | + * @deprecated |
|
| 451 | + */ |
|
| 452 | 452 | public function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) { |
| 453 | 453 | return $this->send($data, $timeout, $response_timeout, $cookies); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | /** |
| 457 | - * if authenticating, set user credentials here |
|
| 458 | - * |
|
| 459 | - * @param string $username |
|
| 460 | - * @param string $password |
|
| 461 | - * @param string $authtype (basic|digest|certificate|ntlm) |
|
| 462 | - * @param array $digestRequest (keys must be nonce, nc, realm, qop) |
|
| 463 | - * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
| 464 | - * @access public |
|
| 465 | - */ |
|
| 457 | + * if authenticating, set user credentials here |
|
| 458 | + * |
|
| 459 | + * @param string $username |
|
| 460 | + * @param string $password |
|
| 461 | + * @param string $authtype (basic|digest|certificate|ntlm) |
|
| 462 | + * @param array $digestRequest (keys must be nonce, nc, realm, qop) |
|
| 463 | + * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
| 464 | + * @access public |
|
| 465 | + */ |
|
| 466 | 466 | public function setCredentials($username, $password, $authtype = 'basic', $digestRequest = array(), $certRequest = array()) { |
| 467 | 467 | $this->debug("setCredentials username=$username authtype=$authtype digestRequest="); |
| 468 | 468 | $this->appendDebug($this->varDump($digestRequest)); |
@@ -532,21 +532,21 @@ discard block |
||
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
| 535 | - * set the soapaction value |
|
| 536 | - * |
|
| 537 | - * @param string $soapaction |
|
| 538 | - * @access public |
|
| 539 | - */ |
|
| 535 | + * set the soapaction value |
|
| 536 | + * |
|
| 537 | + * @param string $soapaction |
|
| 538 | + * @access public |
|
| 539 | + */ |
|
| 540 | 540 | public function setSOAPAction($soapaction) { |
| 541 | 541 | $this->setHeader('SOAPAction', '"' . $soapaction . '"'); |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
| 545 | - * use http encoding |
|
| 546 | - * |
|
| 547 | - * @param string $enc encoding style. supported values: gzip, deflate, or both |
|
| 548 | - * @access public |
|
| 549 | - */ |
|
| 545 | + * use http encoding |
|
| 546 | + * |
|
| 547 | + * @param string $enc encoding style. supported values: gzip, deflate, or both |
|
| 548 | + * @access public |
|
| 549 | + */ |
|
| 550 | 550 | public function setEncoding($enc='gzip, deflate') { |
| 551 | 551 | if (function_exists('gzdeflate')) { |
| 552 | 552 | $this->protocol_version = '1.1'; |
@@ -562,15 +562,15 @@ discard block |
||
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
| 565 | - * set proxy info here |
|
| 566 | - * |
|
| 567 | - * @param string $proxyhost use an empty string to remove proxy |
|
| 568 | - * @param string $proxyport |
|
| 569 | - * @param string $proxyusername |
|
| 570 | - * @param string $proxypassword |
|
| 571 | - * @param string $proxyauthtype (basic|ntlm) |
|
| 572 | - * @access public |
|
| 573 | - */ |
|
| 565 | + * set proxy info here |
|
| 566 | + * |
|
| 567 | + * @param string $proxyhost use an empty string to remove proxy |
|
| 568 | + * @param string $proxyport |
|
| 569 | + * @param string $proxyusername |
|
| 570 | + * @param string $proxypassword |
|
| 571 | + * @param string $proxyauthtype (basic|ntlm) |
|
| 572 | + * @access public |
|
| 573 | + */ |
|
| 574 | 574 | public function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 'basic') { |
| 575 | 575 | if ($proxyhost) { |
| 576 | 576 | $this->proxy = array( |
@@ -617,15 +617,15 @@ discard block |
||
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
| 620 | - * decode a string that is encoded w/ "chunked' transfer encoding |
|
| 621 | - * as defined in RFC2068 19.4.6 |
|
| 622 | - * |
|
| 623 | - * @param string $buffer |
|
| 624 | - * @param string $lb |
|
| 625 | - * @returns string |
|
| 626 | - * @access public |
|
| 627 | - * @deprecated |
|
| 628 | - */ |
|
| 620 | + * decode a string that is encoded w/ "chunked' transfer encoding |
|
| 621 | + * as defined in RFC2068 19.4.6 |
|
| 622 | + * |
|
| 623 | + * @param string $buffer |
|
| 624 | + * @param string $lb |
|
| 625 | + * @returns string |
|
| 626 | + * @access public |
|
| 627 | + * @deprecated |
|
| 628 | + */ |
|
| 629 | 629 | public function decodeChunked($buffer, $lb){ |
| 630 | 630 | // length := 0 |
| 631 | 631 | $length = 0; |
@@ -648,11 +648,11 @@ discard block |
||
| 648 | 648 | |
| 649 | 649 | // Just in case we got a broken connection |
| 650 | 650 | if ($chunkend == FALSE) { |
| 651 | - $chunk = substr($buffer,$chunkstart); |
|
| 651 | + $chunk = substr($buffer,$chunkstart); |
|
| 652 | 652 | // append chunk-data to entity-body |
| 653 | - $new .= $chunk; |
|
| 654 | - $length += strlen($chunk); |
|
| 655 | - break; |
|
| 653 | + $new .= $chunk; |
|
| 654 | + $length += strlen($chunk); |
|
| 655 | + break; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | // read chunk-data and CRLF |
@@ -725,13 +725,13 @@ discard block |
||
| 725 | 725 | } |
| 726 | 726 | |
| 727 | 727 | /** |
| 728 | - * sends the SOAP request via HTTP[S] |
|
| 729 | - * |
|
| 730 | - * @param string $data message data |
|
| 731 | - * @param array $cookies cookies to send |
|
| 732 | - * @return boolean true if OK, false if problem |
|
| 733 | - * @access private |
|
| 734 | - */ |
|
| 728 | + * sends the SOAP request via HTTP[S] |
|
| 729 | + * |
|
| 730 | + * @param string $data message data |
|
| 731 | + * @param array $cookies cookies to send |
|
| 732 | + * @return boolean true if OK, false if problem |
|
| 733 | + * @access private |
|
| 734 | + */ |
|
| 735 | 735 | public function sendRequest($data, $cookies = NULL) { |
| 736 | 736 | // build cookie string |
| 737 | 737 | $cookie_str = $this->getCookiesForRequest($cookies, (($this->scheme == 'ssl') || ($this->scheme == 'https'))); |
@@ -783,18 +783,18 @@ discard block |
||
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | /** |
| 786 | - * gets the SOAP response via HTTP[S] |
|
| 787 | - * |
|
| 788 | - * @return string the response (also sets member variables like incoming_payload) |
|
| 789 | - * @access private |
|
| 790 | - */ |
|
| 786 | + * gets the SOAP response via HTTP[S] |
|
| 787 | + * |
|
| 788 | + * @return string the response (also sets member variables like incoming_payload) |
|
| 789 | + * @access private |
|
| 790 | + */ |
|
| 791 | 791 | public function getResponse(){ |
| 792 | 792 | $this->incoming_payload = ''; |
| 793 | 793 | |
| 794 | 794 | if ($this->io_method() == 'socket') { |
| 795 | - // loop until headers have been retrieved |
|
| 796 | - $data = ''; |
|
| 797 | - while (!isset($lb)){ |
|
| 795 | + // loop until headers have been retrieved |
|
| 796 | + $data = ''; |
|
| 797 | + while (!isset($lb)){ |
|
| 798 | 798 | |
| 799 | 799 | // We might EOF during header read. |
| 800 | 800 | if(feof($this->fp)) { |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | } else { |
| 856 | 856 | $this->debug('did not find cookie in ' . trim($arr[1])); |
| 857 | 857 | } |
| 858 | - } |
|
| 858 | + } |
|
| 859 | 859 | } else if (isset($header_name)) { |
| 860 | 860 | // append continuation line to previous header |
| 861 | 861 | $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line; |
@@ -893,8 +893,8 @@ discard block |
||
| 893 | 893 | $this->debug("chunk length $content_length"); |
| 894 | 894 | } |
| 895 | 895 | $strlen = 0; |
| 896 | - while (($strlen < $content_length) && (!feof($this->fp))) { |
|
| 897 | - $readlen = min(8192, $content_length - $strlen); |
|
| 896 | + while (($strlen < $content_length) && (!feof($this->fp))) { |
|
| 897 | + $readlen = min(8192, $content_length - $strlen); |
|
| 898 | 898 | $tmp = fread($this->fp, $readlen); |
| 899 | 899 | $tmplen = strlen($tmp); |
| 900 | 900 | $this->debug("read buffer of $tmplen bytes"); |
@@ -960,17 +960,17 @@ discard block |
||
| 960 | 960 | $this->incoming_payload = curl_exec($this->ch); |
| 961 | 961 | $data = $this->incoming_payload; |
| 962 | 962 | |
| 963 | - $cErr = curl_error($this->ch); |
|
| 963 | + $cErr = curl_error($this->ch); |
|
| 964 | 964 | if ($cErr != '') { |
| 965 | - $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>'; |
|
| 966 | - // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE |
|
| 965 | + $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>'; |
|
| 966 | + // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE |
|
| 967 | 967 | foreach(curl_getinfo($this->ch) as $k => $v){ |
| 968 | 968 | $err .= "$k: $v<br>"; |
| 969 | 969 | } |
| 970 | 970 | $this->debug($err); |
| 971 | 971 | $this->setError($err); |
| 972 | 972 | curl_close($this->ch); |
| 973 | - return false; |
|
| 973 | + return false; |
|
| 974 | 974 | } else { |
| 975 | 975 | //echo '<pre>'; |
| 976 | 976 | //var_dump(curl_getinfo($this->ch)); |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | } else { |
| 1034 | 1034 | $this->debug('did not find cookie in ' . trim($arr[1])); |
| 1035 | 1035 | } |
| 1036 | - } |
|
| 1036 | + } |
|
| 1037 | 1037 | } else if (isset($header_name)) { |
| 1038 | 1038 | // append continuation line to previous header |
| 1039 | 1039 | $this->incoming_headers[$header_name] .= $lb . ' ' . $header_line; |
@@ -1094,49 +1094,49 @@ discard block |
||
| 1094 | 1094 | // decode content-encoding |
| 1095 | 1095 | if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){ |
| 1096 | 1096 | if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){ |
| 1097 | - // if decoding works, use it. else assume data wasn't gzencoded |
|
| 1098 | - if(function_exists('gzinflate')){ |
|
| 1097 | + // if decoding works, use it. else assume data wasn't gzencoded |
|
| 1098 | + if(function_exists('gzinflate')){ |
|
| 1099 | 1099 | // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress) |
| 1100 | 1100 | // this means there are no Zlib headers, although there should be |
| 1101 | 1101 | $this->debug('The gzinflate function exists'); |
| 1102 | 1102 | $datalen = strlen($data); |
| 1103 | 1103 | if ($this->incoming_headers['content-encoding'] == 'deflate') { |
| 1104 | 1104 | if ($degzdata = @gzinflate($data)) { |
| 1105 | - $data = $degzdata; |
|
| 1106 | - $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes'); |
|
| 1107 | - if (strlen($data) < $datalen) { |
|
| 1108 | - // test for the case that the payload has been compressed twice |
|
| 1109 | - $this->debug('The inflated payload is smaller than the gzipped one; try again'); |
|
| 1105 | + $data = $degzdata; |
|
| 1106 | + $this->debug('The payload has been inflated to ' . strlen($data) . ' bytes'); |
|
| 1107 | + if (strlen($data) < $datalen) { |
|
| 1108 | + // test for the case that the payload has been compressed twice |
|
| 1109 | + $this->debug('The inflated payload is smaller than the gzipped one; try again'); |
|
| 1110 | 1110 | if ($degzdata = @gzinflate($data)) { |
| 1111 | - $data = $degzdata; |
|
| 1112 | - $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes'); |
|
| 1111 | + $data = $degzdata; |
|
| 1112 | + $this->debug('The payload has been inflated again to ' . strlen($data) . ' bytes'); |
|
| 1113 | 1113 | } |
| 1114 | - } |
|
| 1115 | - } else { |
|
| 1116 | - $this->debug('Error using gzinflate to inflate the payload'); |
|
| 1117 | - $this->setError('Error using gzinflate to inflate the payload'); |
|
| 1118 | - } |
|
| 1114 | + } |
|
| 1115 | + } else { |
|
| 1116 | + $this->debug('Error using gzinflate to inflate the payload'); |
|
| 1117 | + $this->setError('Error using gzinflate to inflate the payload'); |
|
| 1118 | + } |
|
| 1119 | 1119 | } elseif ($this->incoming_headers['content-encoding'] == 'gzip') { |
| 1120 | 1120 | if ($degzdata = @gzinflate(substr($data, 10))) { // do our best |
| 1121 | 1121 | $data = $degzdata; |
| 1122 | - $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes'); |
|
| 1123 | - if (strlen($data) < $datalen) { |
|
| 1124 | - // test for the case that the payload has been compressed twice |
|
| 1125 | - $this->debug('The un-gzipped payload is smaller than the gzipped one; try again'); |
|
| 1122 | + $this->debug('The payload has been un-gzipped to ' . strlen($data) . ' bytes'); |
|
| 1123 | + if (strlen($data) < $datalen) { |
|
| 1124 | + // test for the case that the payload has been compressed twice |
|
| 1125 | + $this->debug('The un-gzipped payload is smaller than the gzipped one; try again'); |
|
| 1126 | 1126 | if ($degzdata = @gzinflate(substr($data, 10))) { |
| 1127 | - $data = $degzdata; |
|
| 1128 | - $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes'); |
|
| 1127 | + $data = $degzdata; |
|
| 1128 | + $this->debug('The payload has been un-gzipped again to ' . strlen($data) . ' bytes'); |
|
| 1129 | 1129 | } |
| 1130 | - } |
|
| 1131 | - } else { |
|
| 1132 | - $this->debug('Error using gzinflate to un-gzip the payload'); |
|
| 1130 | + } |
|
| 1131 | + } else { |
|
| 1132 | + $this->debug('Error using gzinflate to un-gzip the payload'); |
|
| 1133 | 1133 | $this->setError('Error using gzinflate to un-gzip the payload'); |
| 1134 | - } |
|
| 1134 | + } |
|
| 1135 | 1135 | } |
| 1136 | 1136 | //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; |
| 1137 | 1137 | // set decoded payload |
| 1138 | 1138 | $this->incoming_payload = $header_data.$lb.$lb.$data; |
| 1139 | - } else { |
|
| 1139 | + } else { |
|
| 1140 | 1140 | $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
| 1141 | 1141 | $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
| 1142 | 1142 | } |
@@ -1239,7 +1239,7 @@ discard block |
||
| 1239 | 1239 | $name = substr($value_str, 0, $sep_pos); |
| 1240 | 1240 | $value = substr($value_str, $sep_pos + 1); |
| 1241 | 1241 | $cookie= array( 'name' => $name, |
| 1242 | - 'value' => $value, |
|
| 1242 | + 'value' => $value, |
|
| 1243 | 1243 | 'domain' => $domain, |
| 1244 | 1244 | 'path' => $path, |
| 1245 | 1245 | 'expires' => $expires, |
@@ -1265,7 +1265,7 @@ discard block |
||
| 1265 | 1265 | if (! is_array($cookie)) { |
| 1266 | 1266 | continue; |
| 1267 | 1267 | } |
| 1268 | - $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']); |
|
| 1268 | + $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']); |
|
| 1269 | 1269 | if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) { |
| 1270 | 1270 | if (strtotime($cookie['expires']) <= time()) { |
| 1271 | 1271 | $this->debug('cookie has expired'); |
@@ -1291,7 +1291,7 @@ discard block |
||
| 1291 | 1291 | continue; |
| 1292 | 1292 | } |
| 1293 | 1293 | $cookie_str .= $cookie['name'] . '=' . $cookie['value'] . '; '; |
| 1294 | - $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']); |
|
| 1294 | + $this->debug('add cookie to Cookie-String: ' . $cookie['name'] . '=' . $cookie['value']); |
|
| 1295 | 1295 | } |
| 1296 | 1296 | } |
| 1297 | 1297 | return $cookie_str; |
@@ -29,18 +29,18 @@ discard block |
||
| 29 | 29 | var $incoming_cookies = array(); |
| 30 | 30 | var $outgoing_payload = ''; |
| 31 | 31 | var $incoming_payload = ''; |
| 32 | - var $response_status_line; // HTTP response status line |
|
| 32 | + var $response_status_line; // HTTP response status line |
|
| 33 | 33 | var $useSOAPAction = true; |
| 34 | 34 | var $persistentConnection = false; |
| 35 | - var $ch = false; // cURL handle |
|
| 36 | - var $ch_options = array(); // cURL custom options |
|
| 37 | - var $use_curl = false; // force cURL use |
|
| 38 | - var $proxy = null; // proxy information (associative array) |
|
| 35 | + var $ch = false; // cURL handle |
|
| 36 | + var $ch_options = array(); // cURL custom options |
|
| 37 | + var $use_curl = false; // force cURL use |
|
| 38 | + var $proxy = null; // proxy information (associative array) |
|
| 39 | 39 | var $username = ''; |
| 40 | 40 | var $password = ''; |
| 41 | 41 | var $authtype = ''; |
| 42 | 42 | var $digestRequest = array(); |
| 43 | - var $certRequest = array(); // keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional) |
|
| 43 | + var $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 | // For PHP 4.3 with OpenSSL, change https scheme to ssl, then treat like |
| 179 | 179 | // "regular" socket. |
| 180 | 180 | // TODO: disabled for now because OpenSSL must be *compiled* in (not just |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // use persistent connection |
| 201 | - if($this->persistentConnection && isset($this->fp) && is_resource($this->fp)){ |
|
| 201 | + if ($this->persistentConnection && isset($this->fp) && is_resource($this->fp)) { |
|
| 202 | 202 | if (!feof($this->fp)) { |
| 203 | 203 | $this->debug('Re-use persistent connection'); |
| 204 | 204 | return true; |
@@ -214,17 +214,17 @@ discard block |
||
| 214 | 214 | $this->debug('calling fsockopen with host ' . $host . ' connection_timeout ' . $connection_timeout); |
| 215 | 215 | |
| 216 | 216 | // open socket |
| 217 | - if($connection_timeout > 0){ |
|
| 218 | - $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str, $connection_timeout); |
|
| 217 | + if ($connection_timeout > 0) { |
|
| 218 | + $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str, $connection_timeout); |
|
| 219 | 219 | } else { |
| 220 | - $this->fp = @fsockopen( $host, $this->port, $this->errno, $this->error_str); |
|
| 220 | + $this->fp = @fsockopen($host, $this->port, $this->errno, $this->error_str); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // test pointer |
| 224 | - if(!$this->fp) { |
|
| 224 | + if (!$this->fp) { |
|
| 225 | 225 | $msg = 'Couldn\'t open socket connection to server ' . $this->url; |
| 226 | 226 | if ($this->errno) { |
| 227 | - $msg .= ', Error ('.$this->errno.'): '.$this->error_str; |
|
| 227 | + $msg .= ', Error (' . $this->errno . '): ' . $this->error_str; |
|
| 228 | 228 | } else { |
| 229 | 229 | $msg .= ' prior to connect(). This is often a problem looking up the host name.'; |
| 230 | 230 | } |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | // set response timeout |
| 237 | 237 | $this->debug('set response timeout to ' . $response_timeout); |
| 238 | - socket_set_timeout( $this->fp, $response_timeout); |
|
| 238 | + socket_set_timeout($this->fp, $response_timeout); |
|
| 239 | 239 | |
| 240 | 240 | $this->debug('socket connected'); |
| 241 | 241 | return true; |
@@ -374,13 +374,13 @@ discard block |
||
| 374 | 374 | if (is_array($this->proxy)) { |
| 375 | 375 | $this->debug('set cURL proxy options'); |
| 376 | 376 | if ($this->proxy['port'] != '') { |
| 377 | - $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'].':'.$this->proxy['port']); |
|
| 377 | + $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host'] . ':' . $this->proxy['port']); |
|
| 378 | 378 | } else { |
| 379 | 379 | $this->setCurlOption(CURLOPT_PROXY, $this->proxy['host']); |
| 380 | 380 | } |
| 381 | 381 | if ($this->proxy['username'] || $this->proxy['password']) { |
| 382 | 382 | $this->debug('set cURL proxy authentication options'); |
| 383 | - $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'].':'.$this->proxy['password']); |
|
| 383 | + $this->setCurlOption(CURLOPT_PROXYUSERPWD, $this->proxy['username'] . ':' . $this->proxy['password']); |
|
| 384 | 384 | if ($this->proxy['authtype'] == 'basic') { |
| 385 | 385 | $this->setCurlOption($CURLOPT_PROXYAUTH, $CURLAUTH_BASIC); |
| 386 | 386 | } |
@@ -408,9 +408,9 @@ discard block |
||
| 408 | 408 | * @return string data |
| 409 | 409 | * @access public |
| 410 | 410 | */ |
| 411 | - public function send($data, $timeout=0, $response_timeout=30, $cookies=NULL) { |
|
| 411 | + public function send($data, $timeout = 0, $response_timeout = 30, $cookies = NULL) { |
|
| 412 | 412 | |
| 413 | - $this->debug('entered send() with data of length: '.strlen($data)); |
|
| 413 | + $this->debug('entered send() with data of length: ' . strlen($data)); |
|
| 414 | 414 | |
| 415 | 415 | $this->tryagain = true; |
| 416 | 416 | $tries = 0; |
@@ -418,12 +418,12 @@ discard block |
||
| 418 | 418 | $this->tryagain = false; |
| 419 | 419 | if ($tries++ < 2) { |
| 420 | 420 | // make connnection |
| 421 | - if (!$this->connect($timeout, $response_timeout)){ |
|
| 421 | + if (!$this->connect($timeout, $response_timeout)) { |
|
| 422 | 422 | return false; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // send request |
| 426 | - if (!$this->sendRequest($data, $cookies)){ |
|
| 426 | + if (!$this->sendRequest($data, $cookies)) { |
|
| 427 | 427 | return false; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * @access public |
| 450 | 450 | * @deprecated |
| 451 | 451 | */ |
| 452 | - public function sendHTTPS($data, $timeout=0, $response_timeout=30, $cookies) { |
|
| 452 | + public function sendHTTPS($data, $timeout = 0, $response_timeout = 30, $cookies) { |
|
| 453 | 453 | return $this->send($data, $timeout, $response_timeout, $cookies); |
| 454 | 454 | } |
| 455 | 455 | |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | $this->appendDebug($this->varDump($certRequest)); |
| 471 | 471 | // cf. RFC 2617 |
| 472 | 472 | if ($authtype == 'basic') { |
| 473 | - $this->setHeader('Authorization', 'Basic '.base64_encode(str_replace(':','',$username).':'.$password)); |
|
| 473 | + $this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password)); |
|
| 474 | 474 | } elseif ($authtype == 'digest') { |
| 475 | 475 | if (isset($digestRequest['nonce'])) { |
| 476 | 476 | $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1; |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html) |
| 479 | 479 | |
| 480 | 480 | // A1 = unq(username-value) ":" unq(realm-value) ":" passwd |
| 481 | - $A1 = $username. ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; |
|
| 481 | + $A1 = $username . ':' . (isset($digestRequest['realm']) ? $digestRequest['realm'] : '') . ':' . $password; |
|
| 482 | 482 | |
| 483 | 483 | // H(A1) = MD5(A1) |
| 484 | 484 | $HA1 = md5($A1); |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | $A2 = $this->request_method . ':' . $this->digest_uri; |
| 488 | 488 | |
| 489 | 489 | // H(A2) |
| 490 | - $HA2 = md5($A2); |
|
| 490 | + $HA2 = md5($A2); |
|
| 491 | 491 | |
| 492 | 492 | // KD(secret, data) = H(concat(secret, ":", data)) |
| 493 | 493 | // if qop == auth: |
@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | * @param string $enc encoding style. supported values: gzip, deflate, or both |
| 548 | 548 | * @access public |
| 549 | 549 | */ |
| 550 | - public function setEncoding($enc='gzip, deflate') { |
|
| 550 | + public function setEncoding($enc = 'gzip, deflate') { |
|
| 551 | 551 | if (function_exists('gzdeflate')) { |
| 552 | 552 | $this->protocol_version = '1.1'; |
| 553 | 553 | $this->setHeader('Accept-Encoding', $enc); |
@@ -581,7 +581,7 @@ discard block |
||
| 581 | 581 | 'authtype' => $proxyauthtype |
| 582 | 582 | ); |
| 583 | 583 | if ($proxyusername != '' && $proxypassword != '' && $proxyauthtype = 'basic') { |
| 584 | - $this->setHeader('Proxy-Authorization', ' Basic '.base64_encode($proxyusername.':'.$proxypassword)); |
|
| 584 | + $this->setHeader('Proxy-Authorization', ' Basic ' . base64_encode($proxyusername . ':' . $proxypassword)); |
|
| 585 | 585 | } |
| 586 | 586 | } else { |
| 587 | 587 | $this->debug('remove proxy'); |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | * @access private |
| 601 | 601 | */ |
| 602 | 602 | public function isSkippableCurlHeader(&$data) { |
| 603 | - $skipHeaders = array( 'HTTP/1.1 100', |
|
| 603 | + $skipHeaders = array('HTTP/1.1 100', |
|
| 604 | 604 | 'HTTP/1.0 301', |
| 605 | 605 | 'HTTP/1.1 301', |
| 606 | 606 | 'HTTP/1.0 302', |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | * @access public |
| 627 | 627 | * @deprecated |
| 628 | 628 | */ |
| 629 | - public function decodeChunked($buffer, $lb){ |
|
| 629 | + public function decodeChunked($buffer, $lb) { |
|
| 630 | 630 | // length := 0 |
| 631 | 631 | $length = 0; |
| 632 | 632 | $new = ''; |
@@ -638,17 +638,17 @@ discard block |
||
| 638 | 638 | $this->debug('no linebreak found in decodeChunked'); |
| 639 | 639 | return $new; |
| 640 | 640 | } |
| 641 | - $temp = substr($buffer,0,$chunkend); |
|
| 642 | - $chunk_size = hexdec( trim($temp) ); |
|
| 641 | + $temp = substr($buffer, 0, $chunkend); |
|
| 642 | + $chunk_size = hexdec(trim($temp)); |
|
| 643 | 643 | $chunkstart = $chunkend + strlen($lb); |
| 644 | 644 | // while (chunk-size > 0) { |
| 645 | 645 | while ($chunk_size > 0) { |
| 646 | 646 | $this->debug("chunkstart: $chunkstart chunk_size: $chunk_size"); |
| 647 | - $chunkend = strpos( $buffer, $lb, $chunkstart + $chunk_size); |
|
| 647 | + $chunkend = strpos($buffer, $lb, $chunkstart + $chunk_size); |
|
| 648 | 648 | |
| 649 | 649 | // Just in case we got a broken connection |
| 650 | 650 | if ($chunkend == FALSE) { |
| 651 | - $chunk = substr($buffer,$chunkstart); |
|
| 651 | + $chunk = substr($buffer, $chunkstart); |
|
| 652 | 652 | // append chunk-data to entity-body |
| 653 | 653 | $new .= $chunk; |
| 654 | 654 | $length += strlen($chunk); |
@@ -656,7 +656,7 @@ discard block |
||
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | // read chunk-data and CRLF |
| 659 | - $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
| 659 | + $chunk = substr($buffer, $chunkstart, $chunkend - $chunkstart); |
|
| 660 | 660 | // append chunk-data to entity-body |
| 661 | 661 | $new .= $chunk; |
| 662 | 662 | // length := length + chunk-size |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | if ($chunkend == FALSE) { |
| 669 | 669 | break; //Just in case we got a broken connection |
| 670 | 670 | } |
| 671 | - $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart); |
|
| 672 | - $chunk_size = hexdec( trim($temp) ); |
|
| 671 | + $temp = substr($buffer, $chunkstart, $chunkend - $chunkstart); |
|
| 672 | + $chunk_size = hexdec(trim($temp)); |
|
| 673 | 673 | $chunkstart = $chunkend; |
| 674 | 674 | } |
| 675 | 675 | return $new; |
@@ -704,15 +704,15 @@ discard block |
||
| 704 | 704 | $this->outgoing_payload = "$req\r\n"; |
| 705 | 705 | |
| 706 | 706 | // loop thru headers, serializing |
| 707 | - foreach($this->outgoing_headers as $k => $v){ |
|
| 708 | - $hdr = $k.': '.$v; |
|
| 707 | + foreach ($this->outgoing_headers as $k => $v) { |
|
| 708 | + $hdr = $k . ': ' . $v; |
|
| 709 | 709 | $this->debug("HTTP header: $hdr"); |
| 710 | 710 | $this->outgoing_payload .= "$hdr\r\n"; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | // add any cookies |
| 714 | 714 | if ($cookie_str != '') { |
| 715 | - $hdr = 'Cookie: '.$cookie_str; |
|
| 715 | + $hdr = 'Cookie: ' . $cookie_str; |
|
| 716 | 716 | $this->debug("HTTP header: $hdr"); |
| 717 | 717 | $this->outgoing_payload .= "$hdr\r\n"; |
| 718 | 718 | } |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | |
| 742 | 742 | if ($this->io_method() == 'socket') { |
| 743 | 743 | // send payload |
| 744 | - if(!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { |
|
| 744 | + if (!fputs($this->fp, $this->outgoing_payload, strlen($this->outgoing_payload))) { |
|
| 745 | 745 | $this->setError('couldn\'t write message data to socket'); |
| 746 | 746 | $this->debug('couldn\'t write message data to socket'); |
| 747 | 747 | return false; |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | // turns out that the URI and HTTP version are appended to this, which |
| 755 | 755 | // some servers refuse to work with (so we no longer use this method!) |
| 756 | 756 | $curl_headers = array(); |
| 757 | - foreach($this->outgoing_headers as $k => $v){ |
|
| 757 | + foreach ($this->outgoing_headers as $k => $v) { |
|
| 758 | 758 | if ($k == 'Connection' || $k == 'Content-Length' || $k == 'Host' || $k == 'Authorization' || $k == 'Proxy-Authorization') { |
| 759 | 759 | $this->debug("Skip cURL header $k: $v"); |
| 760 | 760 | } else { |
@@ -788,16 +788,16 @@ discard block |
||
| 788 | 788 | * @return string the response (also sets member variables like incoming_payload) |
| 789 | 789 | * @access private |
| 790 | 790 | */ |
| 791 | - public function getResponse(){ |
|
| 791 | + public function getResponse() { |
|
| 792 | 792 | $this->incoming_payload = ''; |
| 793 | 793 | |
| 794 | 794 | if ($this->io_method() == 'socket') { |
| 795 | 795 | // loop until headers have been retrieved |
| 796 | 796 | $data = ''; |
| 797 | - while (!isset($lb)){ |
|
| 797 | + while (!isset($lb)) { |
|
| 798 | 798 | |
| 799 | 799 | // We might EOF during header read. |
| 800 | - if(feof($this->fp)) { |
|
| 800 | + if (feof($this->fp)) { |
|
| 801 | 801 | $this->incoming_payload = $data; |
| 802 | 802 | $this->debug('found no headers before EOF after length ' . strlen($data)); |
| 803 | 803 | $this->debug("received before EOF:\n" . $data); |
@@ -818,17 +818,17 @@ discard block |
||
| 818 | 818 | } |
| 819 | 819 | |
| 820 | 820 | $data .= $tmp; |
| 821 | - $pos = strpos($data,"\r\n\r\n"); |
|
| 822 | - if($pos > 1){ |
|
| 821 | + $pos = strpos($data, "\r\n\r\n"); |
|
| 822 | + if ($pos > 1) { |
|
| 823 | 823 | $lb = "\r\n"; |
| 824 | 824 | } else { |
| 825 | - $pos = strpos($data,"\n\n"); |
|
| 826 | - if($pos > 1){ |
|
| 825 | + $pos = strpos($data, "\n\n"); |
|
| 826 | + if ($pos > 1) { |
|
| 827 | 827 | $lb = "\n"; |
| 828 | 828 | } |
| 829 | 829 | } |
| 830 | 830 | // remove 100 headers |
| 831 | - if (isset($lb) && preg_match('/^HTTP\/1.1 100/',$data)) { |
|
| 831 | + if (isset($lb) && preg_match('/^HTTP\/1.1 100/', $data)) { |
|
| 832 | 832 | unset($lb); |
| 833 | 833 | $data = ''; |
| 834 | 834 | }// |
@@ -837,13 +837,13 @@ discard block |
||
| 837 | 837 | $this->incoming_payload .= $data; |
| 838 | 838 | $this->debug('found end of headers after length ' . strlen($data)); |
| 839 | 839 | // process headers |
| 840 | - $header_data = trim(substr($data,0,$pos)); |
|
| 841 | - $header_array = explode($lb,$header_data); |
|
| 840 | + $header_data = trim(substr($data, 0, $pos)); |
|
| 841 | + $header_array = explode($lb, $header_data); |
|
| 842 | 842 | $this->incoming_headers = array(); |
| 843 | 843 | $this->incoming_cookies = array(); |
| 844 | - foreach($header_array as $header_line){ |
|
| 845 | - $arr = explode(':',$header_line, 2); |
|
| 846 | - if(count($arr) > 1){ |
|
| 844 | + foreach ($header_array as $header_line) { |
|
| 845 | + $arr = explode(':', $header_line, 2); |
|
| 846 | + if (count($arr) > 1) { |
|
| 847 | 847 | $header_name = strtolower(trim($arr[0])); |
| 848 | 848 | $this->incoming_headers[$header_name] = trim($arr[1]); |
| 849 | 849 | if ($header_name == 'set-cookie') { |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | |
| 865 | 865 | // loop until msg has been received |
| 866 | 866 | if (isset($this->incoming_headers['transfer-encoding']) && strtolower($this->incoming_headers['transfer-encoding']) == 'chunked') { |
| 867 | - $content_length = 2147483647; // ignore any content-length header |
|
| 867 | + $content_length = 2147483647; // ignore any content-length header |
|
| 868 | 868 | $chunked = true; |
| 869 | 869 | $this->debug("want to read chunked content"); |
| 870 | 870 | } elseif (isset($this->incoming_headers['content-length'])) { |
@@ -872,7 +872,7 @@ discard block |
||
| 872 | 872 | $chunked = false; |
| 873 | 873 | $this->debug("want to read content of length $content_length"); |
| 874 | 874 | } else { |
| 875 | - $content_length = 2147483647; |
|
| 875 | + $content_length = 2147483647; |
|
| 876 | 876 | $chunked = false; |
| 877 | 877 | $this->debug("want to read content to EOF"); |
| 878 | 878 | } |
@@ -926,19 +926,19 @@ discard block |
||
| 926 | 926 | } |
| 927 | 927 | $this->debug('read body of length ' . strlen($data)); |
| 928 | 928 | $this->incoming_payload .= $data; |
| 929 | - $this->debug('received a total of '.strlen($this->incoming_payload).' bytes of data from server'); |
|
| 929 | + $this->debug('received a total of ' . strlen($this->incoming_payload) . ' bytes of data from server'); |
|
| 930 | 930 | |
| 931 | 931 | // close filepointer |
| 932 | - if( |
|
| 932 | + if ( |
|
| 933 | 933 | (isset($this->incoming_headers['connection']) && strtolower($this->incoming_headers['connection']) == 'close') || |
| 934 | - (! $this->persistentConnection) || feof($this->fp)){ |
|
| 934 | + (!$this->persistentConnection) || feof($this->fp)) { |
|
| 935 | 935 | fclose($this->fp); |
| 936 | 936 | $this->fp = false; |
| 937 | 937 | $this->debug('closed socket'); |
| 938 | 938 | } |
| 939 | 939 | |
| 940 | 940 | // connection was closed unexpectedly |
| 941 | - if($this->incoming_payload == ''){ |
|
| 941 | + if ($this->incoming_payload == '') { |
|
| 942 | 942 | $this->setError('no response from server'); |
| 943 | 943 | return false; |
| 944 | 944 | } |
@@ -962,9 +962,9 @@ discard block |
||
| 962 | 962 | |
| 963 | 963 | $cErr = curl_error($this->ch); |
| 964 | 964 | if ($cErr != '') { |
| 965 | - $err = 'cURL ERROR: '.curl_errno($this->ch).': '.$cErr.'<br>'; |
|
| 965 | + $err = 'cURL ERROR: ' . curl_errno($this->ch) . ': ' . $cErr . '<br>'; |
|
| 966 | 966 | // TODO: there is a PHP bug that can cause this to SEGV for CURLINFO_CONTENT_TYPE |
| 967 | - foreach(curl_getinfo($this->ch) as $k => $v){ |
|
| 967 | + foreach (curl_getinfo($this->ch) as $k => $v) { |
|
| 968 | 968 | $err .= "$k: $v<br>"; |
| 969 | 969 | } |
| 970 | 970 | $this->debug($err); |
@@ -984,44 +984,44 @@ discard block |
||
| 984 | 984 | $savedata = $data; |
| 985 | 985 | while ($this->isSkippableCurlHeader($data)) { |
| 986 | 986 | $this->debug("Found HTTP header to skip"); |
| 987 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
| 988 | - $data = ltrim(substr($data,$pos)); |
|
| 989 | - } elseif($pos = strpos($data,"\n\n") ) { |
|
| 990 | - $data = ltrim(substr($data,$pos)); |
|
| 987 | + if ($pos = strpos($data, "\r\n\r\n")) { |
|
| 988 | + $data = ltrim(substr($data, $pos)); |
|
| 989 | + } elseif ($pos = strpos($data, "\n\n")) { |
|
| 990 | + $data = ltrim(substr($data, $pos)); |
|
| 991 | 991 | } |
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | if ($data == '') { |
| 995 | 995 | // have nothing left; just remove 100 header(s) |
| 996 | 996 | $data = $savedata; |
| 997 | - while (preg_match('/^HTTP\/1.1 100/',$data)) { |
|
| 998 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
| 999 | - $data = ltrim(substr($data,$pos)); |
|
| 1000 | - } elseif($pos = strpos($data,"\n\n") ) { |
|
| 1001 | - $data = ltrim(substr($data,$pos)); |
|
| 997 | + while (preg_match('/^HTTP\/1.1 100/', $data)) { |
|
| 998 | + if ($pos = strpos($data, "\r\n\r\n")) { |
|
| 999 | + $data = ltrim(substr($data, $pos)); |
|
| 1000 | + } elseif ($pos = strpos($data, "\n\n")) { |
|
| 1001 | + $data = ltrim(substr($data, $pos)); |
|
| 1002 | 1002 | } |
| 1003 | 1003 | } |
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | // separate content from HTTP headers |
| 1007 | - if ($pos = strpos($data,"\r\n\r\n")) { |
|
| 1007 | + if ($pos = strpos($data, "\r\n\r\n")) { |
|
| 1008 | 1008 | $lb = "\r\n"; |
| 1009 | - } elseif( $pos = strpos($data,"\n\n")) { |
|
| 1009 | + } elseif ($pos = strpos($data, "\n\n")) { |
|
| 1010 | 1010 | $lb = "\n"; |
| 1011 | 1011 | } else { |
| 1012 | 1012 | $this->debug('no proper separation of headers and document'); |
| 1013 | 1013 | $this->setError('no proper separation of headers and document'); |
| 1014 | 1014 | return false; |
| 1015 | 1015 | } |
| 1016 | - $header_data = trim(substr($data,0,$pos)); |
|
| 1017 | - $header_array = explode($lb,$header_data); |
|
| 1018 | - $data = ltrim(substr($data,$pos)); |
|
| 1016 | + $header_data = trim(substr($data, 0, $pos)); |
|
| 1017 | + $header_array = explode($lb, $header_data); |
|
| 1018 | + $data = ltrim(substr($data, $pos)); |
|
| 1019 | 1019 | $this->debug('found proper separation of headers and document'); |
| 1020 | - $this->debug('cleaned data, stringlen: '.strlen($data)); |
|
| 1020 | + $this->debug('cleaned data, stringlen: ' . strlen($data)); |
|
| 1021 | 1021 | // clean headers |
| 1022 | 1022 | foreach ($header_array as $header_line) { |
| 1023 | - $arr = explode(':',$header_line,2); |
|
| 1024 | - if(count($arr) > 1){ |
|
| 1023 | + $arr = explode(':', $header_line, 2); |
|
| 1024 | + if (count($arr) > 1) { |
|
| 1025 | 1025 | $header_name = strtolower(trim($arr[0])); |
| 1026 | 1026 | $this->incoming_headers[$header_name] = trim($arr[1]); |
| 1027 | 1027 | if ($header_name == 'set-cookie') { |
@@ -1092,10 +1092,10 @@ discard block |
||
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | // decode content-encoding |
| 1095 | - if(isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != ''){ |
|
| 1096 | - if(strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip'){ |
|
| 1095 | + if (isset($this->incoming_headers['content-encoding']) && $this->incoming_headers['content-encoding'] != '') { |
|
| 1096 | + if (strtolower($this->incoming_headers['content-encoding']) == 'deflate' || strtolower($this->incoming_headers['content-encoding']) == 'gzip') { |
|
| 1097 | 1097 | // if decoding works, use it. else assume data wasn't gzencoded |
| 1098 | - if(function_exists('gzinflate')){ |
|
| 1098 | + if (function_exists('gzinflate')) { |
|
| 1099 | 1099 | // IIS 5 requires gzinflate instead of gzuncompress (similar to IE 5 and gzdeflate v. gzcompress) |
| 1100 | 1100 | // this means there are no Zlib headers, although there should be |
| 1101 | 1101 | $this->debug('The gzinflate function exists'); |
@@ -1135,7 +1135,7 @@ discard block |
||
| 1135 | 1135 | } |
| 1136 | 1136 | //print "<xmp>\nde-inflated:\n---------------\n$data\n-------------\n</xmp>"; |
| 1137 | 1137 | // set decoded payload |
| 1138 | - $this->incoming_payload = $header_data.$lb.$lb.$data; |
|
| 1138 | + $this->incoming_payload = $header_data . $lb . $lb . $data; |
|
| 1139 | 1139 | } else { |
| 1140 | 1140 | $this->debug('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
| 1141 | 1141 | $this->setError('The server sent compressed data. Your php install must have the Zlib extension compiled in to support this.'); |
@@ -1148,7 +1148,7 @@ discard block |
||
| 1148 | 1148 | $this->debug('No Content-Encoding header'); |
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | - if(strlen($data) == 0){ |
|
| 1151 | + if (strlen($data) == 0) { |
|
| 1152 | 1152 | $this->debug('no data after headers!'); |
| 1153 | 1153 | $this->setError('no data present after HTTP headers'); |
| 1154 | 1154 | return false; |
@@ -1174,7 +1174,7 @@ discard block |
||
| 1174 | 1174 | * @return boolean whether the request was honored by this method. |
| 1175 | 1175 | * @access public |
| 1176 | 1176 | */ |
| 1177 | - public function usePersistentConnection(){ |
|
| 1177 | + public function usePersistentConnection() { |
|
| 1178 | 1178 | if (isset($this->outgoing_headers['Accept-Encoding'])) { |
| 1179 | 1179 | return false; |
| 1180 | 1180 | } |
@@ -1219,7 +1219,7 @@ discard block |
||
| 1219 | 1219 | |
| 1220 | 1220 | $cookie_param = 'path='; |
| 1221 | 1221 | $start = strpos($cookie_str, $cookie_param); |
| 1222 | - if ( $start > 0 ) { |
|
| 1222 | + if ($start > 0) { |
|
| 1223 | 1223 | $path = substr($cookie_str, $start + strlen($cookie_param)); |
| 1224 | 1224 | $path = substr($path, 0, strpos($path, ';')); |
| 1225 | 1225 | } else { |
@@ -1238,7 +1238,7 @@ discard block |
||
| 1238 | 1238 | if ($sep_pos) { |
| 1239 | 1239 | $name = substr($value_str, 0, $sep_pos); |
| 1240 | 1240 | $value = substr($value_str, $sep_pos + 1); |
| 1241 | - $cookie= array( 'name' => $name, |
|
| 1241 | + $cookie = array('name' => $name, |
|
| 1242 | 1242 | 'value' => $value, |
| 1243 | 1243 | 'domain' => $domain, |
| 1244 | 1244 | 'path' => $path, |
@@ -1258,35 +1258,35 @@ discard block |
||
| 1258 | 1258 | * @return string for Cookie-HTTP-Header |
| 1259 | 1259 | * @access private |
| 1260 | 1260 | */ |
| 1261 | - public function getCookiesForRequest($cookies, $secure=false) { |
|
| 1261 | + public function getCookiesForRequest($cookies, $secure = false) { |
|
| 1262 | 1262 | $cookie_str = ''; |
| 1263 | - if ((! is_null($cookies)) && (is_array($cookies))) { |
|
| 1263 | + if ((!is_null($cookies)) && (is_array($cookies))) { |
|
| 1264 | 1264 | foreach ($cookies as $cookie) { |
| 1265 | - if (! is_array($cookie)) { |
|
| 1265 | + if (!is_array($cookie)) { |
|
| 1266 | 1266 | continue; |
| 1267 | 1267 | } |
| 1268 | - $this->debug("check cookie for validity: ".$cookie['name'].'='.$cookie['value']); |
|
| 1269 | - if ((isset($cookie['expires'])) && (! empty($cookie['expires']))) { |
|
| 1268 | + $this->debug("check cookie for validity: " . $cookie['name'] . '=' . $cookie['value']); |
|
| 1269 | + if ((isset($cookie['expires'])) && (!empty($cookie['expires']))) { |
|
| 1270 | 1270 | if (strtotime($cookie['expires']) <= time()) { |
| 1271 | 1271 | $this->debug('cookie has expired'); |
| 1272 | 1272 | continue; |
| 1273 | 1273 | } |
| 1274 | 1274 | } |
| 1275 | - if ((isset($cookie['domain'])) && (! empty($cookie['domain']))) { |
|
| 1275 | + if ((isset($cookie['domain'])) && (!empty($cookie['domain']))) { |
|
| 1276 | 1276 | $domain = preg_quote($cookie['domain']); |
| 1277 | - if (! preg_match("'.*$domain$'i", $this->host)) { |
|
| 1277 | + if (!preg_match("'.*$domain$'i", $this->host)) { |
|
| 1278 | 1278 | $this->debug('cookie has different domain'); |
| 1279 | 1279 | continue; |
| 1280 | 1280 | } |
| 1281 | 1281 | } |
| 1282 | - if ((isset($cookie['path'])) && (! empty($cookie['path']))) { |
|
| 1282 | + if ((isset($cookie['path'])) && (!empty($cookie['path']))) { |
|
| 1283 | 1283 | $path = preg_quote($cookie['path']); |
| 1284 | - if (! preg_match("'^$path.*'i", $this->path)) { |
|
| 1284 | + if (!preg_match("'^$path.*'i", $this->path)) { |
|
| 1285 | 1285 | $this->debug('cookie is for a different path'); |
| 1286 | 1286 | continue; |
| 1287 | 1287 | } |
| 1288 | 1288 | } |
| 1289 | - if ((! $secure) && (isset($cookie['secure'])) && ($cookie['secure'])) { |
|
| 1289 | + if ((!$secure) && (isset($cookie['secure'])) && ($cookie['secure'])) { |
|
| 1290 | 1290 | $this->debug('cookie is secure, transport is not'); |
| 1291 | 1291 | continue; |
| 1292 | 1292 | } |
@@ -159,10 +159,12 @@ discard block |
||
| 159 | 159 | * @access private |
| 160 | 160 | */ |
| 161 | 161 | public function io_method() { |
| 162 | - if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) |
|
| 163 | - return 'curl'; |
|
| 164 | - if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) |
|
| 165 | - return 'socket'; |
|
| 162 | + if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) { |
|
| 163 | + return 'curl'; |
|
| 164 | + } |
|
| 165 | + if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) { |
|
| 166 | + return 'socket'; |
|
| 167 | + } |
|
| 166 | 168 | return 'unknown'; |
| 167 | 169 | } |
| 168 | 170 | |
@@ -246,30 +248,36 @@ discard block |
||
| 246 | 248 | return false; |
| 247 | 249 | } |
| 248 | 250 | // Avoid warnings when PHP does not have these options |
| 249 | - if (defined('CURLOPT_CONNECTIONTIMEOUT')) |
|
| 250 | - $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT; |
|
| 251 | - else |
|
| 252 | - $CURLOPT_CONNECTIONTIMEOUT = 78; |
|
| 253 | - if (defined('CURLOPT_HTTPAUTH')) |
|
| 254 | - $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH; |
|
| 255 | - else |
|
| 256 | - $CURLOPT_HTTPAUTH = 107; |
|
| 257 | - if (defined('CURLOPT_PROXYAUTH')) |
|
| 258 | - $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH; |
|
| 259 | - else |
|
| 260 | - $CURLOPT_PROXYAUTH = 111; |
|
| 261 | - if (defined('CURLAUTH_BASIC')) |
|
| 262 | - $CURLAUTH_BASIC = CURLAUTH_BASIC; |
|
| 263 | - else |
|
| 264 | - $CURLAUTH_BASIC = 1; |
|
| 265 | - if (defined('CURLAUTH_DIGEST')) |
|
| 266 | - $CURLAUTH_DIGEST = CURLAUTH_DIGEST; |
|
| 267 | - else |
|
| 268 | - $CURLAUTH_DIGEST = 2; |
|
| 269 | - if (defined('CURLAUTH_NTLM')) |
|
| 270 | - $CURLAUTH_NTLM = CURLAUTH_NTLM; |
|
| 271 | - else |
|
| 272 | - $CURLAUTH_NTLM = 8; |
|
| 251 | + if (defined('CURLOPT_CONNECTIONTIMEOUT')) { |
|
| 252 | + $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT; |
|
| 253 | + } else { |
|
| 254 | + $CURLOPT_CONNECTIONTIMEOUT = 78; |
|
| 255 | + } |
|
| 256 | + if (defined('CURLOPT_HTTPAUTH')) { |
|
| 257 | + $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH; |
|
| 258 | + } else { |
|
| 259 | + $CURLOPT_HTTPAUTH = 107; |
|
| 260 | + } |
|
| 261 | + if (defined('CURLOPT_PROXYAUTH')) { |
|
| 262 | + $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH; |
|
| 263 | + } else { |
|
| 264 | + $CURLOPT_PROXYAUTH = 111; |
|
| 265 | + } |
|
| 266 | + if (defined('CURLAUTH_BASIC')) { |
|
| 267 | + $CURLAUTH_BASIC = CURLAUTH_BASIC; |
|
| 268 | + } else { |
|
| 269 | + $CURLAUTH_BASIC = 1; |
|
| 270 | + } |
|
| 271 | + if (defined('CURLAUTH_DIGEST')) { |
|
| 272 | + $CURLAUTH_DIGEST = CURLAUTH_DIGEST; |
|
| 273 | + } else { |
|
| 274 | + $CURLAUTH_DIGEST = 2; |
|
| 275 | + } |
|
| 276 | + if (defined('CURLAUTH_NTLM')) { |
|
| 277 | + $CURLAUTH_NTLM = CURLAUTH_NTLM; |
|
| 278 | + } else { |
|
| 279 | + $CURLAUTH_NTLM = 8; |
|
| 280 | + } |
|
| 273 | 281 | |
| 274 | 282 | $this->debug('connect using cURL'); |
| 275 | 283 | // init CURL |
@@ -610,7 +618,9 @@ discard block |
||
| 610 | 618 | 'HTTP/1.0 200 Connection established'); |
| 611 | 619 | foreach ($skipHeaders as $hd) { |
| 612 | 620 | $prefix = substr($data, 0, strlen($hd)); |
| 613 | - if ($prefix == $hd) return true; |
|
| 621 | + if ($prefix == $hd) { |
|
| 622 | + return true; |
|
| 623 | + } |
|
| 614 | 624 | } |
| 615 | 625 | |
| 616 | 626 | return false; |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | * |
| 64 | 64 | * @param string $name optional name |
| 65 | 65 | * @param mixed $type optional type name |
| 66 | - * @param mixed $value optional value |
|
| 66 | + * @param integer $value optional value |
|
| 67 | 67 | * @param mixed $element_ns optional namespace of value |
| 68 | 68 | * @param mixed $type_ns optional namespace of type |
| 69 | 69 | * @param mixed $attributes associative array of attributes to add to element serialization |
@@ -59,16 +59,16 @@ discard block |
||
| 59 | 59 | var $attributes; |
| 60 | 60 | |
| 61 | 61 | /** |
| 62 | - * constructor |
|
| 63 | - * |
|
| 64 | - * @param string $name optional name |
|
| 65 | - * @param mixed $type optional type name |
|
| 66 | - * @param mixed $value optional value |
|
| 67 | - * @param mixed $element_ns optional namespace of value |
|
| 68 | - * @param mixed $type_ns optional namespace of type |
|
| 69 | - * @param mixed $attributes associative array of attributes to add to element serialization |
|
| 70 | - * @access public |
|
| 71 | - */ |
|
| 62 | + * constructor |
|
| 63 | + * |
|
| 64 | + * @param string $name optional name |
|
| 65 | + * @param mixed $type optional type name |
|
| 66 | + * @param mixed $value optional value |
|
| 67 | + * @param mixed $element_ns optional namespace of value |
|
| 68 | + * @param mixed $type_ns optional namespace of type |
|
| 69 | + * @param mixed $attributes associative array of attributes to add to element serialization |
|
| 70 | + * @access public |
|
| 71 | + */ |
|
| 72 | 72 | public function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) { |
| 73 | 73 | parent::nusoap_base(); |
| 74 | 74 | $this->name = $name; |
@@ -77,25 +77,25 @@ discard block |
||
| 77 | 77 | $this->element_ns = $element_ns; |
| 78 | 78 | $this->type_ns = $type_ns; |
| 79 | 79 | $this->attributes = $attributes; |
| 80 | - } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * return serialized value |
|
| 84 | - * |
|
| 85 | - * @param string $use The WSDL use value (encoded|literal) |
|
| 86 | - * @return string XML data |
|
| 87 | - * @access public |
|
| 88 | - */ |
|
| 83 | + * return serialized value |
|
| 84 | + * |
|
| 85 | + * @param string $use The WSDL use value (encoded|literal) |
|
| 86 | + * @return string XML data |
|
| 87 | + * @access public |
|
| 88 | + */ |
|
| 89 | 89 | public function serialize($use='encoded') { |
| 90 | 90 | return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true); |
| 91 | - } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | - * decodes a soapval object into a PHP native type |
|
| 95 | - * |
|
| 96 | - * @return mixed |
|
| 97 | - * @access public |
|
| 98 | - */ |
|
| 94 | + * decodes a soapval object into a PHP native type |
|
| 95 | + * |
|
| 96 | + * @return mixed |
|
| 97 | + * @access public |
|
| 98 | + */ |
|
| 99 | 99 | public function decode(){ |
| 100 | 100 | return $this->value; |
| 101 | 101 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param mixed $attributes associative array of attributes to add to element serialization |
| 70 | 70 | * @access public |
| 71 | 71 | */ |
| 72 | - public function soapval($name='soapval',$type=false,$value=-1,$element_ns=false,$type_ns=false,$attributes=false) { |
|
| 72 | + public function soapval($name = 'soapval', $type = false, $value = -1, $element_ns = false, $type_ns = false, $attributes = false) { |
|
| 73 | 73 | parent::nusoap_base(); |
| 74 | 74 | $this->name = $name; |
| 75 | 75 | $this->type = $type; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @return string XML data |
| 87 | 87 | * @access public |
| 88 | 88 | */ |
| 89 | - public function serialize($use='encoded') { |
|
| 89 | + public function serialize($use = 'encoded') { |
|
| 90 | 90 | return $this->serialize_val($this->value, $this->name, $this->type, $this->element_ns, $this->type_ns, $this->attributes, $use, true); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return mixed |
| 97 | 97 | * @access public |
| 98 | 98 | */ |
| 99 | - public function decode(){ |
|
| 99 | + public function decode() { |
|
| 100 | 100 | return $this->value; |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -88,6 +88,7 @@ discard block |
||
| 88 | 88 | * fetches the WSDL document and parses it |
| 89 | 89 | * |
| 90 | 90 | * @access public |
| 91 | + * @param string $wsdl |
|
| 91 | 92 | */ |
| 92 | 93 | public function fetchWSDL($wsdl) { |
| 93 | 94 | $this->debug("parse and process WSDL path=$wsdl"); |
@@ -882,7 +883,7 @@ discard block |
||
| 882 | 883 | /** |
| 883 | 884 | * serialize the parsed wsdl |
| 884 | 885 | * |
| 885 | - * @param mixed $debug whether to put debug=1 in endpoint URL |
|
| 886 | + * @param integer $debug whether to put debug=1 in endpoint URL |
|
| 886 | 887 | * @return string serialization of WSDL |
| 887 | 888 | * @access public |
| 888 | 889 | */ |
@@ -1105,7 +1106,7 @@ discard block |
||
| 1105 | 1106 | * @param string $direction (input|output) |
| 1106 | 1107 | * @param mixed $parameters parameter value(s) |
| 1107 | 1108 | * @param string $bindingType (soap|soap12) |
| 1108 | - * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
| 1109 | + * @return false|string parameters serialized as XML or false on error (e.g. operation not found) |
|
| 1109 | 1110 | * @access public |
| 1110 | 1111 | */ |
| 1111 | 1112 | public function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') { |
@@ -1205,7 +1206,7 @@ discard block |
||
| 1205 | 1206 | * @param string $operation operation name |
| 1206 | 1207 | * @param string $direction (input|output) |
| 1207 | 1208 | * @param mixed $parameters parameter value(s) |
| 1208 | - * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
| 1209 | + * @return false|string parameters serialized as XML or false on error (e.g. operation not found) |
|
| 1209 | 1210 | * @access public |
| 1210 | 1211 | * @deprecated |
| 1211 | 1212 | */ |
@@ -14,35 +14,35 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class wsdl extends nusoap_base { |
| 16 | 16 | // URL or filename of the root of this WSDL |
| 17 | - var $wsdl; |
|
| 18 | - // define internal arrays of bindings, ports, operations, messages, etc. |
|
| 19 | - var $schemas = array(); |
|
| 20 | - var $currentSchema; |
|
| 21 | - var $message = array(); |
|
| 22 | - var $complexTypes = array(); |
|
| 23 | - var $messages = array(); |
|
| 24 | - var $currentMessage; |
|
| 25 | - var $currentOperation; |
|
| 26 | - var $portTypes = array(); |
|
| 27 | - var $currentPortType; |
|
| 28 | - var $bindings = array(); |
|
| 29 | - var $currentBinding; |
|
| 30 | - var $ports = array(); |
|
| 31 | - var $currentPort; |
|
| 32 | - var $opData = array(); |
|
| 33 | - var $status = ''; |
|
| 34 | - var $documentation = false; |
|
| 35 | - var $endpoint = ''; |
|
| 36 | - // array of wsdl docs to import |
|
| 37 | - var $import = array(); |
|
| 38 | - // parser vars |
|
| 39 | - var $parser; |
|
| 40 | - var $position = 0; |
|
| 41 | - var $depth = 0; |
|
| 42 | - var $depth_array = array(); |
|
| 17 | + var $wsdl; |
|
| 18 | + // define internal arrays of bindings, ports, operations, messages, etc. |
|
| 19 | + var $schemas = array(); |
|
| 20 | + var $currentSchema; |
|
| 21 | + var $message = array(); |
|
| 22 | + var $complexTypes = array(); |
|
| 23 | + var $messages = array(); |
|
| 24 | + var $currentMessage; |
|
| 25 | + var $currentOperation; |
|
| 26 | + var $portTypes = array(); |
|
| 27 | + var $currentPortType; |
|
| 28 | + var $bindings = array(); |
|
| 29 | + var $currentBinding; |
|
| 30 | + var $ports = array(); |
|
| 31 | + var $currentPort; |
|
| 32 | + var $opData = array(); |
|
| 33 | + var $status = ''; |
|
| 34 | + var $documentation = false; |
|
| 35 | + var $endpoint = ''; |
|
| 36 | + // array of wsdl docs to import |
|
| 37 | + var $import = array(); |
|
| 38 | + // parser vars |
|
| 39 | + var $parser; |
|
| 40 | + var $position = 0; |
|
| 41 | + var $depth = 0; |
|
| 42 | + var $depth_array = array(); |
|
| 43 | 43 | // for getting wsdl |
| 44 | 44 | var $proxyhost = ''; |
| 45 | - var $proxyport = ''; |
|
| 45 | + var $proxyport = ''; |
|
| 46 | 46 | var $proxyusername = ''; |
| 47 | 47 | var $proxypassword = ''; |
| 48 | 48 | var $timeout = 0; |
@@ -55,10 +55,10 @@ discard block |
||
| 55 | 55 | var $authtype = ''; // Type of HTTP authentication |
| 56 | 56 | var $certRequest = array(); // Certificate for HTTP SSL authentication |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * constructor |
|
| 60 | - * |
|
| 61 | - * @param string $wsdl WSDL document URL |
|
| 58 | + /** |
|
| 59 | + * constructor |
|
| 60 | + * |
|
| 61 | + * @param string $wsdl WSDL document URL |
|
| 62 | 62 | * @param string $proxyhost |
| 63 | 63 | * @param string $proxyport |
| 64 | 64 | * @param string $proxyusername |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @param integer $response_timeout set the response timeout |
| 68 | 68 | * @param array $curl_options user-specified cURL options |
| 69 | 69 | * @param boolean $use_curl try to use cURL |
| 70 | - * @access public |
|
| 71 | - */ |
|
| 72 | - function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){ |
|
| 70 | + * @access public |
|
| 71 | + */ |
|
| 72 | + function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){ |
|
| 73 | 73 | parent::nusoap_base(); |
| 74 | 74 | $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout"); |
| 75 | - $this->proxyhost = $proxyhost; |
|
| 76 | - $this->proxyport = $proxyport; |
|
| 75 | + $this->proxyhost = $proxyhost; |
|
| 76 | + $this->proxyport = $proxyport; |
|
| 77 | 77 | $this->proxyusername = $proxyusername; |
| 78 | 78 | $this->proxypassword = $proxypassword; |
| 79 | 79 | $this->timeout = $timeout; |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $this->curl_options = $curl_options; |
| 83 | 83 | $this->use_curl = $use_curl; |
| 84 | 84 | $this->fetchWSDL($wsdl); |
| 85 | - } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * fetches the WSDL document and parses it |
@@ -92,30 +92,30 @@ discard block |
||
| 92 | 92 | public function fetchWSDL($wsdl) { |
| 93 | 93 | $this->debug("parse and process WSDL path=$wsdl"); |
| 94 | 94 | $this->wsdl = $wsdl; |
| 95 | - // parse wsdl file |
|
| 96 | - if ($this->wsdl != "") { |
|
| 97 | - $this->parseWSDL($this->wsdl); |
|
| 98 | - } |
|
| 99 | - // imports |
|
| 100 | - // TODO: handle imports more properly, grabbing them in-line and nesting them |
|
| 101 | - $imported_urls = array(); |
|
| 102 | - $imported = 1; |
|
| 103 | - while ($imported > 0) { |
|
| 104 | - $imported = 0; |
|
| 105 | - // Schema imports |
|
| 106 | - foreach ($this->schemas as $ns => $list) { |
|
| 107 | - foreach ($list as $xs) { |
|
| 95 | + // parse wsdl file |
|
| 96 | + if ($this->wsdl != "") { |
|
| 97 | + $this->parseWSDL($this->wsdl); |
|
| 98 | + } |
|
| 99 | + // imports |
|
| 100 | + // TODO: handle imports more properly, grabbing them in-line and nesting them |
|
| 101 | + $imported_urls = array(); |
|
| 102 | + $imported = 1; |
|
| 103 | + while ($imported > 0) { |
|
| 104 | + $imported = 0; |
|
| 105 | + // Schema imports |
|
| 106 | + foreach ($this->schemas as $ns => $list) { |
|
| 107 | + foreach ($list as $xs) { |
|
| 108 | 108 | $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
| 109 | - foreach ($xs->imports as $ns2 => $list2) { |
|
| 110 | - for ($ii = 0; $ii < count($list2); $ii++) { |
|
| 111 | - if (! $list2[$ii]['loaded']) { |
|
| 112 | - /* |
|
| 109 | + foreach ($xs->imports as $ns2 => $list2) { |
|
| 110 | + for ($ii = 0; $ii < count($list2); $ii++) { |
|
| 111 | + if (! $list2[$ii]['loaded']) { |
|
| 112 | + /* |
|
| 113 | 113 | * Substituted with line below |
| 114 | 114 | * because of error "Warning: attempt to modify property of non-object" |
| 115 | 115 | * GitHub issue #1 |
| 116 | 116 | */ |
| 117 | - $list2[$ii]['loaded'] = true; |
|
| 118 | - $url = $list2[$ii]['location']; |
|
| 117 | + $list2[$ii]['loaded'] = true; |
|
| 118 | + $url = $list2[$ii]['location']; |
|
| 119 | 119 | if ($url != '') { |
| 120 | 120 | $urlparts = parse_url($url); |
| 121 | 121 | if (!isset($urlparts['host'])) { |
@@ -123,25 +123,25 @@ discard block |
||
| 123 | 123 | substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
| 124 | 124 | } |
| 125 | 125 | if (! in_array($url, $imported_urls)) { |
| 126 | - $this->parseWSDL($url); |
|
| 127 | - $imported++; |
|
| 128 | - $imported_urls[] = $url; |
|
| 129 | - } |
|
| 126 | + $this->parseWSDL($url); |
|
| 127 | + $imported++; |
|
| 128 | + $imported_urls[] = $url; |
|
| 129 | + } |
|
| 130 | 130 | } else { |
| 131 | 131 | $this->debug("Unexpected scenario: empty URL for unloaded import"); |
| 132 | 132 | } |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - // WSDL imports |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + // WSDL imports |
|
| 139 | 139 | $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
| 140 | - foreach ($this->import as $ns => $list) { |
|
| 141 | - for ($ii = 0; $ii < count($list); $ii++) { |
|
| 142 | - if (! $list[$ii]['loaded']) { |
|
| 143 | - $this->import[$ns][$ii]['loaded'] = true; |
|
| 144 | - $url = $list[$ii]['location']; |
|
| 140 | + foreach ($this->import as $ns => $list) { |
|
| 141 | + for ($ii = 0; $ii < count($list); $ii++) { |
|
| 142 | + if (! $list[$ii]['loaded']) { |
|
| 143 | + $this->import[$ns][$ii]['loaded'] = true; |
|
| 144 | + $url = $list[$ii]['location']; |
|
| 145 | 145 | if ($url != '') { |
| 146 | 146 | $urlparts = parse_url($url); |
| 147 | 147 | if (!isset($urlparts['host'])) { |
@@ -149,70 +149,70 @@ discard block |
||
| 149 | 149 | substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
| 150 | 150 | } |
| 151 | 151 | if (! in_array($url, $imported_urls)) { |
| 152 | - $this->parseWSDL($url); |
|
| 153 | - $imported++; |
|
| 154 | - $imported_urls[] = $url; |
|
| 155 | - } |
|
| 152 | + $this->parseWSDL($url); |
|
| 153 | + $imported++; |
|
| 154 | + $imported_urls[] = $url; |
|
| 155 | + } |
|
| 156 | 156 | } else { |
| 157 | 157 | $this->debug("Unexpected scenario: empty URL for unloaded import"); |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | 160 | } |
| 161 | - } |
|
| 161 | + } |
|
| 162 | 162 | } |
| 163 | - // add new data to operation data |
|
| 164 | - foreach($this->bindings as $binding => $bindingData) { |
|
| 165 | - if (isset($bindingData['operations']) && is_array($bindingData['operations'])) { |
|
| 166 | - foreach($bindingData['operations'] as $operation => $data) { |
|
| 167 | - $this->debug('post-parse data gathering for ' . $operation); |
|
| 168 | - $this->bindings[$binding]['operations'][$operation]['input'] = |
|
| 163 | + // add new data to operation data |
|
| 164 | + foreach($this->bindings as $binding => $bindingData) { |
|
| 165 | + if (isset($bindingData['operations']) && is_array($bindingData['operations'])) { |
|
| 166 | + foreach($bindingData['operations'] as $operation => $data) { |
|
| 167 | + $this->debug('post-parse data gathering for ' . $operation); |
|
| 168 | + $this->bindings[$binding]['operations'][$operation]['input'] = |
|
| 169 | 169 | isset($this->bindings[$binding]['operations'][$operation]['input']) ? |
| 170 | 170 | array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) : |
| 171 | 171 | $this->portTypes[ $bindingData['portType'] ][$operation]['input']; |
| 172 | - $this->bindings[$binding]['operations'][$operation]['output'] = |
|
| 172 | + $this->bindings[$binding]['operations'][$operation]['output'] = |
|
| 173 | 173 | isset($this->bindings[$binding]['operations'][$operation]['output']) ? |
| 174 | 174 | array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) : |
| 175 | 175 | $this->portTypes[ $bindingData['portType'] ][$operation]['output']; |
| 176 | - if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){ |
|
| 176 | + if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){ |
|
| 177 | 177 | $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ]; |
| 178 | 178 | } |
| 179 | 179 | if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){ |
| 180 | - $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; |
|
| 181 | - } |
|
| 182 | - // Set operation style if necessary, but do not override one already provided |
|
| 180 | + $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; |
|
| 181 | + } |
|
| 182 | + // Set operation style if necessary, but do not override one already provided |
|
| 183 | 183 | if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) { |
| 184 | - $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style']; |
|
| 185 | - } |
|
| 186 | - $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : ''; |
|
| 187 | - $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : ''; |
|
| 188 | - $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : ''; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 184 | + $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style']; |
|
| 185 | + } |
|
| 186 | + $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : ''; |
|
| 187 | + $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : ''; |
|
| 188 | + $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : ''; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * parses the wsdl document |
|
| 196 | - * |
|
| 197 | - * @param string $wsdl path or URL |
|
| 198 | - * @access private |
|
| 199 | - */ |
|
| 200 | - function parseWSDL($wsdl = '') { |
|
| 194 | + /** |
|
| 195 | + * parses the wsdl document |
|
| 196 | + * |
|
| 197 | + * @param string $wsdl path or URL |
|
| 198 | + * @access private |
|
| 199 | + */ |
|
| 200 | + function parseWSDL($wsdl = '') { |
|
| 201 | 201 | $this->debug("parse WSDL at path=$wsdl"); |
| 202 | 202 | |
| 203 | - if ($wsdl == '') { |
|
| 204 | - $this->debug('no wsdl passed to parseWSDL()!!'); |
|
| 205 | - $this->setError('no wsdl passed to parseWSDL()!!'); |
|
| 206 | - return false; |
|
| 207 | - } |
|
| 203 | + if ($wsdl == '') { |
|
| 204 | + $this->debug('no wsdl passed to parseWSDL()!!'); |
|
| 205 | + $this->setError('no wsdl passed to parseWSDL()!!'); |
|
| 206 | + return false; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - // parse $wsdl for url format |
|
| 210 | - $wsdl_props = parse_url($wsdl); |
|
| 209 | + // parse $wsdl for url format |
|
| 210 | + $wsdl_props = parse_url($wsdl); |
|
| 211 | 211 | |
| 212 | - if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) { |
|
| 213 | - $this->debug('getting WSDL http(s) URL ' . $wsdl); |
|
| 214 | - // get wsdl |
|
| 215 | - $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl); |
|
| 212 | + if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'http' || $wsdl_props['scheme'] == 'https')) { |
|
| 213 | + $this->debug('getting WSDL http(s) URL ' . $wsdl); |
|
| 214 | + // get wsdl |
|
| 215 | + $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl); |
|
| 216 | 216 | $tr->request_method = 'GET'; |
| 217 | 217 | $tr->useSOAPAction = false; |
| 218 | 218 | if($this->proxyhost && $this->proxyport){ |
@@ -228,239 +228,239 @@ discard block |
||
| 228 | 228 | if($err = $tr->getError() ){ |
| 229 | 229 | $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err; |
| 230 | 230 | $this->debug($errstr); |
| 231 | - $this->setError($errstr); |
|
| 231 | + $this->setError($errstr); |
|
| 232 | 232 | unset($tr); |
| 233 | - return false; |
|
| 233 | + return false; |
|
| 234 | 234 | } |
| 235 | 235 | unset($tr); |
| 236 | 236 | $this->debug("got WSDL URL"); |
| 237 | - } else { |
|
| 238 | - // $wsdl is not http(s), so treat it as a file URL or plain file path |
|
| 239 | - if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) { |
|
| 240 | - $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path']; |
|
| 241 | - } else { |
|
| 242 | - $path = $wsdl; |
|
| 243 | - } |
|
| 244 | - $this->debug('getting WSDL file ' . $path); |
|
| 245 | - if ($fp = @fopen($path, 'r')) { |
|
| 246 | - $wsdl_string = ''; |
|
| 247 | - while ($data = fread($fp, 32768)) { |
|
| 248 | - $wsdl_string .= $data; |
|
| 249 | - } |
|
| 250 | - fclose($fp); |
|
| 251 | - } else { |
|
| 252 | - $errstr = "Bad path to WSDL file $path"; |
|
| 253 | - $this->debug($errstr); |
|
| 254 | - $this->setError($errstr); |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - $this->debug('Parse WSDL'); |
|
| 259 | - // end new code added |
|
| 260 | - // Create an XML parser. |
|
| 261 | - $this->parser = xml_parser_create(); |
|
| 262 | - // Set the options for parsing the XML data. |
|
| 263 | - // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
|
| 264 | - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|
| 265 | - // Set the object for the parser. |
|
| 266 | - xml_set_object($this->parser, $this); |
|
| 267 | - // Set the element handlers for the parser. |
|
| 268 | - xml_set_element_handler($this->parser, 'start_element', 'end_element'); |
|
| 269 | - xml_set_character_data_handler($this->parser, 'character_data'); |
|
| 270 | - // Parse the XML file. |
|
| 271 | - if (!xml_parse($this->parser, $wsdl_string, true)) { |
|
| 272 | - // Display an error message. |
|
| 273 | - $errstr = sprintf( |
|
| 237 | + } else { |
|
| 238 | + // $wsdl is not http(s), so treat it as a file URL or plain file path |
|
| 239 | + if (isset($wsdl_props['scheme']) && ($wsdl_props['scheme'] == 'file') && isset($wsdl_props['path'])) { |
|
| 240 | + $path = isset($wsdl_props['host']) ? ($wsdl_props['host'] . ':' . $wsdl_props['path']) : $wsdl_props['path']; |
|
| 241 | + } else { |
|
| 242 | + $path = $wsdl; |
|
| 243 | + } |
|
| 244 | + $this->debug('getting WSDL file ' . $path); |
|
| 245 | + if ($fp = @fopen($path, 'r')) { |
|
| 246 | + $wsdl_string = ''; |
|
| 247 | + while ($data = fread($fp, 32768)) { |
|
| 248 | + $wsdl_string .= $data; |
|
| 249 | + } |
|
| 250 | + fclose($fp); |
|
| 251 | + } else { |
|
| 252 | + $errstr = "Bad path to WSDL file $path"; |
|
| 253 | + $this->debug($errstr); |
|
| 254 | + $this->setError($errstr); |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + $this->debug('Parse WSDL'); |
|
| 259 | + // end new code added |
|
| 260 | + // Create an XML parser. |
|
| 261 | + $this->parser = xml_parser_create(); |
|
| 262 | + // Set the options for parsing the XML data. |
|
| 263 | + // xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); |
|
| 264 | + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|
| 265 | + // Set the object for the parser. |
|
| 266 | + xml_set_object($this->parser, $this); |
|
| 267 | + // Set the element handlers for the parser. |
|
| 268 | + xml_set_element_handler($this->parser, 'start_element', 'end_element'); |
|
| 269 | + xml_set_character_data_handler($this->parser, 'character_data'); |
|
| 270 | + // Parse the XML file. |
|
| 271 | + if (!xml_parse($this->parser, $wsdl_string, true)) { |
|
| 272 | + // Display an error message. |
|
| 273 | + $errstr = sprintf( |
|
| 274 | 274 | 'XML error parsing WSDL from %s on line %d: %s', |
| 275 | 275 | $wsdl, |
| 276 | - xml_get_current_line_number($this->parser), |
|
| 277 | - xml_error_string(xml_get_error_code($this->parser)) |
|
| 278 | - ); |
|
| 279 | - $this->debug($errstr); |
|
| 276 | + xml_get_current_line_number($this->parser), |
|
| 277 | + xml_error_string(xml_get_error_code($this->parser)) |
|
| 278 | + ); |
|
| 279 | + $this->debug($errstr); |
|
| 280 | 280 | $this->debug("XML payload:\n" . $wsdl_string); |
| 281 | - $this->setError($errstr); |
|
| 282 | - return false; |
|
| 283 | - } |
|
| 281 | + $this->setError($errstr); |
|
| 282 | + return false; |
|
| 283 | + } |
|
| 284 | 284 | // free the parser |
| 285 | - xml_parser_free($this->parser); |
|
| 286 | - $this->debug('Parsing WSDL done'); |
|
| 285 | + xml_parser_free($this->parser); |
|
| 286 | + $this->debug('Parsing WSDL done'); |
|
| 287 | 287 | // catch wsdl parse errors |
| 288 | 288 | if($this->getError()){ |
| 289 | 289 | return false; |
| 290 | 290 | } |
| 291 | - return true; |
|
| 292 | - } |
|
| 291 | + return true; |
|
| 292 | + } |
|
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * start-element handler |
|
| 296 | - * |
|
| 297 | - * @param string $parser XML parser object |
|
| 298 | - * @param string $name element name |
|
| 299 | - * @param string $attrs associative array of attributes |
|
| 300 | - * @access private |
|
| 301 | - */ |
|
| 302 | - function start_element($parser, $name, $attrs) |
|
| 303 | - { |
|
| 304 | - if ($this->status == 'schema') { |
|
| 305 | - $this->currentSchema->schemaStartElement($parser, $name, $attrs); |
|
| 306 | - $this->appendDebug($this->currentSchema->getDebug()); |
|
| 307 | - $this->currentSchema->clearDebug(); |
|
| 308 | - } elseif (preg_match('/schema$/', $name)) { |
|
| 309 | - $this->debug('Parsing WSDL schema'); |
|
| 310 | - $this->status = 'schema'; |
|
| 311 | - $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces); |
|
| 312 | - $this->currentSchema->schemaStartElement($parser, $name, $attrs); |
|
| 313 | - $this->appendDebug($this->currentSchema->getDebug()); |
|
| 314 | - $this->currentSchema->clearDebug(); |
|
| 315 | - } else { |
|
| 316 | - // position in the total number of elements, starting from 0 |
|
| 317 | - $pos = $this->position++; |
|
| 318 | - $depth = $this->depth++; |
|
| 319 | - // set self as current value for this depth |
|
| 320 | - $this->depth_array[$depth] = $pos; |
|
| 321 | - $this->message[$pos] = array('cdata' => ''); |
|
| 322 | - // process attributes |
|
| 323 | - if (count($attrs) > 0) { |
|
| 294 | + /** |
|
| 295 | + * start-element handler |
|
| 296 | + * |
|
| 297 | + * @param string $parser XML parser object |
|
| 298 | + * @param string $name element name |
|
| 299 | + * @param string $attrs associative array of attributes |
|
| 300 | + * @access private |
|
| 301 | + */ |
|
| 302 | + function start_element($parser, $name, $attrs) |
|
| 303 | + { |
|
| 304 | + if ($this->status == 'schema') { |
|
| 305 | + $this->currentSchema->schemaStartElement($parser, $name, $attrs); |
|
| 306 | + $this->appendDebug($this->currentSchema->getDebug()); |
|
| 307 | + $this->currentSchema->clearDebug(); |
|
| 308 | + } elseif (preg_match('/schema$/', $name)) { |
|
| 309 | + $this->debug('Parsing WSDL schema'); |
|
| 310 | + $this->status = 'schema'; |
|
| 311 | + $this->currentSchema = new nusoap_xmlschema('', '', $this->namespaces); |
|
| 312 | + $this->currentSchema->schemaStartElement($parser, $name, $attrs); |
|
| 313 | + $this->appendDebug($this->currentSchema->getDebug()); |
|
| 314 | + $this->currentSchema->clearDebug(); |
|
| 315 | + } else { |
|
| 316 | + // position in the total number of elements, starting from 0 |
|
| 317 | + $pos = $this->position++; |
|
| 318 | + $depth = $this->depth++; |
|
| 319 | + // set self as current value for this depth |
|
| 320 | + $this->depth_array[$depth] = $pos; |
|
| 321 | + $this->message[$pos] = array('cdata' => ''); |
|
| 322 | + // process attributes |
|
| 323 | + if (count($attrs) > 0) { |
|
| 324 | 324 | // register namespace declarations |
| 325 | - foreach($attrs as $k => $v) { |
|
| 326 | - if (preg_match('/^xmlns/',$k)) { |
|
| 327 | - if ($ns_prefix = substr(strrchr($k, ':'), 1)) { |
|
| 328 | - $this->namespaces[$ns_prefix] = $v; |
|
| 329 | - } else { |
|
| 330 | - $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v; |
|
| 331 | - } |
|
| 332 | - if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') { |
|
| 333 | - $this->XMLSchemaVersion = $v; |
|
| 334 | - $this->namespaces['xsi'] = $v . '-instance'; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - // expand each attribute prefix to its namespace |
|
| 339 | - foreach($attrs as $k => $v) { |
|
| 340 | - $k = strpos($k, ':') ? $this->expandQname($k) : $k; |
|
| 341 | - if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') { |
|
| 342 | - $v = strpos($v, ':') ? $this->expandQname($v) : $v; |
|
| 343 | - } |
|
| 344 | - $eAttrs[$k] = $v; |
|
| 345 | - } |
|
| 346 | - $attrs = $eAttrs; |
|
| 347 | - } else { |
|
| 348 | - $attrs = array(); |
|
| 349 | - } |
|
| 350 | - // get element prefix, namespace and name |
|
| 351 | - if (preg_match('/:/', $name)) { |
|
| 352 | - // get ns prefix |
|
| 353 | - $prefix = substr($name, 0, strpos($name, ':')); |
|
| 354 | - // get ns |
|
| 355 | - $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : ''; |
|
| 356 | - // get unqualified name |
|
| 357 | - $name = substr(strstr($name, ':'), 1); |
|
| 358 | - } |
|
| 325 | + foreach($attrs as $k => $v) { |
|
| 326 | + if (preg_match('/^xmlns/',$k)) { |
|
| 327 | + if ($ns_prefix = substr(strrchr($k, ':'), 1)) { |
|
| 328 | + $this->namespaces[$ns_prefix] = $v; |
|
| 329 | + } else { |
|
| 330 | + $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v; |
|
| 331 | + } |
|
| 332 | + if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') { |
|
| 333 | + $this->XMLSchemaVersion = $v; |
|
| 334 | + $this->namespaces['xsi'] = $v . '-instance'; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + // expand each attribute prefix to its namespace |
|
| 339 | + foreach($attrs as $k => $v) { |
|
| 340 | + $k = strpos($k, ':') ? $this->expandQname($k) : $k; |
|
| 341 | + if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') { |
|
| 342 | + $v = strpos($v, ':') ? $this->expandQname($v) : $v; |
|
| 343 | + } |
|
| 344 | + $eAttrs[$k] = $v; |
|
| 345 | + } |
|
| 346 | + $attrs = $eAttrs; |
|
| 347 | + } else { |
|
| 348 | + $attrs = array(); |
|
| 349 | + } |
|
| 350 | + // get element prefix, namespace and name |
|
| 351 | + if (preg_match('/:/', $name)) { |
|
| 352 | + // get ns prefix |
|
| 353 | + $prefix = substr($name, 0, strpos($name, ':')); |
|
| 354 | + // get ns |
|
| 355 | + $namespace = isset($this->namespaces[$prefix]) ? $this->namespaces[$prefix] : ''; |
|
| 356 | + // get unqualified name |
|
| 357 | + $name = substr(strstr($name, ':'), 1); |
|
| 358 | + } |
|
| 359 | 359 | // process attributes, expanding any prefixes to namespaces |
| 360 | - // find status, register data |
|
| 361 | - switch ($this->status) { |
|
| 362 | - case 'message': |
|
| 363 | - if ($name == 'part') { |
|
| 364 | - if (isset($attrs['type'])) { |
|
| 365 | - $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs)); |
|
| 366 | - $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; |
|
| 367 | - } |
|
| 368 | - if (isset($attrs['element'])) { |
|
| 369 | - $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs)); |
|
| 370 | - $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^'; |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - break; |
|
| 374 | - case 'portType': |
|
| 375 | - switch ($name) { |
|
| 376 | - case 'operation': |
|
| 377 | - $this->currentPortOperation = $attrs['name']; |
|
| 378 | - $this->debug("portType $this->currentPortType operation: $this->currentPortOperation"); |
|
| 379 | - if (isset($attrs['parameterOrder'])) { |
|
| 380 | - $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; |
|
| 381 | - } |
|
| 382 | - break; |
|
| 383 | - case 'documentation': |
|
| 384 | - $this->documentation = true; |
|
| 385 | - break; |
|
| 386 | - // merge input/output data |
|
| 387 | - default: |
|
| 388 | - $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : ''; |
|
| 389 | - $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m; |
|
| 390 | - break; |
|
| 360 | + // find status, register data |
|
| 361 | + switch ($this->status) { |
|
| 362 | + case 'message': |
|
| 363 | + if ($name == 'part') { |
|
| 364 | + if (isset($attrs['type'])) { |
|
| 365 | + $this->debug("msg " . $this->currentMessage . ": found part (with type) $attrs[name]: " . implode(',', $attrs)); |
|
| 366 | + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['type']; |
|
| 367 | + } |
|
| 368 | + if (isset($attrs['element'])) { |
|
| 369 | + $this->debug("msg " . $this->currentMessage . ": found part (with element) $attrs[name]: " . implode(',', $attrs)); |
|
| 370 | + $this->messages[$this->currentMessage][$attrs['name']] = $attrs['element'] . '^'; |
|
| 371 | + } |
|
| 391 | 372 | } |
| 392 | - break; |
|
| 373 | + break; |
|
| 374 | + case 'portType': |
|
| 375 | + switch ($name) { |
|
| 376 | + case 'operation': |
|
| 377 | + $this->currentPortOperation = $attrs['name']; |
|
| 378 | + $this->debug("portType $this->currentPortType operation: $this->currentPortOperation"); |
|
| 379 | + if (isset($attrs['parameterOrder'])) { |
|
| 380 | + $this->portTypes[$this->currentPortType][$attrs['name']]['parameterOrder'] = $attrs['parameterOrder']; |
|
| 381 | + } |
|
| 382 | + break; |
|
| 383 | + case 'documentation': |
|
| 384 | + $this->documentation = true; |
|
| 385 | + break; |
|
| 386 | + // merge input/output data |
|
| 387 | + default: |
|
| 388 | + $m = isset($attrs['message']) ? $this->getLocalPart($attrs['message']) : ''; |
|
| 389 | + $this->portTypes[$this->currentPortType][$this->currentPortOperation][$name]['message'] = $m; |
|
| 390 | + break; |
|
| 391 | + } |
|
| 392 | + break; |
|
| 393 | 393 | case 'binding': |
| 394 | - switch ($name) { |
|
| 395 | - case 'binding': |
|
| 396 | - // get ns prefix |
|
| 397 | - if (isset($attrs['style'])) { |
|
| 398 | - $this->bindings[$this->currentBinding]['prefix'] = $prefix; |
|
| 399 | - } |
|
| 400 | - $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs); |
|
| 401 | - break; |
|
| 394 | + switch ($name) { |
|
| 395 | + case 'binding': |
|
| 396 | + // get ns prefix |
|
| 397 | + if (isset($attrs['style'])) { |
|
| 398 | + $this->bindings[$this->currentBinding]['prefix'] = $prefix; |
|
| 399 | + } |
|
| 400 | + $this->bindings[$this->currentBinding] = array_merge($this->bindings[$this->currentBinding], $attrs); |
|
| 401 | + break; |
|
| 402 | 402 | case 'header': |
| 403 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs; |
|
| 404 | - break; |
|
| 403 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus]['headers'][] = $attrs; |
|
| 404 | + break; |
|
| 405 | 405 | case 'operation': |
| 406 | - if (isset($attrs['soapAction'])) { |
|
| 407 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; |
|
| 408 | - } |
|
| 409 | - if (isset($attrs['style'])) { |
|
| 410 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style']; |
|
| 411 | - } |
|
| 412 | - if (isset($attrs['name'])) { |
|
| 413 | - $this->currentOperation = $attrs['name']; |
|
| 414 | - $this->debug("current binding operation: $this->currentOperation"); |
|
| 415 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name']; |
|
| 416 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding; |
|
| 417 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : ''; |
|
| 418 | - } |
|
| 419 | - break; |
|
| 406 | + if (isset($attrs['soapAction'])) { |
|
| 407 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['soapAction'] = $attrs['soapAction']; |
|
| 408 | + } |
|
| 409 | + if (isset($attrs['style'])) { |
|
| 410 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['style'] = $attrs['style']; |
|
| 411 | + } |
|
| 412 | + if (isset($attrs['name'])) { |
|
| 413 | + $this->currentOperation = $attrs['name']; |
|
| 414 | + $this->debug("current binding operation: $this->currentOperation"); |
|
| 415 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['name'] = $attrs['name']; |
|
| 416 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['binding'] = $this->currentBinding; |
|
| 417 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation]['endpoint'] = isset($this->bindings[$this->currentBinding]['endpoint']) ? $this->bindings[$this->currentBinding]['endpoint'] : ''; |
|
| 418 | + } |
|
| 419 | + break; |
|
| 420 | 420 | case 'input': |
| 421 | - $this->opStatus = 'input'; |
|
| 422 | - break; |
|
| 421 | + $this->opStatus = 'input'; |
|
| 422 | + break; |
|
| 423 | 423 | case 'output': |
| 424 | - $this->opStatus = 'output'; |
|
| 425 | - break; |
|
| 424 | + $this->opStatus = 'output'; |
|
| 425 | + break; |
|
| 426 | 426 | case 'body': |
| 427 | - if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) { |
|
| 428 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs); |
|
| 429 | - } else { |
|
| 430 | - $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; |
|
| 431 | - } |
|
| 432 | - break; |
|
| 427 | + if (isset($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus])) { |
|
| 428 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = array_merge($this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus], $attrs); |
|
| 429 | + } else { |
|
| 430 | + $this->bindings[$this->currentBinding]['operations'][$this->currentOperation][$this->opStatus] = $attrs; |
|
| 431 | + } |
|
| 432 | + break; |
|
| 433 | 433 | } |
| 434 | 434 | break; |
| 435 | 435 | case 'service': |
| 436 | 436 | switch ($name) { |
| 437 | - case 'port': |
|
| 438 | - $this->currentPort = $attrs['name']; |
|
| 439 | - $this->debug('current port: ' . $this->currentPort); |
|
| 440 | - $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']); |
|
| 437 | + case 'port': |
|
| 438 | + $this->currentPort = $attrs['name']; |
|
| 439 | + $this->debug('current port: ' . $this->currentPort); |
|
| 440 | + $this->ports[$this->currentPort]['binding'] = $this->getLocalPart($attrs['binding']); |
|
| 441 | 441 | |
| 442 | - break; |
|
| 443 | - case 'address': |
|
| 444 | - $this->ports[$this->currentPort]['location'] = $attrs['location']; |
|
| 445 | - $this->ports[$this->currentPort]['bindingType'] = $namespace; |
|
| 446 | - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; |
|
| 447 | - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; |
|
| 448 | - break; |
|
| 442 | + break; |
|
| 443 | + case 'address': |
|
| 444 | + $this->ports[$this->currentPort]['location'] = $attrs['location']; |
|
| 445 | + $this->ports[$this->currentPort]['bindingType'] = $namespace; |
|
| 446 | + $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; |
|
| 447 | + $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; |
|
| 448 | + break; |
|
| 449 | 449 | } |
| 450 | 450 | break; |
| 451 | 451 | } |
| 452 | 452 | // set status |
| 453 | 453 | switch ($name) { |
| 454 | 454 | case 'import': |
| 455 | - if (isset($attrs['location'])) { |
|
| 456 | - $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false); |
|
| 457 | - $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')'); |
|
| 455 | + if (isset($attrs['location'])) { |
|
| 456 | + $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false); |
|
| 457 | + $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')'); |
|
| 458 | 458 | } else { |
| 459 | - $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
|
| 459 | + $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
|
| 460 | 460 | if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
| 461 | 461 | $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
| 462 | 462 | } |
| 463 | - $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')'); |
|
| 463 | + $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')'); |
|
| 464 | 464 | } |
| 465 | 465 | break; |
| 466 | 466 | //wait for schema |
@@ -481,9 +481,9 @@ discard block |
||
| 481 | 481 | if (isset($attrs['name'])) { |
| 482 | 482 | // get binding name |
| 483 | 483 | if (strpos($attrs['name'], ':')) { |
| 484 | - $this->currentBinding = $this->getLocalPart($attrs['name']); |
|
| 484 | + $this->currentBinding = $this->getLocalPart($attrs['name']); |
|
| 485 | 485 | } else { |
| 486 | - $this->currentBinding = $attrs['name']; |
|
| 486 | + $this->currentBinding = $attrs['name']; |
|
| 487 | 487 | } |
| 488 | 488 | $this->status = 'binding'; |
| 489 | 489 | $this->bindings[$this->currentBinding]['portType'] = $this->getLocalPart($attrs['type']); |
@@ -505,20 +505,20 @@ discard block |
||
| 505 | 505 | } |
| 506 | 506 | |
| 507 | 507 | /** |
| 508 | - * end-element handler |
|
| 509 | - * |
|
| 510 | - * @param string $parser XML parser object |
|
| 511 | - * @param string $name element name |
|
| 512 | - * @access private |
|
| 513 | - */ |
|
| 508 | + * end-element handler |
|
| 509 | + * |
|
| 510 | + * @param string $parser XML parser object |
|
| 511 | + * @param string $name element name |
|
| 512 | + * @access private |
|
| 513 | + */ |
|
| 514 | 514 | public function end_element($parser, $name){ |
| 515 | 515 | // unset schema status |
| 516 | 516 | if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) { |
| 517 | 517 | $this->status = ""; |
| 518 | - $this->appendDebug($this->currentSchema->getDebug()); |
|
| 519 | - $this->currentSchema->clearDebug(); |
|
| 518 | + $this->appendDebug($this->currentSchema->getDebug()); |
|
| 519 | + $this->currentSchema->clearDebug(); |
|
| 520 | 520 | $this->schemas[$this->currentSchema->schemaTargetNamespace][] = $this->currentSchema; |
| 521 | - $this->debug('Parsing WSDL schema done'); |
|
| 521 | + $this->debug('Parsing WSDL schema done'); |
|
| 522 | 522 | } |
| 523 | 523 | if ($this->status == 'schema') { |
| 524 | 524 | $this->currentSchema->schemaEndElement($parser, $name); |
@@ -552,14 +552,14 @@ discard block |
||
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
| 555 | - * if authenticating, set user credentials here |
|
| 556 | - * |
|
| 557 | - * @param string $username |
|
| 558 | - * @param string $password |
|
| 559 | - * @param string $authtype (basic|digest|certificate|ntlm) |
|
| 560 | - * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
| 561 | - * @access public |
|
| 562 | - */ |
|
| 555 | + * if authenticating, set user credentials here |
|
| 556 | + * |
|
| 557 | + * @param string $username |
|
| 558 | + * @param string $password |
|
| 559 | + * @param string $authtype (basic|digest|certificate|ntlm) |
|
| 560 | + * @param array $certRequest (keys must be cainfofile (optional), sslcertfile, sslkeyfile, passphrase, certpassword (optional), verifypeer (optional), verifyhost (optional): see corresponding options in cURL docs) |
|
| 561 | + * @access public |
|
| 562 | + */ |
|
| 563 | 563 | public function setCredentials($username, $password, $authtype = 'basic', $certRequest = array()) { |
| 564 | 564 | $this->debug("setCredentials username=$username authtype=$authtype certRequest="); |
| 565 | 565 | $this->appendDebug($this->varDump($certRequest)); |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | // note that we could/should also check the namespace here |
| 640 | 640 | if ($operation == $bOperation) { |
| 641 | 641 | $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation]; |
| 642 | - return $opData; |
|
| 642 | + return $opData; |
|
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | } |
@@ -667,7 +667,7 @@ discard block |
||
| 667 | 667 | // loop through operations for the binding |
| 668 | 668 | foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
| 669 | 669 | if ($opData['soapAction'] == $soapAction) { |
| 670 | - return $opData; |
|
| 670 | + return $opData; |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | } |
@@ -675,23 +675,23 @@ discard block |
||
| 675 | 675 | } |
| 676 | 676 | |
| 677 | 677 | /** |
| 678 | - * returns an array of information about a given type |
|
| 679 | - * returns false if no type exists by the given name |
|
| 680 | - * |
|
| 681 | - * typeDef = array( |
|
| 682 | - * 'elements' => array(), // refs to elements array |
|
| 683 | - * 'restrictionBase' => '', |
|
| 684 | - * 'phpType' => '', |
|
| 685 | - * 'order' => '(sequence|all)', |
|
| 686 | - * 'attrs' => array() // refs to attributes array |
|
| 687 | - * ) |
|
| 688 | - * |
|
| 689 | - * @param string $type the type |
|
| 690 | - * @param string $ns namespace (not prefix) of the type |
|
| 691 | - * @return mixed |
|
| 692 | - * @access public |
|
| 693 | - * @see nusoap_xmlschema |
|
| 694 | - */ |
|
| 678 | + * returns an array of information about a given type |
|
| 679 | + * returns false if no type exists by the given name |
|
| 680 | + * |
|
| 681 | + * typeDef = array( |
|
| 682 | + * 'elements' => array(), // refs to elements array |
|
| 683 | + * 'restrictionBase' => '', |
|
| 684 | + * 'phpType' => '', |
|
| 685 | + * 'order' => '(sequence|all)', |
|
| 686 | + * 'attrs' => array() // refs to attributes array |
|
| 687 | + * ) |
|
| 688 | + * |
|
| 689 | + * @param string $type the type |
|
| 690 | + * @param string $ns namespace (not prefix) of the type |
|
| 691 | + * @return mixed |
|
| 692 | + * @access public |
|
| 693 | + * @see nusoap_xmlschema |
|
| 694 | + */ |
|
| 695 | 695 | public function getTypeDef($type, $ns) { |
| 696 | 696 | $this->debug("in getTypeDef: type=$type, ns=$ns"); |
| 697 | 697 | if ((! $ns) && isset($this->namespaces['tns'])) { |
@@ -747,13 +747,13 @@ discard block |
||
| 747 | 747 | return false; |
| 748 | 748 | } |
| 749 | 749 | |
| 750 | - /** |
|
| 751 | - * prints html description of services |
|
| 752 | - * |
|
| 753 | - * @access private |
|
| 754 | - */ |
|
| 755 | - function webDescription(){ |
|
| 756 | - global $HTTP_SERVER_VARS; |
|
| 750 | + /** |
|
| 751 | + * prints html description of services |
|
| 752 | + * |
|
| 753 | + * @access private |
|
| 754 | + */ |
|
| 755 | + function webDescription(){ |
|
| 756 | + global $HTTP_SERVER_VARS; |
|
| 757 | 757 | |
| 758 | 758 | if (isset($_SERVER)) { |
| 759 | 759 | $PHP_SELF = $_SERVER['PHP_SELF']; |
@@ -847,29 +847,29 @@ discard block |
||
| 847 | 847 | Click on an operation name to view it's details.</p> |
| 848 | 848 | <ul>'; |
| 849 | 849 | foreach($this->getOperations() as $op => $data){ |
| 850 | - $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>"; |
|
| 851 | - // create hidden div |
|
| 852 | - $b .= "<div id='$op' class='hidden'> |
|
| 850 | + $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>"; |
|
| 851 | + // create hidden div |
|
| 852 | + $b .= "<div id='$op' class='hidden'> |
|
| 853 | 853 | <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>"; |
| 854 | - foreach($data as $donnie => $marie){ // loop through opdata |
|
| 854 | + foreach($data as $donnie => $marie){ // loop through opdata |
|
| 855 | 855 | if($donnie == 'input' || $donnie == 'output'){ // show input/output data |
| 856 | - $b .= "<font color='white'>".ucfirst($donnie).':</font><br>'; |
|
| 857 | - foreach($marie as $captain => $tenille){ // loop through data |
|
| 856 | + $b .= "<font color='white'>".ucfirst($donnie).':</font><br>'; |
|
| 857 | + foreach($marie as $captain => $tenille){ // loop through data |
|
| 858 | 858 | if($captain == 'parts'){ // loop thru parts |
| 859 | - $b .= " $captain:<br>"; |
|
| 860 | - //if(is_array($tenille)){ |
|
| 861 | - foreach($tenille as $joanie => $chachi){ |
|
| 859 | + $b .= " $captain:<br>"; |
|
| 860 | + //if(is_array($tenille)){ |
|
| 861 | + foreach($tenille as $joanie => $chachi){ |
|
| 862 | 862 | $b .= " $joanie: $chachi<br>"; |
| 863 | - } |
|
| 864 | - //} |
|
| 863 | + } |
|
| 864 | + //} |
|
| 865 | 865 | } else { |
| 866 | - $b .= " $captain: $tenille<br>"; |
|
| 866 | + $b .= " $captain: $tenille<br>"; |
|
| 867 | 867 | } |
| 868 | - } |
|
| 868 | + } |
|
| 869 | 869 | } else { |
| 870 | - $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>"; |
|
| 870 | + $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>"; |
|
| 871 | 871 | } |
| 872 | - } |
|
| 872 | + } |
|
| 873 | 873 | $b .= '</div>'; |
| 874 | 874 | } |
| 875 | 875 | $b .= ' |
@@ -877,15 +877,15 @@ discard block |
||
| 877 | 877 | </div> |
| 878 | 878 | </div></body></html>'; |
| 879 | 879 | return $b; |
| 880 | - } |
|
| 880 | + } |
|
| 881 | 881 | |
| 882 | 882 | /** |
| 883 | - * serialize the parsed wsdl |
|
| 884 | - * |
|
| 885 | - * @param mixed $debug whether to put debug=1 in endpoint URL |
|
| 886 | - * @return string serialization of WSDL |
|
| 887 | - * @access public |
|
| 888 | - */ |
|
| 883 | + * serialize the parsed wsdl |
|
| 884 | + * |
|
| 885 | + * @param mixed $debug whether to put debug=1 in endpoint URL |
|
| 886 | + * @return string serialization of WSDL |
|
| 887 | + * @access public |
|
| 888 | + */ |
|
| 889 | 889 | public function serialize($debug = 0) |
| 890 | 890 | { |
| 891 | 891 | $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'; |
@@ -931,19 +931,19 @@ discard block |
||
| 931 | 931 | foreach($msgParts as $partName => $partType) { |
| 932 | 932 | // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>'; |
| 933 | 933 | if (strpos($partType, ':')) { |
| 934 | - $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType)); |
|
| 934 | + $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType)); |
|
| 935 | 935 | } elseif (isset($this->typemap[$this->namespaces['xsd']][$partType])) { |
| 936 | - // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>'; |
|
| 937 | - $typePrefix = 'xsd'; |
|
| 936 | + // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>'; |
|
| 937 | + $typePrefix = 'xsd'; |
|
| 938 | 938 | } else { |
| 939 | - foreach($this->typemap as $ns => $types) { |
|
| 940 | - if (isset($types[$partType])) { |
|
| 941 | - $typePrefix = $this->getPrefixFromNamespace($ns); |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - if (!isset($typePrefix)) { |
|
| 945 | - die("$partType has no namespace!"); |
|
| 946 | - } |
|
| 939 | + foreach($this->typemap as $ns => $types) { |
|
| 940 | + if (isset($types[$partType])) { |
|
| 941 | + $typePrefix = $this->getPrefixFromNamespace($ns); |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + if (!isset($typePrefix)) { |
|
| 945 | + die("$partType has no namespace!"); |
|
| 946 | + } |
|
| 947 | 947 | } |
| 948 | 948 | $ns = $this->getNamespaceFromPrefix($typePrefix); |
| 949 | 949 | $localPart = $this->getLocalPart($partType); |
@@ -988,7 +988,7 @@ discard block |
||
| 988 | 988 | $binding_xml .= "\n" . ' </operation>'; |
| 989 | 989 | $portType_xml .= "\n" . ' <operation name="' . $opParts['name'] . '"'; |
| 990 | 990 | if (isset($opParts['parameterOrder'])) { |
| 991 | - $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"'; |
|
| 991 | + $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"'; |
|
| 992 | 992 | } |
| 993 | 993 | $portType_xml .= '>'; |
| 994 | 994 | if(isset($opParts['documentation']) && $opParts['documentation'] != '') { |
@@ -1297,34 +1297,34 @@ discard block |
||
| 1297 | 1297 | } |
| 1298 | 1298 | |
| 1299 | 1299 | // if a soapval has been supplied, let its type override the WSDL |
| 1300 | - if (is_object($value) && get_class($value) == 'soapval') { |
|
| 1301 | - if ($value->type_ns) { |
|
| 1302 | - $type = $value->type_ns . ':' . $value->type; |
|
| 1303 | - $forceType = true; |
|
| 1304 | - $this->debug("in serializeType: soapval overrides type to $type"); |
|
| 1305 | - } elseif ($value->type) { |
|
| 1306 | - $type = $value->type; |
|
| 1307 | - $forceType = true; |
|
| 1308 | - $this->debug("in serializeType: soapval overrides type to $type"); |
|
| 1309 | - } else { |
|
| 1310 | - $forceType = false; |
|
| 1311 | - $this->debug("in serializeType: soapval does not override type"); |
|
| 1312 | - } |
|
| 1313 | - $attrs = $value->attributes; |
|
| 1314 | - $value = $value->value; |
|
| 1315 | - $this->debug("in serializeType: soapval overrides value to $value"); |
|
| 1316 | - if ($attrs) { |
|
| 1317 | - if (!is_array($value)) { |
|
| 1318 | - $value['!'] = $value; |
|
| 1319 | - } |
|
| 1320 | - foreach ($attrs as $n => $v) { |
|
| 1321 | - $value['!' . $n] = $v; |
|
| 1322 | - } |
|
| 1323 | - $this->debug("in serializeType: soapval provides attributes"); |
|
| 1324 | - } |
|
| 1325 | - } else { |
|
| 1326 | - $forceType = false; |
|
| 1327 | - } |
|
| 1300 | + if (is_object($value) && get_class($value) == 'soapval') { |
|
| 1301 | + if ($value->type_ns) { |
|
| 1302 | + $type = $value->type_ns . ':' . $value->type; |
|
| 1303 | + $forceType = true; |
|
| 1304 | + $this->debug("in serializeType: soapval overrides type to $type"); |
|
| 1305 | + } elseif ($value->type) { |
|
| 1306 | + $type = $value->type; |
|
| 1307 | + $forceType = true; |
|
| 1308 | + $this->debug("in serializeType: soapval overrides type to $type"); |
|
| 1309 | + } else { |
|
| 1310 | + $forceType = false; |
|
| 1311 | + $this->debug("in serializeType: soapval does not override type"); |
|
| 1312 | + } |
|
| 1313 | + $attrs = $value->attributes; |
|
| 1314 | + $value = $value->value; |
|
| 1315 | + $this->debug("in serializeType: soapval overrides value to $value"); |
|
| 1316 | + if ($attrs) { |
|
| 1317 | + if (!is_array($value)) { |
|
| 1318 | + $value['!'] = $value; |
|
| 1319 | + } |
|
| 1320 | + foreach ($attrs as $n => $v) { |
|
| 1321 | + $value['!' . $n] = $v; |
|
| 1322 | + } |
|
| 1323 | + $this->debug("in serializeType: soapval provides attributes"); |
|
| 1324 | + } |
|
| 1325 | + } else { |
|
| 1326 | + $forceType = false; |
|
| 1327 | + } |
|
| 1328 | 1328 | |
| 1329 | 1329 | $xml = ''; |
| 1330 | 1330 | if (strpos($type, ':')) { |
@@ -1358,8 +1358,8 @@ discard block |
||
| 1358 | 1358 | // JBoss/Axis does this sometimes |
| 1359 | 1359 | return $this->serialize_val($value, $name, false, false, false, false, $use); |
| 1360 | 1360 | } |
| 1361 | - if ($uqType == 'boolean') { |
|
| 1362 | - if ((is_string($value) && $value == 'false') || (! $value)) { |
|
| 1361 | + if ($uqType == 'boolean') { |
|
| 1362 | + if ((is_string($value) && $value == 'false') || (! $value)) { |
|
| 1363 | 1363 | $value = 'false'; |
| 1364 | 1364 | } else { |
| 1365 | 1365 | $value = 'true'; |
@@ -1549,9 +1549,9 @@ discard block |
||
| 1549 | 1549 | $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]"); |
| 1550 | 1550 | //if (strpos($typeDef['arrayType'], ':') ) { |
| 1551 | 1551 | if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) { |
| 1552 | - $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); |
|
| 1552 | + $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); |
|
| 1553 | 1553 | } else { |
| 1554 | - $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use); |
|
| 1554 | + $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use); |
|
| 1555 | 1555 | } |
| 1556 | 1556 | } |
| 1557 | 1557 | } else { |
@@ -1709,7 +1709,7 @@ discard block |
||
| 1709 | 1709 | } |
| 1710 | 1710 | // if user took advantage of a minOccurs=0, then only serialize named parameters |
| 1711 | 1711 | if (isset($optionals) |
| 1712 | - && (!isset($xvalue[$eName])) |
|
| 1712 | + && (!isset($xvalue[$eName])) |
|
| 1713 | 1713 | && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
| 1714 | 1714 | ){ |
| 1715 | 1715 | if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') { |
@@ -1720,9 +1720,9 @@ discard block |
||
| 1720 | 1720 | } else { |
| 1721 | 1721 | // get value |
| 1722 | 1722 | if (isset($xvalue[$eName])) { |
| 1723 | - $v = $xvalue[$eName]; |
|
| 1723 | + $v = $xvalue[$eName]; |
|
| 1724 | 1724 | } else { |
| 1725 | - $v = null; |
|
| 1725 | + $v = null; |
|
| 1726 | 1726 | } |
| 1727 | 1727 | if (isset($attrs['form'])) { |
| 1728 | 1728 | $unqualified = ($attrs['form'] == 'unqualified'); |
@@ -1734,11 +1734,11 @@ discard block |
||
| 1734 | 1734 | foreach ($vv as $k => $v) { |
| 1735 | 1735 | if (isset($attrs['type']) || isset($attrs['ref'])) { |
| 1736 | 1736 | // serialize schema-defined type |
| 1737 | - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
| 1737 | + $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
| 1738 | 1738 | } else { |
| 1739 | 1739 | // serialize generic type (can this ever really happen?) |
| 1740 | - $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
| 1741 | - $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
| 1740 | + $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
| 1741 | + $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
| 1742 | 1742 | } |
| 1743 | 1743 | } |
| 1744 | 1744 | } else { |
@@ -1746,14 +1746,14 @@ discard block |
||
| 1746 | 1746 | // do nothing |
| 1747 | 1747 | } elseif (is_null($v) && isset($attrs['nillable']) && $attrs['nillable'] == 'true') { |
| 1748 | 1748 | // TODO: serialize a nil correctly, but for now serialize schema-defined type |
| 1749 | - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
| 1749 | + $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
| 1750 | 1750 | } elseif (isset($attrs['type']) || isset($attrs['ref'])) { |
| 1751 | 1751 | // serialize schema-defined type |
| 1752 | - $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
| 1752 | + $xml .= $this->serializeType($eName, isset($attrs['type']) ? $attrs['type'] : $attrs['ref'], $v, $use, $encodingStyle, $unqualified); |
|
| 1753 | 1753 | } else { |
| 1754 | 1754 | // serialize generic type (can this ever really happen?) |
| 1755 | - $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
| 1756 | - $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
| 1755 | + $this->debug("calling serialize_val() for $v, $eName, false, false, false, false, $use"); |
|
| 1756 | + $xml .= $this->serialize_val($v, $eName, false, false, false, false, $use); |
|
| 1757 | 1757 | } |
| 1758 | 1758 | } |
| 1759 | 1759 | } |
@@ -1765,46 +1765,46 @@ discard block |
||
| 1765 | 1765 | } |
| 1766 | 1766 | |
| 1767 | 1767 | /** |
| 1768 | - * adds an XML Schema complex type to the WSDL types |
|
| 1769 | - * |
|
| 1770 | - * @param string $name |
|
| 1771 | - * @param string $typeClass (complexType|simpleType|attribute) |
|
| 1772 | - * @param string $phpType currently supported are array and struct (php assoc array) |
|
| 1773 | - * @param string $compositor (all|sequence|choice) |
|
| 1774 | - * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 1775 | - * @param array $elements e.g. array ( name => array(name=>'',type=>'') ) |
|
| 1776 | - * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')) |
|
| 1777 | - * @param string $arrayType as namespace:name (xsd:string) |
|
| 1778 | - * @see nusoap_xmlschema |
|
| 1779 | - * @access public |
|
| 1780 | - */ |
|
| 1768 | + * adds an XML Schema complex type to the WSDL types |
|
| 1769 | + * |
|
| 1770 | + * @param string $name |
|
| 1771 | + * @param string $typeClass (complexType|simpleType|attribute) |
|
| 1772 | + * @param string $phpType currently supported are array and struct (php assoc array) |
|
| 1773 | + * @param string $compositor (all|sequence|choice) |
|
| 1774 | + * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 1775 | + * @param array $elements e.g. array ( name => array(name=>'',type=>'') ) |
|
| 1776 | + * @param array $attrs e.g. array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'xsd:string[]')) |
|
| 1777 | + * @param string $arrayType as namespace:name (xsd:string) |
|
| 1778 | + * @see nusoap_xmlschema |
|
| 1779 | + * @access public |
|
| 1780 | + */ |
|
| 1781 | 1781 | public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') { |
| 1782 | 1782 | if (count($elements) > 0) { |
| 1783 | 1783 | $eElements = array(); |
| 1784 | - foreach($elements as $n => $e){ |
|
| 1785 | - // expand each element |
|
| 1786 | - $ee = array(); |
|
| 1787 | - foreach ($e as $k => $v) { |
|
| 1788 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 1789 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 1790 | - $ee[$k] = $v; |
|
| 1791 | - } |
|
| 1792 | - $eElements[$n] = $ee; |
|
| 1793 | - } |
|
| 1794 | - $elements = $eElements; |
|
| 1784 | + foreach($elements as $n => $e){ |
|
| 1785 | + // expand each element |
|
| 1786 | + $ee = array(); |
|
| 1787 | + foreach ($e as $k => $v) { |
|
| 1788 | + $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 1789 | + $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 1790 | + $ee[$k] = $v; |
|
| 1791 | + } |
|
| 1792 | + $eElements[$n] = $ee; |
|
| 1793 | + } |
|
| 1794 | + $elements = $eElements; |
|
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | 1797 | if (count($attrs) > 0) { |
| 1798 | - foreach($attrs as $n => $a){ |
|
| 1799 | - // expand each attribute |
|
| 1800 | - foreach ($a as $k => $v) { |
|
| 1801 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 1802 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 1803 | - $aa[$k] = $v; |
|
| 1804 | - } |
|
| 1805 | - $eAttrs[$n] = $aa; |
|
| 1806 | - } |
|
| 1807 | - $attrs = $eAttrs; |
|
| 1798 | + foreach($attrs as $n => $a){ |
|
| 1799 | + // expand each attribute |
|
| 1800 | + foreach ($a as $k => $v) { |
|
| 1801 | + $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 1802 | + $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 1803 | + $aa[$k] = $v; |
|
| 1804 | + } |
|
| 1805 | + $eAttrs[$n] = $aa; |
|
| 1806 | + } |
|
| 1807 | + $attrs = $eAttrs; |
|
| 1808 | 1808 | } |
| 1809 | 1809 | |
| 1810 | 1810 | $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
@@ -1815,16 +1815,16 @@ discard block |
||
| 1815 | 1815 | } |
| 1816 | 1816 | |
| 1817 | 1817 | /** |
| 1818 | - * adds an XML Schema simple type to the WSDL types |
|
| 1819 | - * |
|
| 1820 | - * @param string $name |
|
| 1821 | - * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 1822 | - * @param string $typeClass (should always be simpleType) |
|
| 1823 | - * @param string $phpType (should always be scalar) |
|
| 1824 | - * @param array $enumeration array of values |
|
| 1825 | - * @see nusoap_xmlschema |
|
| 1826 | - * @access public |
|
| 1827 | - */ |
|
| 1818 | + * adds an XML Schema simple type to the WSDL types |
|
| 1819 | + * |
|
| 1820 | + * @param string $name |
|
| 1821 | + * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 1822 | + * @param string $typeClass (should always be simpleType) |
|
| 1823 | + * @param string $phpType (should always be scalar) |
|
| 1824 | + * @param array $enumeration array of values |
|
| 1825 | + * @see nusoap_xmlschema |
|
| 1826 | + * @access public |
|
| 1827 | + */ |
|
| 1828 | 1828 | public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
| 1829 | 1829 | $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
| 1830 | 1830 | |
@@ -1833,31 +1833,31 @@ discard block |
||
| 1833 | 1833 | } |
| 1834 | 1834 | |
| 1835 | 1835 | /** |
| 1836 | - * adds an element to the WSDL types |
|
| 1837 | - * |
|
| 1838 | - * @param array $attrs attributes that must include name and type |
|
| 1839 | - * @see nusoap_xmlschema |
|
| 1840 | - * @access public |
|
| 1841 | - */ |
|
| 1836 | + * adds an element to the WSDL types |
|
| 1837 | + * |
|
| 1838 | + * @param array $attrs attributes that must include name and type |
|
| 1839 | + * @see nusoap_xmlschema |
|
| 1840 | + * @access public |
|
| 1841 | + */ |
|
| 1842 | 1842 | public function addElement($attrs) { |
| 1843 | 1843 | $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
| 1844 | 1844 | $this->schemas[$typens][0]->addElement($attrs); |
| 1845 | 1845 | } |
| 1846 | 1846 | |
| 1847 | 1847 | /** |
| 1848 | - * register an operation with the server |
|
| 1849 | - * |
|
| 1850 | - * @param string $name operation (method) name |
|
| 1851 | - * @param array $in assoc array of input values: key = param name, value = param type |
|
| 1852 | - * @param array $out assoc array of output values: key = param name, value = param type |
|
| 1853 | - * @param string $namespace optional The namespace for the operation |
|
| 1854 | - * @param string $soapaction optional The soapaction for the operation |
|
| 1855 | - * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically |
|
| 1856 | - * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now) |
|
| 1857 | - * @param string $documentation optional The description to include in the WSDL |
|
| 1858 | - * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
| 1859 | - * @access public |
|
| 1860 | - */ |
|
| 1848 | + * register an operation with the server |
|
| 1849 | + * |
|
| 1850 | + * @param string $name operation (method) name |
|
| 1851 | + * @param array $in assoc array of input values: key = param name, value = param type |
|
| 1852 | + * @param array $out assoc array of output values: key = param name, value = param type |
|
| 1853 | + * @param string $namespace optional The namespace for the operation |
|
| 1854 | + * @param string $soapaction optional The soapaction for the operation |
|
| 1855 | + * @param string $style (rpc|document) optional The style for the operation Note: when 'document' is specified, parameter and return wrappers are created for you automatically |
|
| 1856 | + * @param string $use (encoded|literal) optional The use for the parameters (cannot mix right now) |
|
| 1857 | + * @param string $documentation optional The description to include in the WSDL |
|
| 1858 | + * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
|
| 1859 | + * @access public |
|
| 1860 | + */ |
|
| 1861 | 1861 | public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){ |
| 1862 | 1862 | if ($use == 'encoded' && $encodingStyle == '') { |
| 1863 | 1863 | $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
@@ -1916,8 +1916,8 @@ discard block |
||
| 1916 | 1916 | $this->messages[$name.'Request'][$pName] = $pType; |
| 1917 | 1917 | } |
| 1918 | 1918 | } else { |
| 1919 | - $this->messages[$name.'Request']= '0'; |
|
| 1920 | - } |
|
| 1919 | + $this->messages[$name.'Request']= '0'; |
|
| 1920 | + } |
|
| 1921 | 1921 | if($out) |
| 1922 | 1922 | { |
| 1923 | 1923 | foreach($out as $pName => $pType) |
@@ -1928,8 +1928,8 @@ discard block |
||
| 1928 | 1928 | $this->messages[$name.'Response'][$pName] = $pType; |
| 1929 | 1929 | } |
| 1930 | 1930 | } else { |
| 1931 | - $this->messages[$name.'Response']= '0'; |
|
| 1932 | - } |
|
| 1931 | + $this->messages[$name.'Response']= '0'; |
|
| 1932 | + } |
|
| 1933 | 1933 | return true; |
| 1934 | 1934 | } |
| 1935 | 1935 | } |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | var $proxypassword = ''; |
| 48 | 48 | var $timeout = 0; |
| 49 | 49 | var $response_timeout = 30; |
| 50 | - var $curl_options = array(); // User-specified cURL options |
|
| 51 | - var $use_curl = false; // whether to always try to use cURL |
|
| 50 | + var $curl_options = array(); // User-specified cURL options |
|
| 51 | + var $use_curl = false; // whether to always try to use cURL |
|
| 52 | 52 | // for HTTP authentication |
| 53 | - var $username = ''; // Username for HTTP authentication |
|
| 54 | - var $password = ''; // Password for HTTP authentication |
|
| 55 | - var $authtype = ''; // Type of HTTP authentication |
|
| 56 | - var $certRequest = array(); // Certificate for HTTP SSL authentication |
|
| 53 | + var $username = ''; // Username for HTTP authentication |
|
| 54 | + var $password = ''; // Password for HTTP authentication |
|
| 55 | + var $authtype = ''; // Type of HTTP authentication |
|
| 56 | + var $certRequest = array(); // Certificate for HTTP SSL authentication |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * constructor |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @param boolean $use_curl try to use cURL |
| 70 | 70 | * @access public |
| 71 | 71 | */ |
| 72 | - function wsdl($wsdl = '',$proxyhost=false,$proxyport=false,$proxyusername=false,$proxypassword=false,$timeout=0,$response_timeout=30,$curl_options=null,$use_curl=false){ |
|
| 72 | + function wsdl($wsdl = '', $proxyhost = false, $proxyport = false, $proxyusername = false, $proxypassword = false, $timeout = 0, $response_timeout = 30, $curl_options = null, $use_curl = false) { |
|
| 73 | 73 | parent::nusoap_base(); |
| 74 | 74 | $this->debug("ctor wsdl=$wsdl timeout=$timeout response_timeout=$response_timeout"); |
| 75 | 75 | $this->proxyhost = $proxyhost; |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | // Schema imports |
| 106 | 106 | foreach ($this->schemas as $ns => $list) { |
| 107 | 107 | foreach ($list as $xs) { |
| 108 | - $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
| 108 | + $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
| 109 | 109 | foreach ($xs->imports as $ns2 => $list2) { |
| 110 | 110 | for ($ii = 0; $ii < count($list2); $ii++) { |
| 111 | - if (! $list2[$ii]['loaded']) { |
|
| 111 | + if (!$list2[$ii]['loaded']) { |
|
| 112 | 112 | /* |
| 113 | 113 | * Substituted with line below |
| 114 | 114 | * because of error "Warning: attempt to modify property of non-object" |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | if ($url != '') { |
| 120 | 120 | $urlparts = parse_url($url); |
| 121 | 121 | if (!isset($urlparts['host'])) { |
| 122 | - $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' .$wsdlparts['port'] : '') . |
|
| 123 | - substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
|
| 122 | + $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') . |
|
| 123 | + substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path']; |
|
| 124 | 124 | } |
| 125 | - if (! in_array($url, $imported_urls)) { |
|
| 125 | + if (!in_array($url, $imported_urls)) { |
|
| 126 | 126 | $this->parseWSDL($url); |
| 127 | 127 | $imported++; |
| 128 | 128 | $imported_urls[] = $url; |
@@ -136,19 +136,19 @@ discard block |
||
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | // WSDL imports |
| 139 | - $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
| 139 | + $wsdlparts = parse_url($this->wsdl); // this is bogusly simple! |
|
| 140 | 140 | foreach ($this->import as $ns => $list) { |
| 141 | 141 | for ($ii = 0; $ii < count($list); $ii++) { |
| 142 | - if (! $list[$ii]['loaded']) { |
|
| 142 | + if (!$list[$ii]['loaded']) { |
|
| 143 | 143 | $this->import[$ns][$ii]['loaded'] = true; |
| 144 | 144 | $url = $list[$ii]['location']; |
| 145 | 145 | if ($url != '') { |
| 146 | 146 | $urlparts = parse_url($url); |
| 147 | 147 | if (!isset($urlparts['host'])) { |
| 148 | 148 | $url = $wsdlparts['scheme'] . '://' . $wsdlparts['host'] . (isset($wsdlparts['port']) ? ':' . $wsdlparts['port'] : '') . |
| 149 | - substr($wsdlparts['path'],0,strrpos($wsdlparts['path'],'/') + 1) .$urlparts['path']; |
|
| 149 | + substr($wsdlparts['path'], 0, strrpos($wsdlparts['path'], '/') + 1) . $urlparts['path']; |
|
| 150 | 150 | } |
| 151 | - if (! in_array($url, $imported_urls)) { |
|
| 151 | + if (!in_array($url, $imported_urls)) { |
|
| 152 | 152 | $this->parseWSDL($url); |
| 153 | 153 | $imported++; |
| 154 | 154 | $imported_urls[] = $url; |
@@ -161,30 +161,28 @@ discard block |
||
| 161 | 161 | } |
| 162 | 162 | } |
| 163 | 163 | // add new data to operation data |
| 164 | - foreach($this->bindings as $binding => $bindingData) { |
|
| 164 | + foreach ($this->bindings as $binding => $bindingData) { |
|
| 165 | 165 | if (isset($bindingData['operations']) && is_array($bindingData['operations'])) { |
| 166 | - foreach($bindingData['operations'] as $operation => $data) { |
|
| 166 | + foreach ($bindingData['operations'] as $operation => $data) { |
|
| 167 | 167 | $this->debug('post-parse data gathering for ' . $operation); |
| 168 | 168 | $this->bindings[$binding]['operations'][$operation]['input'] = |
| 169 | 169 | isset($this->bindings[$binding]['operations'][$operation]['input']) ? |
| 170 | - array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[ $bindingData['portType'] ][$operation]['input']) : |
|
| 171 | - $this->portTypes[ $bindingData['portType'] ][$operation]['input']; |
|
| 170 | + array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) : $this->portTypes[$bindingData['portType']][$operation]['input']; |
|
| 172 | 171 | $this->bindings[$binding]['operations'][$operation]['output'] = |
| 173 | 172 | isset($this->bindings[$binding]['operations'][$operation]['output']) ? |
| 174 | - array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[ $bindingData['portType'] ][$operation]['output']) : |
|
| 175 | - $this->portTypes[ $bindingData['portType'] ][$operation]['output']; |
|
| 176 | - if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ])){ |
|
| 177 | - $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['input']['message'] ]; |
|
| 173 | + array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) : $this->portTypes[$bindingData['portType']][$operation]['output']; |
|
| 174 | + if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) { |
|
| 175 | + $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']]; |
|
| 178 | 176 | } |
| 179 | - if(isset($this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ])){ |
|
| 180 | - $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[ $this->bindings[$binding]['operations'][$operation]['output']['message'] ]; |
|
| 177 | + if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']])) { |
|
| 178 | + $this->bindings[$binding]['operations'][$operation]['output']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['output']['message']]; |
|
| 181 | 179 | } |
| 182 | 180 | // Set operation style if necessary, but do not override one already provided |
| 183 | 181 | if (isset($bindingData['style']) && !isset($this->bindings[$binding]['operations'][$operation]['style'])) { |
| 184 | 182 | $this->bindings[$binding]['operations'][$operation]['style'] = $bindingData['style']; |
| 185 | 183 | } |
| 186 | 184 | $this->bindings[$binding]['operations'][$operation]['transport'] = isset($bindingData['transport']) ? $bindingData['transport'] : ''; |
| 187 | - $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[ $bindingData['portType'] ][$operation]['documentation']) ? $this->portTypes[ $bindingData['portType'] ][$operation]['documentation'] : ''; |
|
| 185 | + $this->bindings[$binding]['operations'][$operation]['documentation'] = isset($this->portTypes[$bindingData['portType']][$operation]['documentation']) ? $this->portTypes[$bindingData['portType']][$operation]['documentation'] : ''; |
|
| 188 | 186 | $this->bindings[$binding]['operations'][$operation]['endpoint'] = isset($bindingData['endpoint']) ? $bindingData['endpoint'] : ''; |
| 189 | 187 | } |
| 190 | 188 | } |
@@ -215,8 +213,8 @@ discard block |
||
| 215 | 213 | $tr = new soap_transport_http($wsdl, $this->curl_options, $this->use_curl); |
| 216 | 214 | $tr->request_method = 'GET'; |
| 217 | 215 | $tr->useSOAPAction = false; |
| 218 | - if($this->proxyhost && $this->proxyport){ |
|
| 219 | - $tr->setProxy($this->proxyhost,$this->proxyport,$this->proxyusername,$this->proxypassword); |
|
| 216 | + if ($this->proxyhost && $this->proxyport) { |
|
| 217 | + $tr->setProxy($this->proxyhost, $this->proxyport, $this->proxyusername, $this->proxypassword); |
|
| 220 | 218 | } |
| 221 | 219 | if ($this->authtype != '') { |
| 222 | 220 | $tr->setCredentials($this->username, $this->password, $this->authtype, array(), $this->certRequest); |
@@ -225,8 +223,8 @@ discard block |
||
| 225 | 223 | $wsdl_string = $tr->send('', $this->timeout, $this->response_timeout); |
| 226 | 224 | $this->appendDebug($tr->getDebug()); |
| 227 | 225 | // catch errors |
| 228 | - if($err = $tr->getError() ){ |
|
| 229 | - $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: '.$err; |
|
| 226 | + if ($err = $tr->getError()) { |
|
| 227 | + $errstr = 'Getting ' . $wsdl . ' - HTTP ERROR: ' . $err; |
|
| 230 | 228 | $this->debug($errstr); |
| 231 | 229 | $this->setError($errstr); |
| 232 | 230 | unset($tr); |
@@ -285,7 +283,7 @@ discard block |
||
| 285 | 283 | xml_parser_free($this->parser); |
| 286 | 284 | $this->debug('Parsing WSDL done'); |
| 287 | 285 | // catch wsdl parse errors |
| 288 | - if($this->getError()){ |
|
| 286 | + if ($this->getError()) { |
|
| 289 | 287 | return false; |
| 290 | 288 | } |
| 291 | 289 | return true; |
@@ -322,8 +320,8 @@ discard block |
||
| 322 | 320 | // process attributes |
| 323 | 321 | if (count($attrs) > 0) { |
| 324 | 322 | // register namespace declarations |
| 325 | - foreach($attrs as $k => $v) { |
|
| 326 | - if (preg_match('/^xmlns/',$k)) { |
|
| 323 | + foreach ($attrs as $k => $v) { |
|
| 324 | + if (preg_match('/^xmlns/', $k)) { |
|
| 327 | 325 | if ($ns_prefix = substr(strrchr($k, ':'), 1)) { |
| 328 | 326 | $this->namespaces[$ns_prefix] = $v; |
| 329 | 327 | } else { |
@@ -336,7 +334,7 @@ discard block |
||
| 336 | 334 | } |
| 337 | 335 | } |
| 338 | 336 | // expand each attribute prefix to its namespace |
| 339 | - foreach($attrs as $k => $v) { |
|
| 337 | + foreach ($attrs as $k => $v) { |
|
| 340 | 338 | $k = strpos($k, ':') ? $this->expandQname($k) : $k; |
| 341 | 339 | if ($k != 'location' && $k != 'soapAction' && $k != 'namespace') { |
| 342 | 340 | $v = strpos($v, ':') ? $this->expandQname($v) : $v; |
@@ -443,8 +441,8 @@ discard block |
||
| 443 | 441 | case 'address': |
| 444 | 442 | $this->ports[$this->currentPort]['location'] = $attrs['location']; |
| 445 | 443 | $this->ports[$this->currentPort]['bindingType'] = $namespace; |
| 446 | - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['bindingType'] = $namespace; |
|
| 447 | - $this->bindings[ $this->ports[$this->currentPort]['binding'] ]['endpoint'] = $attrs['location']; |
|
| 444 | + $this->bindings[$this->ports[$this->currentPort]['binding']]['bindingType'] = $namespace; |
|
| 445 | + $this->bindings[$this->ports[$this->currentPort]['binding']]['endpoint'] = $attrs['location']; |
|
| 448 | 446 | break; |
| 449 | 447 | } |
| 450 | 448 | break; |
@@ -454,13 +452,13 @@ discard block |
||
| 454 | 452 | case 'import': |
| 455 | 453 | if (isset($attrs['location'])) { |
| 456 | 454 | $this->import[$attrs['namespace']][] = array('location' => $attrs['location'], 'loaded' => false); |
| 457 | - $this->debug('parsing import ' . $attrs['namespace']. ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]).')'); |
|
| 455 | + $this->debug('parsing import ' . $attrs['namespace'] . ' - ' . $attrs['location'] . ' (' . count($this->import[$attrs['namespace']]) . ')'); |
|
| 458 | 456 | } else { |
| 459 | 457 | $this->import[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
| 460 | - if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
|
| 461 | - $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
|
| 458 | + if (!$this->getPrefixFromNamespace($attrs['namespace'])) { |
|
| 459 | + $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace']; |
|
| 462 | 460 | } |
| 463 | - $this->debug('parsing import ' . $attrs['namespace']. ' - [no location] (' . count($this->import[$attrs['namespace']]).')'); |
|
| 461 | + $this->debug('parsing import ' . $attrs['namespace'] . ' - [no location] (' . count($this->import[$attrs['namespace']]) . ')'); |
|
| 464 | 462 | } |
| 465 | 463 | break; |
| 466 | 464 | //wait for schema |
@@ -511,7 +509,7 @@ discard block |
||
| 511 | 509 | * @param string $name element name |
| 512 | 510 | * @access private |
| 513 | 511 | */ |
| 514 | - public function end_element($parser, $name){ |
|
| 512 | + public function end_element($parser, $name) { |
|
| 515 | 513 | // unset schema status |
| 516 | 514 | if (/*preg_match('/types$/', $name) ||*/ preg_match('/schema$/', $name)) { |
| 517 | 515 | $this->status = ""; |
@@ -595,15 +593,15 @@ discard block |
||
| 595 | 593 | } |
| 596 | 594 | $this->debug("getOperations for port '$portName' bindingType $bindingType"); |
| 597 | 595 | // loop thru ports |
| 598 | - foreach($this->ports as $port => $portData) { |
|
| 596 | + foreach ($this->ports as $port => $portData) { |
|
| 599 | 597 | $this->debug("getOperations checking port $port bindingType " . $portData['bindingType']); |
| 600 | 598 | if ($portName == '' || $port == $portName) { |
| 601 | 599 | // binding type of port matches parameter |
| 602 | 600 | if ($portData['bindingType'] == $bindingType) { |
| 603 | 601 | $this->debug("getOperations found port $port bindingType $bindingType"); |
| 604 | 602 | // merge bindings |
| 605 | - if (isset($this->bindings[ $portData['binding'] ]['operations'])) { |
|
| 606 | - $ops = array_merge ($ops, $this->bindings[ $portData['binding'] ]['operations']); |
|
| 603 | + if (isset($this->bindings[$portData['binding']]['operations'])) { |
|
| 604 | + $ops = array_merge($ops, $this->bindings[$portData['binding']]['operations']); |
|
| 607 | 605 | } |
| 608 | 606 | } |
| 609 | 607 | } |
@@ -630,15 +628,15 @@ discard block |
||
| 630 | 628 | $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
| 631 | 629 | } |
| 632 | 630 | // loop thru ports |
| 633 | - foreach($this->ports as $port => $portData) { |
|
| 631 | + foreach ($this->ports as $port => $portData) { |
|
| 634 | 632 | // binding type of port matches parameter |
| 635 | 633 | if ($portData['bindingType'] == $bindingType) { |
| 636 | 634 | // get binding |
| 637 | 635 | //foreach($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
| 638 | - foreach(array_keys($this->bindings[ $portData['binding'] ]['operations']) as $bOperation) { |
|
| 636 | + foreach (array_keys($this->bindings[$portData['binding']]['operations']) as $bOperation) { |
|
| 639 | 637 | // note that we could/should also check the namespace here |
| 640 | 638 | if ($operation == $bOperation) { |
| 641 | - $opData = $this->bindings[ $portData['binding'] ]['operations'][$operation]; |
|
| 639 | + $opData = $this->bindings[$portData['binding']]['operations'][$operation]; |
|
| 642 | 640 | return $opData; |
| 643 | 641 | } |
| 644 | 642 | } |
@@ -661,11 +659,11 @@ discard block |
||
| 661 | 659 | $bindingType = 'http://schemas.xmlsoap.org/wsdl/soap12/'; |
| 662 | 660 | } |
| 663 | 661 | // loop thru ports |
| 664 | - foreach($this->ports as $port => $portData) { |
|
| 662 | + foreach ($this->ports as $port => $portData) { |
|
| 665 | 663 | // binding type of port matches parameter |
| 666 | 664 | if ($portData['bindingType'] == $bindingType) { |
| 667 | 665 | // loop through operations for the binding |
| 668 | - foreach ($this->bindings[ $portData['binding'] ]['operations'] as $bOperation => $opData) { |
|
| 666 | + foreach ($this->bindings[$portData['binding']]['operations'] as $bOperation => $opData) { |
|
| 669 | 667 | if ($opData['soapAction'] == $soapAction) { |
| 670 | 668 | return $opData; |
| 671 | 669 | } |
@@ -694,7 +692,7 @@ discard block |
||
| 694 | 692 | */ |
| 695 | 693 | public function getTypeDef($type, $ns) { |
| 696 | 694 | $this->debug("in getTypeDef: type=$type, ns=$ns"); |
| 697 | - if ((! $ns) && isset($this->namespaces['tns'])) { |
|
| 695 | + if ((!$ns) && isset($this->namespaces['tns'])) { |
|
| 698 | 696 | $ns = $this->namespaces['tns']; |
| 699 | 697 | $this->debug("in getTypeDef: type namespace forced to $ns"); |
| 700 | 698 | } |
@@ -752,7 +750,7 @@ discard block |
||
| 752 | 750 | * |
| 753 | 751 | * @access private |
| 754 | 752 | */ |
| 755 | - function webDescription(){ |
|
| 753 | + function webDescription() { |
|
| 756 | 754 | global $HTTP_SERVER_VARS; |
| 757 | 755 | |
| 758 | 756 | if (isset($_SERVER)) { |
@@ -764,7 +762,7 @@ discard block |
||
| 764 | 762 | } |
| 765 | 763 | |
| 766 | 764 | $b = ' |
| 767 | - <html><head><title>NuSOAP: '.$this->serviceName.'</title> |
|
| 765 | + <html><head><title>NuSOAP: '.$this->serviceName . '</title> |
|
| 768 | 766 | <style type="text/css"> |
| 769 | 767 | body { font-family: arial; color: #000000; background-color: #ffffff; margin: 0px 0px 0px 0px; } |
| 770 | 768 | p { font-family: arial; color: #000000; margin-top: 0px; margin-bottom: 12px; } |
@@ -841,24 +839,24 @@ discard block |
||
| 841 | 839 | <body> |
| 842 | 840 | <div class=content> |
| 843 | 841 | <br><br> |
| 844 | - <div class=title>'.$this->serviceName.'</div> |
|
| 842 | + <div class=title>'.$this->serviceName . '</div> |
|
| 845 | 843 | <div class=nav> |
| 846 | - <p>View the <a href="'.$PHP_SELF.'?wsdl">WSDL</a> for the service. |
|
| 844 | + <p>View the <a href="'.$PHP_SELF . '?wsdl">WSDL</a> for the service. |
|
| 847 | 845 | Click on an operation name to view it's details.</p> |
| 848 | 846 | <ul>'; |
| 849 | - foreach($this->getOperations() as $op => $data){ |
|
| 847 | + foreach ($this->getOperations() as $op => $data) { |
|
| 850 | 848 | $b .= "<li><a href='#' onclick=\"popout();popup('$op')\">$op</a></li>"; |
| 851 | 849 | // create hidden div |
| 852 | 850 | $b .= "<div id='$op' class='hidden'> |
| 853 | 851 | <a href='#' onclick='popout()'><font color='#ffffff'>Close</font></a><br><br>"; |
| 854 | - foreach($data as $donnie => $marie){ // loop through opdata |
|
| 855 | - if($donnie == 'input' || $donnie == 'output'){ // show input/output data |
|
| 856 | - $b .= "<font color='white'>".ucfirst($donnie).':</font><br>'; |
|
| 857 | - foreach($marie as $captain => $tenille){ // loop through data |
|
| 858 | - if($captain == 'parts'){ // loop thru parts |
|
| 852 | + foreach ($data as $donnie => $marie) { // loop through opdata |
|
| 853 | + if ($donnie == 'input' || $donnie == 'output') { // show input/output data |
|
| 854 | + $b .= "<font color='white'>" . ucfirst($donnie) . ':</font><br>'; |
|
| 855 | + foreach ($marie as $captain => $tenille) { // loop through data |
|
| 856 | + if ($captain == 'parts') { // loop thru parts |
|
| 859 | 857 | $b .= " $captain:<br>"; |
| 860 | 858 | //if(is_array($tenille)){ |
| 861 | - foreach($tenille as $joanie => $chachi){ |
|
| 859 | + foreach ($tenille as $joanie => $chachi) { |
|
| 862 | 860 | $b .= " $joanie: $chachi<br>"; |
| 863 | 861 | } |
| 864 | 862 | //} |
@@ -867,7 +865,7 @@ discard block |
||
| 867 | 865 | } |
| 868 | 866 | } |
| 869 | 867 | } else { |
| 870 | - $b .= "<font color='white'>".ucfirst($donnie).":</font> $marie<br>"; |
|
| 868 | + $b .= "<font color='white'>" . ucfirst($donnie) . ":</font> $marie<br>"; |
|
| 871 | 869 | } |
| 872 | 870 | } |
| 873 | 871 | $b .= '</div>'; |
@@ -890,7 +888,7 @@ discard block |
||
| 890 | 888 | { |
| 891 | 889 | $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'; |
| 892 | 890 | $xml .= "\n<definitions"; |
| 893 | - foreach($this->namespaces as $k => $v) { |
|
| 891 | + foreach ($this->namespaces as $k => $v) { |
|
| 894 | 892 | $xml .= " xmlns:$k=\"$v\""; |
| 895 | 893 | } |
| 896 | 894 | // 10.9.02 - add poulter fix for wsdl and tns declarations |
@@ -903,7 +901,7 @@ discard block |
||
| 903 | 901 | $xml .= '>'; |
| 904 | 902 | // imports |
| 905 | 903 | if (sizeof($this->import) > 0) { |
| 906 | - foreach($this->import as $ns => $list) { |
|
| 904 | + foreach ($this->import as $ns => $list) { |
|
| 907 | 905 | foreach ($list as $ii) { |
| 908 | 906 | if ($ii['location'] != '') { |
| 909 | 907 | $xml .= '<import location="' . $ii['location'] . '" namespace="' . $ns . '" />'; |
@@ -914,7 +912,7 @@ discard block |
||
| 914 | 912 | } |
| 915 | 913 | } |
| 916 | 914 | // types |
| 917 | - if (count($this->schemas)>=1) { |
|
| 915 | + if (count($this->schemas) >= 1) { |
|
| 918 | 916 | $xml .= "\n<types>\n"; |
| 919 | 917 | foreach ($this->schemas as $ns => $list) { |
| 920 | 918 | foreach ($list as $xs) { |
@@ -925,10 +923,10 @@ discard block |
||
| 925 | 923 | } |
| 926 | 924 | // messages |
| 927 | 925 | if (count($this->messages) >= 1) { |
| 928 | - foreach($this->messages as $msgName => $msgParts) { |
|
| 926 | + foreach ($this->messages as $msgName => $msgParts) { |
|
| 929 | 927 | $xml .= "\n<message name=\"" . $msgName . '">'; |
| 930 | - if(is_array($msgParts)){ |
|
| 931 | - foreach($msgParts as $partName => $partType) { |
|
| 928 | + if (is_array($msgParts)) { |
|
| 929 | + foreach ($msgParts as $partName => $partType) { |
|
| 932 | 930 | // print 'serializing '.$partType.', sv: '.$this->XMLSchemaVersion.'<br>'; |
| 933 | 931 | if (strpos($partType, ':')) { |
| 934 | 932 | $typePrefix = $this->getPrefixFromNamespace($this->getPrefix($partType)); |
@@ -936,7 +934,7 @@ discard block |
||
| 936 | 934 | // print 'checking typemap: '.$this->XMLSchemaVersion.'<br>'; |
| 937 | 935 | $typePrefix = 'xsd'; |
| 938 | 936 | } else { |
| 939 | - foreach($this->typemap as $ns => $types) { |
|
| 937 | + foreach ($this->typemap as $ns => $types) { |
|
| 940 | 938 | if (isset($types[$partType])) { |
| 941 | 939 | $typePrefix = $this->getPrefixFromNamespace($ns); |
| 942 | 940 | } |
@@ -966,13 +964,13 @@ discard block |
||
| 966 | 964 | if (count($this->bindings) >= 1) { |
| 967 | 965 | $binding_xml = ''; |
| 968 | 966 | $portType_xml = ''; |
| 969 | - foreach($this->bindings as $bindingName => $attrs) { |
|
| 967 | + foreach ($this->bindings as $bindingName => $attrs) { |
|
| 970 | 968 | $binding_xml .= "\n<binding name=\"" . $bindingName . '" type="tns:' . $attrs['portType'] . '">'; |
| 971 | 969 | $binding_xml .= "\n" . ' <soap:binding style="' . $attrs['style'] . '" transport="' . $attrs['transport'] . '"/>'; |
| 972 | 970 | $portType_xml .= "\n<portType name=\"" . $attrs['portType'] . '">'; |
| 973 | - foreach($attrs['operations'] as $opName => $opParts) { |
|
| 971 | + foreach ($attrs['operations'] as $opName => $opParts) { |
|
| 974 | 972 | $binding_xml .= "\n" . ' <operation name="' . $opName . '">'; |
| 975 | - $binding_xml .= "\n" . ' <soap:operation soapAction="' . $opParts['soapAction'] . '" style="'. $opParts['style'] . '"/>'; |
|
| 973 | + $binding_xml .= "\n" . ' <soap:operation soapAction="' . $opParts['soapAction'] . '" style="' . $opParts['style'] . '"/>'; |
|
| 976 | 974 | if (isset($opParts['input']['encodingStyle']) && $opParts['input']['encodingStyle'] != '') { |
| 977 | 975 | $enc_style = ' encodingStyle="' . $opParts['input']['encodingStyle'] . '"'; |
| 978 | 976 | } else { |
@@ -991,7 +989,7 @@ discard block |
||
| 991 | 989 | $portType_xml .= ' parameterOrder="' . $opParts['parameterOrder'] . '"'; |
| 992 | 990 | } |
| 993 | 991 | $portType_xml .= '>'; |
| 994 | - if(isset($opParts['documentation']) && $opParts['documentation'] != '') { |
|
| 992 | + if (isset($opParts['documentation']) && $opParts['documentation'] != '') { |
|
| 995 | 993 | $portType_xml .= "\n" . ' <documentation>' . htmlspecialchars($opParts['documentation']) . '</documentation>'; |
| 996 | 994 | } |
| 997 | 995 | $portType_xml .= "\n" . ' <input message="tns:' . $opParts['input']['message'] . '"/>'; |
@@ -1006,7 +1004,7 @@ discard block |
||
| 1006 | 1004 | // services |
| 1007 | 1005 | $xml .= "\n<service name=\"" . $this->serviceName . '">'; |
| 1008 | 1006 | if (count($this->ports) >= 1) { |
| 1009 | - foreach($this->ports as $pName => $attrs) { |
|
| 1007 | + foreach ($this->ports as $pName => $attrs) { |
|
| 1010 | 1008 | $xml .= "\n" . ' <port name="' . $pName . '" binding="tns:' . $attrs['binding'] . '">'; |
| 1011 | 1009 | $xml .= "\n" . ' <soap:address location="' . $attrs['location'] . ($debug ? '?debug=1' : '') . '"/>'; |
| 1012 | 1010 | $xml .= "\n" . ' </port>'; |
@@ -1127,7 +1125,7 @@ discard block |
||
| 1127 | 1125 | |
| 1128 | 1126 | // Get encoding style for output and set to current |
| 1129 | 1127 | $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
| 1130 | - if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
| 1128 | + if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
| 1131 | 1129 | $encodingStyle = $opData['output']['encodingStyle']; |
| 1132 | 1130 | $enc_style = $encodingStyle; |
| 1133 | 1131 | } |
@@ -1229,7 +1227,7 @@ discard block |
||
| 1229 | 1227 | |
| 1230 | 1228 | // Get encoding style for output and set to current |
| 1231 | 1229 | $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
| 1232 | - if(($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
| 1230 | + if (($direction == 'input') && isset($opData['output']['encodingStyle']) && ($opData['output']['encodingStyle'] != $encodingStyle)) { |
|
| 1233 | 1231 | $encodingStyle = $opData['output']['encodingStyle']; |
| 1234 | 1232 | $enc_style = $encodingStyle; |
| 1235 | 1233 | } |
@@ -1244,10 +1242,10 @@ discard block |
||
| 1244 | 1242 | if (is_array($parameters)) { |
| 1245 | 1243 | $parametersArrayType = $this->isArraySimpleOrStruct($parameters); |
| 1246 | 1244 | $this->debug('have ' . $parametersArrayType . ' parameters'); |
| 1247 | - foreach($opData[$direction]['parts'] as $name => $type) { |
|
| 1248 | - $this->debug('serializing part "'.$name.'" of type "'.$type.'"'); |
|
| 1245 | + foreach ($opData[$direction]['parts'] as $name => $type) { |
|
| 1246 | + $this->debug('serializing part "' . $name . '" of type "' . $type . '"'); |
|
| 1249 | 1247 | // Track encoding style |
| 1250 | - if(isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { |
|
| 1248 | + if (isset($opData[$direction]['encodingStyle']) && $encodingStyle != $opData[$direction]['encodingStyle']) { |
|
| 1251 | 1249 | $encodingStyle = $opData[$direction]['encodingStyle']; |
| 1252 | 1250 | $enc_style = $encodingStyle; |
| 1253 | 1251 | } else { |
@@ -1288,11 +1286,11 @@ discard block |
||
| 1288 | 1286 | * @return string value serialized as an XML string |
| 1289 | 1287 | * @access private |
| 1290 | 1288 | */ |
| 1291 | - public function serializeType($name, $type, $value, $use='encoded', $encodingStyle=false, $unqualified=false) |
|
| 1289 | + public function serializeType($name, $type, $value, $use = 'encoded', $encodingStyle = false, $unqualified = false) |
|
| 1292 | 1290 | { |
| 1293 | 1291 | $this->debug("in serializeType: name=$name, type=$type, use=$use, encodingStyle=$encodingStyle, unqualified=" . ($unqualified ? "unqualified" : "qualified")); |
| 1294 | 1292 | $this->appendDebug("value=" . $this->varDump($value)); |
| 1295 | - if($use == 'encoded' && $encodingStyle) { |
|
| 1293 | + if ($use == 'encoded' && $encodingStyle) { |
|
| 1296 | 1294 | $encodingStyle = ' SOAP-ENV:encodingStyle="' . $encodingStyle . '"'; |
| 1297 | 1295 | } |
| 1298 | 1296 | |
@@ -1336,7 +1334,7 @@ discard block |
||
| 1336 | 1334 | $this->debug("in serializeType: expanded prefixed type: $uqType, $ns"); |
| 1337 | 1335 | } |
| 1338 | 1336 | |
| 1339 | - if($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/'){ |
|
| 1337 | + if ($ns == $this->XMLSchemaVersion || $ns == 'http://schemas.xmlsoap.org/soap/encoding/') { |
|
| 1340 | 1338 | $this->debug('in serializeType: type namespace indicates XML Schema or SOAP Encoding type'); |
| 1341 | 1339 | if ($unqualified && $use == 'literal') { |
| 1342 | 1340 | $elementNS = " xmlns=\"\""; |
@@ -1359,7 +1357,7 @@ discard block |
||
| 1359 | 1357 | return $this->serialize_val($value, $name, false, false, false, false, $use); |
| 1360 | 1358 | } |
| 1361 | 1359 | if ($uqType == 'boolean') { |
| 1362 | - if ((is_string($value) && $value == 'false') || (! $value)) { |
|
| 1360 | + if ((is_string($value) && $value == 'false') || (!$value)) { |
|
| 1363 | 1361 | $value = 'false'; |
| 1364 | 1362 | } else { |
| 1365 | 1363 | $value = 'true'; |
@@ -1392,7 +1390,7 @@ discard block |
||
| 1392 | 1390 | $this->debug('in serializeType: appears to be Apache SOAP type'); |
| 1393 | 1391 | if ($uqType == 'Map') { |
| 1394 | 1392 | $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); |
| 1395 | - if (! $tt_prefix) { |
|
| 1393 | + if (!$tt_prefix) { |
|
| 1396 | 1394 | $this->debug('in serializeType: Add namespace for Apache SOAP type'); |
| 1397 | 1395 | $tt_prefix = 'ns' . rand(1000, 9999); |
| 1398 | 1396 | $this->namespaces[$tt_prefix] = 'http://xml.apache.org/xml-soap'; |
@@ -1400,11 +1398,11 @@ discard block |
||
| 1400 | 1398 | $tt_prefix = $this->getPrefixFromNamespace('http://xml.apache.org/xml-soap'); |
| 1401 | 1399 | } |
| 1402 | 1400 | $contents = ''; |
| 1403 | - foreach($value as $k => $v) { |
|
| 1401 | + foreach ($value as $k => $v) { |
|
| 1404 | 1402 | $this->debug("serializing map element: key $k, value $v"); |
| 1405 | 1403 | $contents .= '<item>'; |
| 1406 | - $contents .= $this->serialize_val($k,'key',false,false,false,false,$use); |
|
| 1407 | - $contents .= $this->serialize_val($v,'value',false,false,false,false,$use); |
|
| 1404 | + $contents .= $this->serialize_val($k, 'key', false, false, false, false, $use); |
|
| 1405 | + $contents .= $this->serialize_val($v, 'value', false, false, false, false, $use); |
|
| 1408 | 1406 | $contents .= '</item>'; |
| 1409 | 1407 | } |
| 1410 | 1408 | if ($use == 'literal') { |
@@ -1428,7 +1426,7 @@ discard block |
||
| 1428 | 1426 | $ns = ''; |
| 1429 | 1427 | $uqType = $type; |
| 1430 | 1428 | } |
| 1431 | - if(!$typeDef = $this->getTypeDef($uqType, $ns)){ |
|
| 1429 | + if (!$typeDef = $this->getTypeDef($uqType, $ns)) { |
|
| 1432 | 1430 | $this->setError("$type ($uqType) is not a supported type."); |
| 1433 | 1431 | $this->debug("in serializeType: $type ($uqType) is not a supported type."); |
| 1434 | 1432 | return false; |
@@ -1445,7 +1443,7 @@ discard block |
||
| 1445 | 1443 | return false; |
| 1446 | 1444 | } |
| 1447 | 1445 | $phpType = $typeDef['phpType']; |
| 1448 | - $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '') ); |
|
| 1446 | + $this->debug("in serializeType: uqType: $uqType, ns: $ns, phptype: $phpType, arrayType: " . (isset($typeDef['arrayType']) ? $typeDef['arrayType'] : '')); |
|
| 1449 | 1447 | // if php type == struct, map value to the <all> element names |
| 1450 | 1448 | if ($phpType == 'struct') { |
| 1451 | 1449 | if (isset($typeDef['typeClass']) && $typeDef['typeClass'] == 'element') { |
@@ -1527,14 +1525,14 @@ discard block |
||
| 1527 | 1525 | ':arrayType="' . |
| 1528 | 1526 | $this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) . |
| 1529 | 1527 | ':' . |
| 1530 | - $this->getLocalPart($typeDef['arrayType'])."[0]\"/>"; |
|
| 1528 | + $this->getLocalPart($typeDef['arrayType']) . "[0]\"/>"; |
|
| 1531 | 1529 | } |
| 1532 | 1530 | $this->debug("in serializeType: returning: $xml"); |
| 1533 | 1531 | return $xml; |
| 1534 | 1532 | } |
| 1535 | 1533 | if (isset($typeDef['multidimensional'])) { |
| 1536 | 1534 | $nv = array(); |
| 1537 | - foreach($value as $v) { |
|
| 1535 | + foreach ($value as $v) { |
|
| 1538 | 1536 | $cols = ',' . sizeof($v); |
| 1539 | 1537 | $nv = array_merge($nv, $v); |
| 1540 | 1538 | } |
@@ -1545,10 +1543,10 @@ discard block |
||
| 1545 | 1543 | if (is_array($value) && sizeof($value) >= 1) { |
| 1546 | 1544 | $rows = sizeof($value); |
| 1547 | 1545 | $contents = ''; |
| 1548 | - foreach($value as $k => $v) { |
|
| 1546 | + foreach ($value as $k => $v) { |
|
| 1549 | 1547 | $this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]"); |
| 1550 | 1548 | //if (strpos($typeDef['arrayType'], ':') ) { |
| 1551 | - if (!in_array($typeDef['arrayType'],$this->typemap['http://www.w3.org/2001/XMLSchema'])) { |
|
| 1549 | + if (!in_array($typeDef['arrayType'], $this->typemap['http://www.w3.org/2001/XMLSchema'])) { |
|
| 1552 | 1550 | $contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use); |
| 1553 | 1551 | } else { |
| 1554 | 1552 | $contents .= $this->serialize_val($v, 'item', $typeDef['arrayType'], null, $this->XMLSchemaVersion, false, $use); |
@@ -1565,11 +1563,11 @@ discard block |
||
| 1565 | 1563 | .$contents |
| 1566 | 1564 | ."</$name>"; |
| 1567 | 1565 | } else { |
| 1568 | - $xml = "<$name$elementNS xsi:type=\"".$this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/').':Array" '. |
|
| 1566 | + $xml = "<$name$elementNS xsi:type=\"" . $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') . ':Array" ' . |
|
| 1569 | 1567 | $this->getPrefixFromNamespace('http://schemas.xmlsoap.org/soap/encoding/') |
| 1570 | 1568 | .':arrayType="' |
| 1571 | 1569 | .$this->getPrefixFromNamespace($this->getPrefix($typeDef['arrayType'])) |
| 1572 | - .":".$this->getLocalPart($typeDef['arrayType'])."[$rows$cols]\">" |
|
| 1570 | + .":" . $this->getLocalPart($typeDef['arrayType']) . "[$rows$cols]\">" |
|
| 1573 | 1571 | .$contents |
| 1574 | 1572 | ."</$name>"; |
| 1575 | 1573 | } |
@@ -1649,7 +1647,7 @@ discard block |
||
| 1649 | 1647 | $this->debug("no value provided for attribute $aName"); |
| 1650 | 1648 | } |
| 1651 | 1649 | if ($xname) { |
| 1652 | - $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\""; |
|
| 1650 | + $xml .= " $aName=\"" . $this->expandEntities($xvalue[$xname]) . "\""; |
|
| 1653 | 1651 | } |
| 1654 | 1652 | } |
| 1655 | 1653 | } else { |
@@ -1670,7 +1668,7 @@ discard block |
||
| 1670 | 1668 | * @return string value serialized as an XML string |
| 1671 | 1669 | * @access private |
| 1672 | 1670 | */ |
| 1673 | - public function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use='encoded', $encodingStyle=false) { |
|
| 1671 | + public function serializeComplexTypeElements($typeDef, $value, $ns, $uqType, $use = 'encoded', $encodingStyle = false) { |
|
| 1674 | 1672 | $this->debug("in serializeComplexTypeElements for XML Schema type $ns:$uqType"); |
| 1675 | 1673 | $xml = ''; |
| 1676 | 1674 | if (isset($typeDef['extensionBase'])) { |
@@ -1697,7 +1695,7 @@ discard block |
||
| 1697 | 1695 | $xvalue = array(); |
| 1698 | 1696 | } |
| 1699 | 1697 | // toggle whether all elements are present - ideally should validate against schema |
| 1700 | - if (count($typeDef['elements']) != count($xvalue)){ |
|
| 1698 | + if (count($typeDef['elements']) != count($xvalue)) { |
|
| 1701 | 1699 | $optionals = true; |
| 1702 | 1700 | } |
| 1703 | 1701 | foreach ($typeDef['elements'] as $eName => $attrs) { |
@@ -1710,8 +1708,8 @@ discard block |
||
| 1710 | 1708 | // if user took advantage of a minOccurs=0, then only serialize named parameters |
| 1711 | 1709 | if (isset($optionals) |
| 1712 | 1710 | && (!isset($xvalue[$eName])) |
| 1713 | - && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
| 1714 | - ){ |
|
| 1711 | + && ((!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
| 1712 | + ) { |
|
| 1715 | 1713 | if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') { |
| 1716 | 1714 | $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']); |
| 1717 | 1715 | } |
@@ -1778,15 +1776,15 @@ discard block |
||
| 1778 | 1776 | * @see nusoap_xmlschema |
| 1779 | 1777 | * @access public |
| 1780 | 1778 | */ |
| 1781 | - public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType='') { |
|
| 1779 | + public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '') { |
|
| 1782 | 1780 | if (count($elements) > 0) { |
| 1783 | 1781 | $eElements = array(); |
| 1784 | - foreach($elements as $n => $e){ |
|
| 1782 | + foreach ($elements as $n => $e) { |
|
| 1785 | 1783 | // expand each element |
| 1786 | 1784 | $ee = array(); |
| 1787 | 1785 | foreach ($e as $k => $v) { |
| 1788 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 1789 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 1786 | + $k = strpos($k, ':') ? $this->expandQname($k) : $k; |
|
| 1787 | + $v = strpos($v, ':') ? $this->expandQname($v) : $v; |
|
| 1790 | 1788 | $ee[$k] = $v; |
| 1791 | 1789 | } |
| 1792 | 1790 | $eElements[$n] = $ee; |
@@ -1795,11 +1793,11 @@ discard block |
||
| 1795 | 1793 | } |
| 1796 | 1794 | |
| 1797 | 1795 | if (count($attrs) > 0) { |
| 1798 | - foreach($attrs as $n => $a){ |
|
| 1796 | + foreach ($attrs as $n => $a) { |
|
| 1799 | 1797 | // expand each attribute |
| 1800 | 1798 | foreach ($a as $k => $v) { |
| 1801 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 1802 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 1799 | + $k = strpos($k, ':') ? $this->expandQname($k) : $k; |
|
| 1800 | + $v = strpos($v, ':') ? $this->expandQname($v) : $v; |
|
| 1803 | 1801 | $aa[$k] = $v; |
| 1804 | 1802 | } |
| 1805 | 1803 | $eAttrs[$n] = $aa; |
@@ -1807,11 +1805,11 @@ discard block |
||
| 1807 | 1805 | $attrs = $eAttrs; |
| 1808 | 1806 | } |
| 1809 | 1807 | |
| 1810 | - $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
| 1811 | - $arrayType = strpos($arrayType,':') ? $this->expandQname($arrayType) : $arrayType; |
|
| 1808 | + $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
| 1809 | + $arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType; |
|
| 1812 | 1810 | |
| 1813 | 1811 | $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
| 1814 | - $this->schemas[$typens][0]->addComplexType($name,$typeClass,$phpType,$compositor,$restrictionBase,$elements,$attrs,$arrayType); |
|
| 1812 | + $this->schemas[$typens][0]->addComplexType($name, $typeClass, $phpType, $compositor, $restrictionBase, $elements, $attrs, $arrayType); |
|
| 1815 | 1813 | } |
| 1816 | 1814 | |
| 1817 | 1815 | /** |
@@ -1825,8 +1823,8 @@ discard block |
||
| 1825 | 1823 | * @see nusoap_xmlschema |
| 1826 | 1824 | * @access public |
| 1827 | 1825 | */ |
| 1828 | - public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
|
| 1829 | - $restrictionBase = strpos($restrictionBase,':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
| 1826 | + public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array()) { |
|
| 1827 | + $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
| 1830 | 1828 | |
| 1831 | 1829 | $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
| 1832 | 1830 | $this->schemas[$typens][0]->addSimpleType($name, $restrictionBase, $typeClass, $phpType, $enumeration); |
@@ -1858,7 +1856,7 @@ discard block |
||
| 1858 | 1856 | * @param string $encodingStyle optional (usually 'http://schemas.xmlsoap.org/soap/encoding/' for encoded) |
| 1859 | 1857 | * @access public |
| 1860 | 1858 | */ |
| 1861 | - public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = ''){ |
|
| 1859 | + public function addOperation($name, $in = false, $out = false, $namespace = false, $soapaction = false, $style = 'rpc', $use = 'encoded', $documentation = '', $encodingStyle = '') { |
|
| 1862 | 1860 | if ($use == 'encoded' && $encodingStyle == '') { |
| 1863 | 1861 | $encodingStyle = 'http://schemas.xmlsoap.org/soap/encoding/'; |
| 1864 | 1862 | } |
@@ -1882,7 +1880,7 @@ discard block |
||
| 1882 | 1880 | } |
| 1883 | 1881 | |
| 1884 | 1882 | // get binding |
| 1885 | - $this->bindings[ $this->serviceName . 'Binding' ]['operations'][$name] = |
|
| 1883 | + $this->bindings[$this->serviceName . 'Binding']['operations'][$name] = |
|
| 1886 | 1884 | array( |
| 1887 | 1885 | 'name' => $name, |
| 1888 | 1886 | 'binding' => $this->serviceName . 'Binding', |
@@ -1906,29 +1904,29 @@ discard block |
||
| 1906 | 1904 | 'documentation' => $documentation); |
| 1907 | 1905 | // add portTypes |
| 1908 | 1906 | // add messages |
| 1909 | - if($in) |
|
| 1907 | + if ($in) |
|
| 1910 | 1908 | { |
| 1911 | - foreach($in as $pName => $pType) |
|
| 1909 | + foreach ($in as $pName => $pType) |
|
| 1912 | 1910 | { |
| 1913 | - if(strpos($pType,':')) { |
|
| 1914 | - $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType); |
|
| 1911 | + if (strpos($pType, ':')) { |
|
| 1912 | + $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType); |
|
| 1915 | 1913 | } |
| 1916 | - $this->messages[$name.'Request'][$pName] = $pType; |
|
| 1914 | + $this->messages[$name . 'Request'][$pName] = $pType; |
|
| 1917 | 1915 | } |
| 1918 | 1916 | } else { |
| 1919 | - $this->messages[$name.'Request']= '0'; |
|
| 1917 | + $this->messages[$name . 'Request'] = '0'; |
|
| 1920 | 1918 | } |
| 1921 | - if($out) |
|
| 1919 | + if ($out) |
|
| 1922 | 1920 | { |
| 1923 | - foreach($out as $pName => $pType) |
|
| 1921 | + foreach ($out as $pName => $pType) |
|
| 1924 | 1922 | { |
| 1925 | - if(strpos($pType,':')) { |
|
| 1926 | - $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)).":".$this->getLocalPart($pType); |
|
| 1923 | + if (strpos($pType, ':')) { |
|
| 1924 | + $pType = $this->getNamespaceFromPrefix($this->getPrefix($pType)) . ":" . $this->getLocalPart($pType); |
|
| 1927 | 1925 | } |
| 1928 | - $this->messages[$name.'Response'][$pName] = $pType; |
|
| 1926 | + $this->messages[$name . 'Response'][$pName] = $pType; |
|
| 1929 | 1927 | } |
| 1930 | 1928 | } else { |
| 1931 | - $this->messages[$name.'Response']= '0'; |
|
| 1929 | + $this->messages[$name . 'Response'] = '0'; |
|
| 1932 | 1930 | } |
| 1933 | 1931 | return true; |
| 1934 | 1932 | } |
@@ -78,8 +78,9 @@ |
||
| 78 | 78 | $this->proxypassword = $proxypassword; |
| 79 | 79 | $this->timeout = $timeout; |
| 80 | 80 | $this->response_timeout = $response_timeout; |
| 81 | - if (is_array($curl_options)) |
|
| 82 | - $this->curl_options = $curl_options; |
|
| 81 | + if (is_array($curl_options)) { |
|
| 82 | + $this->curl_options = $curl_options; |
|
| 83 | + } |
|
| 83 | 84 | $this->use_curl = $use_curl; |
| 84 | 85 | $this->fetchWSDL($wsdl); |
| 85 | 86 | } |
@@ -779,7 +779,7 @@ |
||
| 779 | 779 | * returns a sample serialization of a given type, or false if no type by the given name |
| 780 | 780 | * |
| 781 | 781 | * @param string $type name of type |
| 782 | - * @return mixed |
|
| 782 | + * @return string|false |
|
| 783 | 783 | * @access public |
| 784 | 784 | * @deprecated |
| 785 | 785 | */ |
@@ -44,13 +44,13 @@ discard block |
||
| 44 | 44 | var $defaultNamespace = array(); |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * constructor |
|
| 48 | - * |
|
| 49 | - * @param string $schema schema document URI |
|
| 50 | - * @param string $xml xml document URI |
|
| 51 | - * @param string $namespaces namespaces defined in enclosing XML |
|
| 52 | - * @access public |
|
| 53 | - */ |
|
| 47 | + * constructor |
|
| 48 | + * |
|
| 49 | + * @param string $schema schema document URI |
|
| 50 | + * @param string $xml xml document URI |
|
| 51 | + * @param string $namespaces namespaces defined in enclosing XML |
|
| 52 | + * @access public |
|
| 53 | + */ |
|
| 54 | 54 | public function nusoap_xmlschema($schema='',$xml='',$namespaces=array()){ |
| 55 | 55 | parent::nusoap_base(); |
| 56 | 56 | $this->debug('nusoap_xmlschema class instantiated, inside constructor'); |
@@ -76,14 +76,14 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * parse an XML file |
|
| 81 | - * |
|
| 82 | - * @param string $xml path/URL to XML file |
|
| 83 | - * @param string $type (schema | xml) |
|
| 84 | - * @return boolean |
|
| 85 | - * @access public |
|
| 86 | - */ |
|
| 79 | + /** |
|
| 80 | + * parse an XML file |
|
| 81 | + * |
|
| 82 | + * @param string $xml path/URL to XML file |
|
| 83 | + * @param string $type (schema | xml) |
|
| 84 | + * @return boolean |
|
| 85 | + * @access public |
|
| 86 | + */ |
|
| 87 | 87 | public function parseFile($xml,$type){ |
| 88 | 88 | // parse xml file |
| 89 | 89 | if($xml != ""){ |
@@ -104,35 +104,35 @@ discard block |
||
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
| 107 | - * parse an XML string |
|
| 108 | - * |
|
| 109 | - * @param string $xml path or URL |
|
| 110 | - * @param string $type (schema|xml) |
|
| 111 | - * @access private |
|
| 112 | - */ |
|
| 107 | + * parse an XML string |
|
| 108 | + * |
|
| 109 | + * @param string $xml path or URL |
|
| 110 | + * @param string $type (schema|xml) |
|
| 111 | + * @access private |
|
| 112 | + */ |
|
| 113 | 113 | public function parseString($xml,$type){ |
| 114 | 114 | // parse xml string |
| 115 | 115 | if($xml != ""){ |
| 116 | 116 | |
| 117 | - // Create an XML parser. |
|
| 118 | - $this->parser = xml_parser_create(); |
|
| 119 | - // Set the options for parsing the XML data. |
|
| 120 | - xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|
| 117 | + // Create an XML parser. |
|
| 118 | + $this->parser = xml_parser_create(); |
|
| 119 | + // Set the options for parsing the XML data. |
|
| 120 | + xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0); |
|
| 121 | 121 | |
| 122 | - // Set the object for the parser. |
|
| 123 | - xml_set_object($this->parser, $this); |
|
| 122 | + // Set the object for the parser. |
|
| 123 | + xml_set_object($this->parser, $this); |
|
| 124 | 124 | |
| 125 | - // Set the element handlers for the parser. |
|
| 125 | + // Set the element handlers for the parser. |
|
| 126 | 126 | if($type == "schema"){ |
| 127 | - xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); |
|
| 128 | - xml_set_character_data_handler($this->parser,'schemaCharacterData'); |
|
| 127 | + xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); |
|
| 128 | + xml_set_character_data_handler($this->parser,'schemaCharacterData'); |
|
| 129 | 129 | } elseif($type == "xml"){ |
| 130 | 130 | xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement'); |
| 131 | - xml_set_character_data_handler($this->parser,'xmlCharacterData'); |
|
| 131 | + xml_set_character_data_handler($this->parser,'xmlCharacterData'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - // Parse the XML file. |
|
| 135 | - if(!xml_parse($this->parser,$xml,true)){ |
|
| 134 | + // Parse the XML file. |
|
| 135 | + if(!xml_parse($this->parser,$xml,true)){ |
|
| 136 | 136 | // Display an error message. |
| 137 | 137 | $errstr = sprintf('XML error parsing XML schema on line %d: %s', |
| 138 | 138 | xml_get_current_line_number($this->parser), |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $this->debug($errstr); |
| 142 | 142 | $this->debug("XML payload:\n" . $xml); |
| 143 | 143 | $this->setError($errstr); |
| 144 | - } |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | xml_parser_free($this->parser); |
| 147 | 147 | } else{ |
@@ -166,13 +166,13 @@ discard block |
||
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
| 169 | - * start-element handler |
|
| 170 | - * |
|
| 171 | - * @param string $parser XML parser object |
|
| 172 | - * @param string $name element name |
|
| 173 | - * @param string $attrs associative array of attributes |
|
| 174 | - * @access private |
|
| 175 | - */ |
|
| 169 | + * start-element handler |
|
| 170 | + * |
|
| 171 | + * @param string $parser XML parser object |
|
| 172 | + * @param string $name element name |
|
| 173 | + * @param string $attrs associative array of attributes |
|
| 174 | + * @access private |
|
| 175 | + */ |
|
| 176 | 176 | public function schemaStartElement($parser, $name, $attrs) { |
| 177 | 177 | |
| 178 | 178 | // position in the total number of elements, starting from 0 |
@@ -192,15 +192,15 @@ discard block |
||
| 192 | 192 | // get unqualified name |
| 193 | 193 | $name = $this->getLocalPart($name); |
| 194 | 194 | } else { |
| 195 | - $prefix = ''; |
|
| 196 | - } |
|
| 195 | + $prefix = ''; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - // loop thru attributes, expanding, and registering namespace declarations |
|
| 199 | - if(count($attrs) > 0){ |
|
| 200 | - foreach($attrs as $k => $v){ |
|
| 201 | - // if ns declarations, add to class level array of valid namespaces |
|
| 198 | + // loop thru attributes, expanding, and registering namespace declarations |
|
| 199 | + if(count($attrs) > 0){ |
|
| 200 | + foreach($attrs as $k => $v){ |
|
| 201 | + // if ns declarations, add to class level array of valid namespaces |
|
| 202 | 202 | if(preg_match('/^xmlns/',$k)){ |
| 203 | - if($ns_prefix = substr(strrchr($k,':'),1)){ |
|
| 203 | + if($ns_prefix = substr(strrchr($k,':'),1)){ |
|
| 204 | 204 | $this->namespaces[$ns_prefix] = $v; |
| 205 | 205 | } else { |
| 206 | 206 | $this->defaultNamespace[$pos] = $v; |
@@ -213,17 +213,17 @@ discard block |
||
| 213 | 213 | $this->namespaces['xsi'] = $v.'-instance'; |
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | - } |
|
| 217 | - foreach($attrs as $k => $v){ |
|
| 218 | - // expand each attribute |
|
| 219 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 220 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 221 | - $eAttrs[$k] = $v; |
|
| 222 | - } |
|
| 223 | - $attrs = $eAttrs; |
|
| 224 | - } else { |
|
| 225 | - $attrs = array(); |
|
| 226 | - } |
|
| 216 | + } |
|
| 217 | + foreach($attrs as $k => $v){ |
|
| 218 | + // expand each attribute |
|
| 219 | + $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 220 | + $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 221 | + $eAttrs[$k] = $v; |
|
| 222 | + } |
|
| 223 | + $attrs = $eAttrs; |
|
| 224 | + } else { |
|
| 225 | + $attrs = array(); |
|
| 226 | + } |
|
| 227 | 227 | // find status, register data |
| 228 | 228 | switch($name){ |
| 229 | 229 | case 'all': // (optional) compositor content for a complexType |
@@ -234,13 +234,13 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | break; |
| 236 | 236 | case 'attribute': // complexType attribute |
| 237 | - $this->xdebug("parsing attribute:"); |
|
| 238 | - $this->appendDebug($this->varDump($attrs)); |
|
| 237 | + $this->xdebug("parsing attribute:"); |
|
| 238 | + $this->appendDebug($this->varDump($attrs)); |
|
| 239 | 239 | if (!isset($attrs['form'])) { |
| 240 | 240 | // TODO: handle globals |
| 241 | 241 | $attrs['form'] = $this->schemaInfo['attributeFormDefault']; |
| 242 | 242 | } |
| 243 | - if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
| 243 | + if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
| 244 | 244 | $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
| 245 | 245 | if (!strpos($v, ':')) { |
| 246 | 246 | // no namespace in arrayType attribute value... |
@@ -249,19 +249,19 @@ discard block |
||
| 249 | 249 | $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'] = $this->defaultNamespace[$pos] . ':' . $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | - } |
|
| 253 | - if(isset($attrs['name'])){ |
|
| 252 | + } |
|
| 253 | + if(isset($attrs['name'])){ |
|
| 254 | 254 | $this->attributes[$attrs['name']] = $attrs; |
| 255 | 255 | $aname = $attrs['name']; |
| 256 | 256 | } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){ |
| 257 | 257 | if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
| 258 | - $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
| 259 | - } else { |
|
| 260 | - $aname = ''; |
|
| 261 | - } |
|
| 258 | + $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
|
| 259 | + } else { |
|
| 260 | + $aname = ''; |
|
| 261 | + } |
|
| 262 | 262 | } elseif(isset($attrs['ref'])){ |
| 263 | 263 | $aname = $attrs['ref']; |
| 264 | - $this->attributes[$attrs['ref']] = $attrs; |
|
| 264 | + $this->attributes[$attrs['ref']] = $attrs; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | if($this->currentComplexType){ // This should *always* be |
@@ -270,20 +270,20 @@ discard block |
||
| 270 | 270 | // arrayType attribute |
| 271 | 271 | if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){ |
| 272 | 272 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
| 273 | - $prefix = $this->getPrefix($aname); |
|
| 273 | + $prefix = $this->getPrefix($aname); |
|
| 274 | 274 | if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){ |
| 275 | 275 | $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
| 276 | 276 | } else { |
| 277 | 277 | $v = ''; |
| 278 | 278 | } |
| 279 | - if(strpos($v,'[,]')){ |
|
| 280 | - $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; |
|
| 281 | - } |
|
| 282 | - $v = substr($v,0,strpos($v,'[')); // clip the [] |
|
| 283 | - if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){ |
|
| 284 | - $v = $this->XMLSchemaVersion.':'.$v; |
|
| 285 | - } |
|
| 286 | - $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; |
|
| 279 | + if(strpos($v,'[,]')){ |
|
| 280 | + $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; |
|
| 281 | + } |
|
| 282 | + $v = substr($v,0,strpos($v,'[')); // clip the [] |
|
| 283 | + if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){ |
|
| 284 | + $v = $this->XMLSchemaVersion.':'.$v; |
|
| 285 | + } |
|
| 286 | + $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; |
|
| 287 | 287 | } |
| 288 | 288 | break; |
| 289 | 289 | case 'complexContent': // (optional) content for a complexType |
@@ -406,21 +406,21 @@ discard block |
||
| 406 | 406 | } |
| 407 | 407 | break; |
| 408 | 408 | case 'import': |
| 409 | - if (isset($attrs['schemaLocation'])) { |
|
| 409 | + if (isset($attrs['schemaLocation'])) { |
|
| 410 | 410 | $this->xdebug('import namespace ' . $attrs['namespace'] . ' from ' . $attrs['schemaLocation']); |
| 411 | - $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); |
|
| 411 | + $this->imports[$attrs['namespace']][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); |
|
| 412 | 412 | } else { |
| 413 | 413 | $this->xdebug('import namespace ' . $attrs['namespace']); |
| 414 | - $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
|
| 414 | + $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
|
| 415 | 415 | if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
| 416 | 416 | $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | break; |
| 420 | 420 | case 'include': |
| 421 | - if (isset($attrs['schemaLocation'])) { |
|
| 421 | + if (isset($attrs['schemaLocation'])) { |
|
| 422 | 422 | $this->xdebug('include into namespace ' . $this->schemaTargetNamespace . ' from ' . $attrs['schemaLocation']); |
| 423 | - $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); |
|
| 423 | + $this->imports[$this->schemaTargetNamespace][] = array('location' => $attrs['schemaLocation'], 'loaded' => false); |
|
| 424 | 424 | } else { |
| 425 | 425 | $this->xdebug('ignoring invalid XML Schema construct: include without schemaLocation attribute'); |
| 426 | 426 | } |
@@ -484,26 +484,26 @@ discard block |
||
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | /** |
| 487 | - * end-element handler |
|
| 488 | - * |
|
| 489 | - * @param string $parser XML parser object |
|
| 490 | - * @param string $name element name |
|
| 491 | - * @access private |
|
| 492 | - */ |
|
| 487 | + * end-element handler |
|
| 488 | + * |
|
| 489 | + * @param string $parser XML parser object |
|
| 490 | + * @param string $name element name |
|
| 491 | + * @access private |
|
| 492 | + */ |
|
| 493 | 493 | public function schemaEndElement($parser, $name) { |
| 494 | 494 | // bring depth down a notch |
| 495 | 495 | $this->depth--; |
| 496 | 496 | // position of current element is equal to the last value left in depth_array for my depth |
| 497 | 497 | if(isset($this->depth_array[$this->depth])){ |
| 498 | - $pos = $this->depth_array[$this->depth]; |
|
| 499 | - } |
|
| 498 | + $pos = $this->depth_array[$this->depth]; |
|
| 499 | + } |
|
| 500 | 500 | // get element prefix |
| 501 | 501 | if ($prefix = $this->getPrefix($name)){ |
| 502 | 502 | // get unqualified name |
| 503 | 503 | $name = $this->getLocalPart($name); |
| 504 | 504 | } else { |
| 505 | - $prefix = ''; |
|
| 506 | - } |
|
| 505 | + $prefix = ''; |
|
| 506 | + } |
|
| 507 | 507 | // move on... |
| 508 | 508 | if($name == 'complexType'){ |
| 509 | 509 | $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); |
@@ -522,22 +522,22 @@ discard block |
||
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | /** |
| 525 | - * element content handler |
|
| 526 | - * |
|
| 527 | - * @param string $parser XML parser object |
|
| 528 | - * @param string $data element content |
|
| 529 | - * @access private |
|
| 530 | - */ |
|
| 525 | + * element content handler |
|
| 526 | + * |
|
| 527 | + * @param string $parser XML parser object |
|
| 528 | + * @param string $data element content |
|
| 529 | + * @access private |
|
| 530 | + */ |
|
| 531 | 531 | public function schemaCharacterData($parser, $data){ |
| 532 | 532 | $pos = $this->depth_array[$this->depth - 1]; |
| 533 | 533 | $this->message[$pos]['cdata'] .= $data; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
| 537 | - * serialize the schema |
|
| 538 | - * |
|
| 539 | - * @access public |
|
| 540 | - */ |
|
| 537 | + * serialize the schema |
|
| 538 | + * |
|
| 539 | + * @access public |
|
| 540 | + */ |
|
| 541 | 541 | public function serializeSchema(){ |
| 542 | 542 | |
| 543 | 543 | $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); |
@@ -651,27 +651,27 @@ discard block |
||
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | /** |
| 654 | - * adds debug data to the clas level debug string |
|
| 655 | - * |
|
| 656 | - * @param string $string debug data |
|
| 657 | - * @access private |
|
| 658 | - */ |
|
| 654 | + * adds debug data to the clas level debug string |
|
| 655 | + * |
|
| 656 | + * @param string $string debug data |
|
| 657 | + * @access private |
|
| 658 | + */ |
|
| 659 | 659 | public function xdebug($string){ |
| 660 | 660 | $this->debug('<' . $this->schemaTargetNamespace . '> '.$string); |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | - /** |
|
| 664 | - * get the PHP type of a user defined type in the schema |
|
| 665 | - * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays |
|
| 666 | - * returns false if no type exists, or not w/ the given namespace |
|
| 667 | - * else returns a string that is either a native php type, or 'struct' |
|
| 668 | - * |
|
| 669 | - * @param string $type name of defined type |
|
| 670 | - * @param string $ns namespace of type |
|
| 671 | - * @return mixed |
|
| 672 | - * @access public |
|
| 673 | - * @deprecated |
|
| 674 | - */ |
|
| 663 | + /** |
|
| 664 | + * get the PHP type of a user defined type in the schema |
|
| 665 | + * PHP type is kind of a misnomer since it actually returns 'struct' for assoc. arrays |
|
| 666 | + * returns false if no type exists, or not w/ the given namespace |
|
| 667 | + * else returns a string that is either a native php type, or 'struct' |
|
| 668 | + * |
|
| 669 | + * @param string $type name of defined type |
|
| 670 | + * @param string $ns namespace of type |
|
| 671 | + * @return mixed |
|
| 672 | + * @access public |
|
| 673 | + * @deprecated |
|
| 674 | + */ |
|
| 675 | 675 | public function getPHPType($type,$ns){ |
| 676 | 676 | if(isset($this->typemap[$ns][$type])){ |
| 677 | 677 | //print "found type '$type' and ns $ns in typemap<br>"; |
@@ -684,27 +684,27 @@ discard block |
||
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | /** |
| 687 | - * returns an associative array of information about a given type |
|
| 688 | - * returns false if no type exists by the given name |
|
| 689 | - * |
|
| 690 | - * For a complexType typeDef = array( |
|
| 691 | - * 'restrictionBase' => '', |
|
| 692 | - * 'phpType' => '', |
|
| 693 | - * 'compositor' => '(sequence|all)', |
|
| 694 | - * 'elements' => array(), // refs to elements array |
|
| 695 | - * 'attrs' => array() // refs to attributes array |
|
| 696 | - * ... and so on (see addComplexType) |
|
| 697 | - * ) |
|
| 698 | - * |
|
| 699 | - * For simpleType or element, the array has different keys. |
|
| 700 | - * |
|
| 701 | - * @param string $type |
|
| 702 | - * @return mixed |
|
| 703 | - * @access public |
|
| 704 | - * @see addComplexType |
|
| 705 | - * @see addSimpleType |
|
| 706 | - * @see addElement |
|
| 707 | - */ |
|
| 687 | + * returns an associative array of information about a given type |
|
| 688 | + * returns false if no type exists by the given name |
|
| 689 | + * |
|
| 690 | + * For a complexType typeDef = array( |
|
| 691 | + * 'restrictionBase' => '', |
|
| 692 | + * 'phpType' => '', |
|
| 693 | + * 'compositor' => '(sequence|all)', |
|
| 694 | + * 'elements' => array(), // refs to elements array |
|
| 695 | + * 'attrs' => array() // refs to attributes array |
|
| 696 | + * ... and so on (see addComplexType) |
|
| 697 | + * ) |
|
| 698 | + * |
|
| 699 | + * For simpleType or element, the array has different keys. |
|
| 700 | + * |
|
| 701 | + * @param string $type |
|
| 702 | + * @return mixed |
|
| 703 | + * @access public |
|
| 704 | + * @see addComplexType |
|
| 705 | + * @see addSimpleType |
|
| 706 | + * @see addElement |
|
| 707 | + */ |
|
| 708 | 708 | public function getTypeDef($type){ |
| 709 | 709 | if (substr($type, -1) == '^') { |
| 710 | 710 | $is_element = 1; |
@@ -776,49 +776,49 @@ discard block |
||
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | /** |
| 779 | - * returns a sample serialization of a given type, or false if no type by the given name |
|
| 780 | - * |
|
| 781 | - * @param string $type name of type |
|
| 782 | - * @return mixed |
|
| 783 | - * @access public |
|
| 784 | - * @deprecated |
|
| 785 | - */ |
|
| 786 | - function serializeTypeDef($type){ |
|
| 787 | - //print "in sTD() for type $type<br>"; |
|
| 779 | + * returns a sample serialization of a given type, or false if no type by the given name |
|
| 780 | + * |
|
| 781 | + * @param string $type name of type |
|
| 782 | + * @return mixed |
|
| 783 | + * @access public |
|
| 784 | + * @deprecated |
|
| 785 | + */ |
|
| 786 | + function serializeTypeDef($type){ |
|
| 787 | + //print "in sTD() for type $type<br>"; |
|
| 788 | 788 | if($typeDef = $this->getTypeDef($type)){ |
| 789 | 789 | $str .= '<'.$type; |
| 790 | - if(is_array($typeDef['attrs'])){ |
|
| 790 | + if(is_array($typeDef['attrs'])){ |
|
| 791 | 791 | foreach($typeDef['attrs'] as $attName => $data){ |
| 792 | - $str .= " $attName=\"{type = ".$data['type']."}\""; |
|
| 792 | + $str .= " $attName=\"{type = ".$data['type']."}\""; |
|
| 793 | 793 | } |
| 794 | - } |
|
| 795 | - $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; |
|
| 796 | - if(count($typeDef['elements']) > 0){ |
|
| 794 | + } |
|
| 795 | + $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; |
|
| 796 | + if(count($typeDef['elements']) > 0){ |
|
| 797 | 797 | $str .= ">"; |
| 798 | 798 | foreach($typeDef['elements'] as $element => $eData){ |
| 799 | - $str .= $this->serializeTypeDef($element); |
|
| 799 | + $str .= $this->serializeTypeDef($element); |
|
| 800 | 800 | } |
| 801 | 801 | $str .= "</$type>"; |
| 802 | - } elseif($typeDef['typeClass'] == 'element') { |
|
| 802 | + } elseif($typeDef['typeClass'] == 'element') { |
|
| 803 | 803 | $str .= "></$type>"; |
| 804 | - } else { |
|
| 804 | + } else { |
|
| 805 | 805 | $str .= "/>"; |
| 806 | - } |
|
| 806 | + } |
|
| 807 | 807 | return $str; |
| 808 | 808 | } |
| 809 | - return false; |
|
| 810 | - } |
|
| 809 | + return false; |
|
| 810 | + } |
|
| 811 | 811 | |
| 812 | - /** |
|
| 813 | - * returns HTML form elements that allow a user |
|
| 814 | - * to enter values for creating an instance of the given type. |
|
| 815 | - * |
|
| 816 | - * @param string $name name for type instance |
|
| 817 | - * @param string $type name of type |
|
| 818 | - * @return string |
|
| 819 | - * @access public |
|
| 820 | - * @deprecated |
|
| 821 | - */ |
|
| 812 | + /** |
|
| 813 | + * returns HTML form elements that allow a user |
|
| 814 | + * to enter values for creating an instance of the given type. |
|
| 815 | + * |
|
| 816 | + * @param string $name name for type instance |
|
| 817 | + * @param string $type name of type |
|
| 818 | + * @return string |
|
| 819 | + * @access public |
|
| 820 | + * @deprecated |
|
| 821 | + */ |
|
| 822 | 822 | public function typeToForm($name,$type){ |
| 823 | 823 | // get typedef |
| 824 | 824 | if($typeDef = $this->getTypeDef($type)){ |
@@ -851,56 +851,56 @@ discard block |
||
| 851 | 851 | } |
| 852 | 852 | |
| 853 | 853 | /** |
| 854 | - * adds a complex type to the schema |
|
| 855 | - * |
|
| 856 | - * example: array |
|
| 857 | - * |
|
| 858 | - * addType( |
|
| 859 | - * 'ArrayOfstring', |
|
| 860 | - * 'complexType', |
|
| 861 | - * 'array', |
|
| 862 | - * '', |
|
| 863 | - * 'SOAP-ENC:Array', |
|
| 864 | - * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'), |
|
| 865 | - * 'xsd:string' |
|
| 866 | - * ); |
|
| 867 | - * |
|
| 868 | - * example: PHP associative array ( SOAP Struct ) |
|
| 869 | - * |
|
| 870 | - * addType( |
|
| 871 | - * 'SOAPStruct', |
|
| 872 | - * 'complexType', |
|
| 873 | - * 'struct', |
|
| 874 | - * 'all', |
|
| 875 | - * array('myVar'=> array('name'=>'myVar','type'=>'string') |
|
| 876 | - * ); |
|
| 877 | - * |
|
| 878 | - * @param name |
|
| 879 | - * @param typeClass (complexType|simpleType|attribute) |
|
| 880 | - * @param phpType: currently supported are array and struct (php assoc array) |
|
| 881 | - * @param compositor (all|sequence|choice) |
|
| 882 | - * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 883 | - * @param elements = array ( name = array(name=>'',type=>'') ) |
|
| 884 | - * @param attrs = array( |
|
| 885 | - * array( |
|
| 886 | - * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType", |
|
| 887 | - * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" |
|
| 888 | - * ) |
|
| 889 | - * ) |
|
| 890 | - * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) |
|
| 891 | - * @access public |
|
| 892 | - * @see getTypeDef |
|
| 893 | - */ |
|
| 854 | + * adds a complex type to the schema |
|
| 855 | + * |
|
| 856 | + * example: array |
|
| 857 | + * |
|
| 858 | + * addType( |
|
| 859 | + * 'ArrayOfstring', |
|
| 860 | + * 'complexType', |
|
| 861 | + * 'array', |
|
| 862 | + * '', |
|
| 863 | + * 'SOAP-ENC:Array', |
|
| 864 | + * array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'string[]'), |
|
| 865 | + * 'xsd:string' |
|
| 866 | + * ); |
|
| 867 | + * |
|
| 868 | + * example: PHP associative array ( SOAP Struct ) |
|
| 869 | + * |
|
| 870 | + * addType( |
|
| 871 | + * 'SOAPStruct', |
|
| 872 | + * 'complexType', |
|
| 873 | + * 'struct', |
|
| 874 | + * 'all', |
|
| 875 | + * array('myVar'=> array('name'=>'myVar','type'=>'string') |
|
| 876 | + * ); |
|
| 877 | + * |
|
| 878 | + * @param name |
|
| 879 | + * @param typeClass (complexType|simpleType|attribute) |
|
| 880 | + * @param phpType: currently supported are array and struct (php assoc array) |
|
| 881 | + * @param compositor (all|sequence|choice) |
|
| 882 | + * @param restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 883 | + * @param elements = array ( name = array(name=>'',type=>'') ) |
|
| 884 | + * @param attrs = array( |
|
| 885 | + * array( |
|
| 886 | + * 'ref' => "http://schemas.xmlsoap.org/soap/encoding/:arrayType", |
|
| 887 | + * "http://schemas.xmlsoap.org/wsdl/:arrayType" => "string[]" |
|
| 888 | + * ) |
|
| 889 | + * ) |
|
| 890 | + * @param arrayType: namespace:name (http://www.w3.org/2001/XMLSchema:string) |
|
| 891 | + * @access public |
|
| 892 | + * @see getTypeDef |
|
| 893 | + */ |
|
| 894 | 894 | public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){ |
| 895 | 895 | $this->complexTypes[$name] = array( |
| 896 | - 'name' => $name, |
|
| 897 | - 'typeClass' => $typeClass, |
|
| 898 | - 'phpType' => $phpType, |
|
| 896 | + 'name' => $name, |
|
| 897 | + 'typeClass' => $typeClass, |
|
| 898 | + 'phpType' => $phpType, |
|
| 899 | 899 | 'compositor'=> $compositor, |
| 900 | - 'restrictionBase' => $restrictionBase, |
|
| 900 | + 'restrictionBase' => $restrictionBase, |
|
| 901 | 901 | 'elements' => $elements, |
| 902 | - 'attrs' => $attrs, |
|
| 903 | - 'arrayType' => $arrayType |
|
| 902 | + 'attrs' => $attrs, |
|
| 903 | + 'arrayType' => $arrayType |
|
| 904 | 904 | ); |
| 905 | 905 | |
| 906 | 906 | $this->xdebug("addComplexType $name:"); |
@@ -908,24 +908,24 @@ discard block |
||
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
| 911 | - * adds a simple type to the schema |
|
| 912 | - * |
|
| 913 | - * @param string $name |
|
| 914 | - * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 915 | - * @param string $typeClass (should always be simpleType) |
|
| 916 | - * @param string $phpType (should always be scalar) |
|
| 917 | - * @param array $enumeration array of values |
|
| 918 | - * @access public |
|
| 919 | - * @see nusoap_xmlschema |
|
| 920 | - * @see getTypeDef |
|
| 921 | - */ |
|
| 911 | + * adds a simple type to the schema |
|
| 912 | + * |
|
| 913 | + * @param string $name |
|
| 914 | + * @param string $restrictionBase namespace:name (http://schemas.xmlsoap.org/soap/encoding/:Array) |
|
| 915 | + * @param string $typeClass (should always be simpleType) |
|
| 916 | + * @param string $phpType (should always be scalar) |
|
| 917 | + * @param array $enumeration array of values |
|
| 918 | + * @access public |
|
| 919 | + * @see nusoap_xmlschema |
|
| 920 | + * @see getTypeDef |
|
| 921 | + */ |
|
| 922 | 922 | public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
| 923 | 923 | $this->simpleTypes[$name] = array( |
| 924 | - 'name' => $name, |
|
| 925 | - 'typeClass' => $typeClass, |
|
| 926 | - 'phpType' => $phpType, |
|
| 927 | - 'type' => $restrictionBase, |
|
| 928 | - 'enumeration' => $enumeration |
|
| 924 | + 'name' => $name, |
|
| 925 | + 'typeClass' => $typeClass, |
|
| 926 | + 'phpType' => $phpType, |
|
| 927 | + 'type' => $restrictionBase, |
|
| 928 | + 'enumeration' => $enumeration |
|
| 929 | 929 | ); |
| 930 | 930 | |
| 931 | 931 | $this->xdebug("addSimpleType $name:"); |
@@ -933,12 +933,12 @@ discard block |
||
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
| 936 | - * adds an element to the schema |
|
| 937 | - * |
|
| 938 | - * @param array $attrs attributes that must include name and type |
|
| 939 | - * @see nusoap_xmlschema |
|
| 940 | - * @access public |
|
| 941 | - */ |
|
| 936 | + * adds an element to the schema |
|
| 937 | + * |
|
| 938 | + * @param array $attrs attributes that must include name and type |
|
| 939 | + * @see nusoap_xmlschema |
|
| 940 | + * @access public |
|
| 941 | + */ |
|
| 942 | 942 | public function addElement($attrs) { |
| 943 | 943 | if (! $this->getPrefix($attrs['type'])) { |
| 944 | 944 | $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type']; |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | * @version $Id: class.xmlschema.php,v 1.53 2010/04/26 20:15:08 snichol Exp $ |
| 13 | 13 | * @access public |
| 14 | 14 | */ |
| 15 | -class nusoap_xmlschema extends nusoap_base { |
|
| 15 | +class nusoap_xmlschema extends nusoap_base { |
|
| 16 | 16 | |
| 17 | 17 | // files |
| 18 | 18 | var $schema = ''; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * @param string $namespaces namespaces defined in enclosing XML |
| 52 | 52 | * @access public |
| 53 | 53 | */ |
| 54 | - public function nusoap_xmlschema($schema='',$xml='',$namespaces=array()){ |
|
| 54 | + public function nusoap_xmlschema($schema = '', $xml = '', $namespaces = array()) { |
|
| 55 | 55 | parent::nusoap_base(); |
| 56 | 56 | $this->debug('nusoap_xmlschema class instantiated, inside constructor'); |
| 57 | 57 | // files |
@@ -63,14 +63,14 @@ discard block |
||
| 63 | 63 | $this->namespaces = array_merge($this->namespaces, $namespaces); |
| 64 | 64 | |
| 65 | 65 | // parse schema file |
| 66 | - if($schema != ''){ |
|
| 67 | - $this->debug('initial schema file: '.$schema); |
|
| 66 | + if ($schema != '') { |
|
| 67 | + $this->debug('initial schema file: ' . $schema); |
|
| 68 | 68 | $this->parseFile($schema, 'schema'); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // parse xml file |
| 72 | - if($xml != ''){ |
|
| 73 | - $this->debug('initial xml file: '.$xml); |
|
| 72 | + if ($xml != '') { |
|
| 73 | + $this->debug('initial xml file: ' . $xml); |
|
| 74 | 74 | $this->parseFile($xml, 'xml'); |
| 75 | 75 | } |
| 76 | 76 | |
@@ -84,18 +84,18 @@ discard block |
||
| 84 | 84 | * @return boolean |
| 85 | 85 | * @access public |
| 86 | 86 | */ |
| 87 | - public function parseFile($xml,$type){ |
|
| 87 | + public function parseFile($xml, $type) { |
|
| 88 | 88 | // parse xml file |
| 89 | - if($xml != ""){ |
|
| 90 | - $xmlStr = @join("",@file($xml)); |
|
| 91 | - if($xmlStr == ""){ |
|
| 92 | - $msg = 'Error reading XML from '.$xml; |
|
| 89 | + if ($xml != "") { |
|
| 90 | + $xmlStr = @join("", @file($xml)); |
|
| 91 | + if ($xmlStr == "") { |
|
| 92 | + $msg = 'Error reading XML from ' . $xml; |
|
| 93 | 93 | $this->setError($msg); |
| 94 | 94 | $this->debug($msg); |
| 95 | 95 | return false; |
| 96 | 96 | } else { |
| 97 | 97 | $this->debug("parsing $xml"); |
| 98 | - $this->parseString($xmlStr,$type); |
|
| 98 | + $this->parseString($xmlStr, $type); |
|
| 99 | 99 | $this->debug("done parsing $xml"); |
| 100 | 100 | return true; |
| 101 | 101 | } |
@@ -110,9 +110,9 @@ discard block |
||
| 110 | 110 | * @param string $type (schema|xml) |
| 111 | 111 | * @access private |
| 112 | 112 | */ |
| 113 | - public function parseString($xml,$type){ |
|
| 113 | + public function parseString($xml, $type) { |
|
| 114 | 114 | // parse xml string |
| 115 | - if($xml != ""){ |
|
| 115 | + if ($xml != "") { |
|
| 116 | 116 | |
| 117 | 117 | // Create an XML parser. |
| 118 | 118 | $this->parser = xml_parser_create(); |
@@ -123,16 +123,16 @@ discard block |
||
| 123 | 123 | xml_set_object($this->parser, $this); |
| 124 | 124 | |
| 125 | 125 | // Set the element handlers for the parser. |
| 126 | - if($type == "schema"){ |
|
| 127 | - xml_set_element_handler($this->parser, 'schemaStartElement','schemaEndElement'); |
|
| 128 | - xml_set_character_data_handler($this->parser,'schemaCharacterData'); |
|
| 129 | - } elseif($type == "xml"){ |
|
| 130 | - xml_set_element_handler($this->parser, 'xmlStartElement','xmlEndElement'); |
|
| 131 | - xml_set_character_data_handler($this->parser,'xmlCharacterData'); |
|
| 126 | + if ($type == "schema") { |
|
| 127 | + xml_set_element_handler($this->parser, 'schemaStartElement', 'schemaEndElement'); |
|
| 128 | + xml_set_character_data_handler($this->parser, 'schemaCharacterData'); |
|
| 129 | + } elseif ($type == "xml") { |
|
| 130 | + xml_set_element_handler($this->parser, 'xmlStartElement', 'xmlEndElement'); |
|
| 131 | + xml_set_character_data_handler($this->parser, 'xmlCharacterData'); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | // Parse the XML file. |
| 135 | - if(!xml_parse($this->parser,$xml,true)){ |
|
| 135 | + if (!xml_parse($this->parser, $xml, true)) { |
|
| 136 | 136 | // Display an error message. |
| 137 | 137 | $errstr = sprintf('XML error parsing XML schema on line %d: %s', |
| 138 | 138 | xml_get_current_line_number($this->parser), |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | xml_parser_free($this->parser); |
| 147 | - } else{ |
|
| 147 | + } else { |
|
| 148 | 148 | $this->debug('no xml passed to parseString()!!'); |
| 149 | 149 | $this->setError('no xml passed to parseString()!!'); |
| 150 | 150 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | // get element prefix |
| 191 | - if($prefix = $this->getPrefix($name)){ |
|
| 191 | + if ($prefix = $this->getPrefix($name)) { |
|
| 192 | 192 | // get unqualified name |
| 193 | 193 | $name = $this->getLocalPart($name); |
| 194 | 194 | } else { |
@@ -196,28 +196,28 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | // loop thru attributes, expanding, and registering namespace declarations |
| 199 | - if(count($attrs) > 0){ |
|
| 200 | - foreach($attrs as $k => $v){ |
|
| 199 | + if (count($attrs) > 0) { |
|
| 200 | + foreach ($attrs as $k => $v) { |
|
| 201 | 201 | // if ns declarations, add to class level array of valid namespaces |
| 202 | - if(preg_match('/^xmlns/',$k)){ |
|
| 203 | - if($ns_prefix = substr(strrchr($k,':'),1)){ |
|
| 202 | + if (preg_match('/^xmlns/', $k)) { |
|
| 203 | + if ($ns_prefix = substr(strrchr($k, ':'), 1)) { |
|
| 204 | 204 | $this->namespaces[$ns_prefix] = $v; |
| 205 | 205 | } else { |
| 206 | 206 | $this->defaultNamespace[$pos] = $v; |
| 207 | - if (! $this->getPrefixFromNamespace($v)) { |
|
| 208 | - $this->namespaces['ns'.(count($this->namespaces)+1)] = $v; |
|
| 207 | + if (!$this->getPrefixFromNamespace($v)) { |
|
| 208 | + $this->namespaces['ns' . (count($this->namespaces) + 1)] = $v; |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | - if($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema'){ |
|
| 211 | + if ($v == 'http://www.w3.org/2001/XMLSchema' || $v == 'http://www.w3.org/1999/XMLSchema' || $v == 'http://www.w3.org/2000/10/XMLSchema') { |
|
| 212 | 212 | $this->XMLSchemaVersion = $v; |
| 213 | - $this->namespaces['xsi'] = $v.'-instance'; |
|
| 213 | + $this->namespaces['xsi'] = $v . '-instance'; |
|
| 214 | 214 | } |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | - foreach($attrs as $k => $v){ |
|
| 217 | + foreach ($attrs as $k => $v) { |
|
| 218 | 218 | // expand each attribute |
| 219 | - $k = strpos($k,':') ? $this->expandQname($k) : $k; |
|
| 220 | - $v = strpos($v,':') ? $this->expandQname($v) : $v; |
|
| 219 | + $k = strpos($k, ':') ? $this->expandQname($k) : $k; |
|
| 220 | + $v = strpos($v, ':') ? $this->expandQname($v) : $v; |
|
| 221 | 221 | $eAttrs[$k] = $v; |
| 222 | 222 | } |
| 223 | 223 | $attrs = $eAttrs; |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | $attrs = array(); |
| 226 | 226 | } |
| 227 | 227 | // find status, register data |
| 228 | - switch($name){ |
|
| 228 | + switch ($name) { |
|
| 229 | 229 | case 'all': // (optional) compositor content for a complexType |
| 230 | 230 | case 'choice': |
| 231 | 231 | case 'group': |
@@ -250,38 +250,38 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | } |
| 253 | - if(isset($attrs['name'])){ |
|
| 253 | + if (isset($attrs['name'])) { |
|
| 254 | 254 | $this->attributes[$attrs['name']] = $attrs; |
| 255 | 255 | $aname = $attrs['name']; |
| 256 | - } elseif(isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType'){ |
|
| 256 | + } elseif (isset($attrs['ref']) && $attrs['ref'] == 'http://schemas.xmlsoap.org/soap/encoding/:arrayType') { |
|
| 257 | 257 | if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
| 258 | 258 | $aname = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
| 259 | 259 | } else { |
| 260 | 260 | $aname = ''; |
| 261 | 261 | } |
| 262 | - } elseif(isset($attrs['ref'])){ |
|
| 262 | + } elseif (isset($attrs['ref'])) { |
|
| 263 | 263 | $aname = $attrs['ref']; |
| 264 | 264 | $this->attributes[$attrs['ref']] = $attrs; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if($this->currentComplexType){ // This should *always* be |
|
| 267 | + if ($this->currentComplexType) { // This should *always* be |
|
| 268 | 268 | $this->complexTypes[$this->currentComplexType]['attrs'][$aname] = $attrs; |
| 269 | 269 | } |
| 270 | 270 | // arrayType attribute |
| 271 | - if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType'){ |
|
| 271 | + if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']) || $this->getLocalPart($aname) == 'arrayType') { |
|
| 272 | 272 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
| 273 | 273 | $prefix = $this->getPrefix($aname); |
| 274 | - if(isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])){ |
|
| 274 | + if (isset($attrs['http://schemas.xmlsoap.org/wsdl/:arrayType'])) { |
|
| 275 | 275 | $v = $attrs['http://schemas.xmlsoap.org/wsdl/:arrayType']; |
| 276 | 276 | } else { |
| 277 | 277 | $v = ''; |
| 278 | 278 | } |
| 279 | - if(strpos($v,'[,]')){ |
|
| 279 | + if (strpos($v, '[,]')) { |
|
| 280 | 280 | $this->complexTypes[$this->currentComplexType]['multidimensional'] = true; |
| 281 | 281 | } |
| 282 | - $v = substr($v,0,strpos($v,'[')); // clip the [] |
|
| 283 | - if(!strpos($v,':') && isset($this->typemap[$this->XMLSchemaVersion][$v])){ |
|
| 284 | - $v = $this->XMLSchemaVersion.':'.$v; |
|
| 282 | + $v = substr($v, 0, strpos($v, '[')); // clip the [] |
|
| 283 | + if (!strpos($v, ':') && isset($this->typemap[$this->XMLSchemaVersion][$v])) { |
|
| 284 | + $v = $this->XMLSchemaVersion . ':' . $v; |
|
| 285 | 285 | } |
| 286 | 286 | $this->complexTypes[$this->currentComplexType]['arrayType'] = $v; |
| 287 | 287 | } |
@@ -291,10 +291,10 @@ discard block |
||
| 291 | 291 | break; |
| 292 | 292 | case 'complexType': |
| 293 | 293 | array_push($this->complexTypeStack, $this->currentComplexType); |
| 294 | - if(isset($attrs['name'])){ |
|
| 294 | + if (isset($attrs['name'])) { |
|
| 295 | 295 | // TODO: what is the scope of named complexTypes that appear |
| 296 | 296 | // nested within other c complexTypes? |
| 297 | - $this->xdebug('processing named complexType '.$attrs['name']); |
|
| 297 | + $this->xdebug('processing named complexType ' . $attrs['name']); |
|
| 298 | 298 | $this->currentComplexType = $attrs['name']; |
| 299 | 299 | $this->complexTypes[$this->currentComplexType] = $attrs; |
| 300 | 300 | $this->complexTypes[$this->currentComplexType]['typeClass'] = 'complexType'; |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | // minOccurs="0" maxOccurs="unbounded" /> |
| 306 | 306 | // </sequence> |
| 307 | 307 | // </complexType> |
| 308 | - if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ |
|
| 308 | + if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) { |
|
| 309 | 309 | $this->xdebug('complexType is unusual array'); |
| 310 | 310 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
| 311 | 311 | } else { |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | // minOccurs="0" maxOccurs="unbounded" /> |
| 325 | 325 | // </sequence> |
| 326 | 326 | // </complexType> |
| 327 | - if(isset($attrs['base']) && preg_match('/:Array$/',$attrs['base'])){ |
|
| 327 | + if (isset($attrs['base']) && preg_match('/:Array$/', $attrs['base'])) { |
|
| 328 | 328 | $this->xdebug('complexType is unusual array'); |
| 329 | 329 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
| 330 | 330 | } else { |
@@ -343,9 +343,9 @@ discard block |
||
| 343 | 343 | $attrs['form'] = 'qualified'; |
| 344 | 344 | } |
| 345 | 345 | } |
| 346 | - if(isset($attrs['type'])){ |
|
| 347 | - $this->xdebug("processing typed element ".$attrs['name']." of type ".$attrs['type']); |
|
| 348 | - if (! $this->getPrefix($attrs['type'])) { |
|
| 346 | + if (isset($attrs['type'])) { |
|
| 347 | + $this->xdebug("processing typed element " . $attrs['name'] . " of type " . $attrs['type']); |
|
| 348 | + if (!$this->getPrefix($attrs['type'])) { |
|
| 349 | 349 | if ($this->defaultNamespace[$pos]) { |
| 350 | 350 | $attrs['type'] = $this->defaultNamespace[$pos] . ':' . $attrs['type']; |
| 351 | 351 | $this->xdebug('used default namespace to make type ' . $attrs['type']); |
@@ -364,9 +364,9 @@ discard block |
||
| 364 | 364 | } |
| 365 | 365 | $this->currentElement = $attrs['name']; |
| 366 | 366 | $ename = $attrs['name']; |
| 367 | - } elseif(isset($attrs['ref'])){ |
|
| 368 | - $this->xdebug("processing element as ref to ".$attrs['ref']); |
|
| 369 | - $this->currentElement = "ref to ".$attrs['ref']; |
|
| 367 | + } elseif (isset($attrs['ref'])) { |
|
| 368 | + $this->xdebug("processing element as ref to " . $attrs['ref']); |
|
| 369 | + $this->currentElement = "ref to " . $attrs['ref']; |
|
| 370 | 370 | $ename = $this->getLocalPart($attrs['ref']); |
| 371 | 371 | } else { |
| 372 | 372 | $type = $this->CreateTypeName($this->currentComplexType . '_' . $attrs['name']); |
@@ -380,8 +380,8 @@ discard block |
||
| 380 | 380 | $this->complexTypes[$this->currentComplexType]['elements'][$ename] = $attrs; |
| 381 | 381 | } elseif (!isset($attrs['ref'])) { |
| 382 | 382 | $this->xdebug("add element $ename to elements array"); |
| 383 | - $this->elements[ $attrs['name'] ] = $attrs; |
|
| 384 | - $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
|
| 383 | + $this->elements[$attrs['name']] = $attrs; |
|
| 384 | + $this->elements[$attrs['name']]['typeClass'] = 'element'; |
|
| 385 | 385 | } |
| 386 | 386 | break; |
| 387 | 387 | case 'enumeration': // restriction value list member |
@@ -412,8 +412,8 @@ discard block |
||
| 412 | 412 | } else { |
| 413 | 413 | $this->xdebug('import namespace ' . $attrs['namespace']); |
| 414 | 414 | $this->imports[$attrs['namespace']][] = array('location' => '', 'loaded' => true); |
| 415 | - if (! $this->getPrefixFromNamespace($attrs['namespace'])) { |
|
| 416 | - $this->namespaces['ns'.(count($this->namespaces)+1)] = $attrs['namespace']; |
|
| 415 | + if (!$this->getPrefixFromNamespace($attrs['namespace'])) { |
|
| 416 | + $this->namespaces['ns' . (count($this->namespaces) + 1)] = $attrs['namespace']; |
|
| 417 | 417 | } |
| 418 | 418 | } |
| 419 | 419 | break; |
@@ -430,11 +430,11 @@ discard block |
||
| 430 | 430 | break; |
| 431 | 431 | case 'restriction': // simpleType, simpleContent or complexContent value restriction |
| 432 | 432 | $this->xdebug('restriction ' . $attrs['base']); |
| 433 | - if($this->currentSimpleType){ |
|
| 433 | + if ($this->currentSimpleType) { |
|
| 434 | 434 | $this->simpleTypes[$this->currentSimpleType]['type'] = $attrs['base']; |
| 435 | - } elseif($this->currentComplexType){ |
|
| 435 | + } elseif ($this->currentComplexType) { |
|
| 436 | 436 | $this->complexTypes[$this->currentComplexType]['restrictionBase'] = $attrs['base']; |
| 437 | - if(strstr($attrs['base'],':') == ':Array'){ |
|
| 437 | + if (strstr($attrs['base'], ':') == ':Array') { |
|
| 438 | 438 | $this->complexTypes[$this->currentComplexType]['phpType'] = 'array'; |
| 439 | 439 | } |
| 440 | 440 | } |
@@ -461,12 +461,12 @@ discard block |
||
| 461 | 461 | break; |
| 462 | 462 | case 'simpleType': |
| 463 | 463 | array_push($this->simpleTypeStack, $this->currentSimpleType); |
| 464 | - if(isset($attrs['name'])){ |
|
| 464 | + if (isset($attrs['name'])) { |
|
| 465 | 465 | $this->xdebug("processing simpleType for name " . $attrs['name']); |
| 466 | 466 | $this->currentSimpleType = $attrs['name']; |
| 467 | - $this->simpleTypes[ $attrs['name'] ] = $attrs; |
|
| 468 | - $this->simpleTypes[ $attrs['name'] ]['typeClass'] = 'simpleType'; |
|
| 469 | - $this->simpleTypes[ $attrs['name'] ]['phpType'] = 'scalar'; |
|
| 467 | + $this->simpleTypes[$attrs['name']] = $attrs; |
|
| 468 | + $this->simpleTypes[$attrs['name']]['typeClass'] = 'simpleType'; |
|
| 469 | + $this->simpleTypes[$attrs['name']]['phpType'] = 'scalar'; |
|
| 470 | 470 | } else { |
| 471 | 471 | $name = $this->CreateTypeName($this->currentComplexType . '_' . $this->currentElement); |
| 472 | 472 | $this->xdebug('processing unnamed simpleType for element ' . $this->currentElement . ' named ' . $name); |
@@ -494,27 +494,27 @@ discard block |
||
| 494 | 494 | // bring depth down a notch |
| 495 | 495 | $this->depth--; |
| 496 | 496 | // position of current element is equal to the last value left in depth_array for my depth |
| 497 | - if(isset($this->depth_array[$this->depth])){ |
|
| 497 | + if (isset($this->depth_array[$this->depth])) { |
|
| 498 | 498 | $pos = $this->depth_array[$this->depth]; |
| 499 | 499 | } |
| 500 | 500 | // get element prefix |
| 501 | - if ($prefix = $this->getPrefix($name)){ |
|
| 501 | + if ($prefix = $this->getPrefix($name)) { |
|
| 502 | 502 | // get unqualified name |
| 503 | 503 | $name = $this->getLocalPart($name); |
| 504 | 504 | } else { |
| 505 | 505 | $prefix = ''; |
| 506 | 506 | } |
| 507 | 507 | // move on... |
| 508 | - if($name == 'complexType'){ |
|
| 508 | + if ($name == 'complexType') { |
|
| 509 | 509 | $this->xdebug('done processing complexType ' . ($this->currentComplexType ? $this->currentComplexType : '(unknown)')); |
| 510 | 510 | $this->xdebug($this->varDump($this->complexTypes[$this->currentComplexType])); |
| 511 | 511 | $this->currentComplexType = array_pop($this->complexTypeStack); |
| 512 | 512 | } |
| 513 | - if($name == 'element'){ |
|
| 513 | + if ($name == 'element') { |
|
| 514 | 514 | $this->xdebug('done processing element ' . ($this->currentElement ? $this->currentElement : '(unknown)')); |
| 515 | 515 | $this->currentElement = array_pop($this->elementStack); |
| 516 | 516 | } |
| 517 | - if($name == 'simpleType'){ |
|
| 517 | + if ($name == 'simpleType') { |
|
| 518 | 518 | $this->xdebug('done processing simpleType ' . ($this->currentSimpleType ? $this->currentSimpleType : '(unknown)')); |
| 519 | 519 | $this->xdebug($this->varDump($this->simpleTypes[$this->currentSimpleType])); |
| 520 | 520 | $this->currentSimpleType = array_pop($this->simpleTypeStack); |
@@ -528,7 +528,7 @@ discard block |
||
| 528 | 528 | * @param string $data element content |
| 529 | 529 | * @access private |
| 530 | 530 | */ |
| 531 | - public function schemaCharacterData($parser, $data){ |
|
| 531 | + public function schemaCharacterData($parser, $data) { |
|
| 532 | 532 | $pos = $this->depth_array[$this->depth - 1]; |
| 533 | 533 | $this->message[$pos]['cdata'] .= $data; |
| 534 | 534 | } |
@@ -538,13 +538,13 @@ discard block |
||
| 538 | 538 | * |
| 539 | 539 | * @access public |
| 540 | 540 | */ |
| 541 | - public function serializeSchema(){ |
|
| 541 | + public function serializeSchema() { |
|
| 542 | 542 | |
| 543 | 543 | $schemaPrefix = $this->getPrefixFromNamespace($this->XMLSchemaVersion); |
| 544 | 544 | $xml = ''; |
| 545 | 545 | // imports |
| 546 | 546 | if (sizeof($this->imports) > 0) { |
| 547 | - foreach($this->imports as $ns => $list) { |
|
| 547 | + foreach ($this->imports as $ns => $list) { |
|
| 548 | 548 | foreach ($list as $ii) { |
| 549 | 549 | if ($ii['location'] != '') { |
| 550 | 550 | $xml .= " <$schemaPrefix:import location=\"" . $ii['location'] . '" namespace="' . $ns . "\" />\n"; |
@@ -555,12 +555,12 @@ discard block |
||
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | // complex types |
| 558 | - foreach($this->complexTypes as $typeName => $attrs){ |
|
| 558 | + foreach ($this->complexTypes as $typeName => $attrs) { |
|
| 559 | 559 | $contentStr = ''; |
| 560 | 560 | // serialize child elements |
| 561 | - if(isset($attrs['elements']) && (count($attrs['elements']) > 0)){ |
|
| 562 | - foreach($attrs['elements'] as $element => $eParts){ |
|
| 563 | - if(isset($eParts['ref'])){ |
|
| 561 | + if (isset($attrs['elements']) && (count($attrs['elements']) > 0)) { |
|
| 562 | + foreach ($attrs['elements'] as $element => $eParts) { |
|
| 563 | + if (isset($eParts['ref'])) { |
|
| 564 | 564 | $contentStr .= " <$schemaPrefix:element ref=\"$element\"/>\n"; |
| 565 | 565 | } else { |
| 566 | 566 | $contentStr .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\""; |
@@ -575,19 +575,19 @@ discard block |
||
| 575 | 575 | } |
| 576 | 576 | // compositor wraps elements |
| 577 | 577 | if (isset($attrs['compositor']) && ($attrs['compositor'] != '')) { |
| 578 | - $contentStr = " <$schemaPrefix:$attrs[compositor]>\n".$contentStr." </$schemaPrefix:$attrs[compositor]>\n"; |
|
| 578 | + $contentStr = " <$schemaPrefix:$attrs[compositor]>\n" . $contentStr . " </$schemaPrefix:$attrs[compositor]>\n"; |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | // attributes |
| 582 | - if(isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)){ |
|
| 583 | - foreach($attrs['attrs'] as $attr => $aParts){ |
|
| 582 | + if (isset($attrs['attrs']) && (count($attrs['attrs']) >= 1)) { |
|
| 583 | + foreach ($attrs['attrs'] as $attr => $aParts) { |
|
| 584 | 584 | $contentStr .= " <$schemaPrefix:attribute"; |
| 585 | 585 | foreach ($aParts as $a => $v) { |
| 586 | 586 | if ($a == 'ref' || $a == 'type') { |
| 587 | - $contentStr .= " $a=\"".$this->contractQName($v).'"'; |
|
| 587 | + $contentStr .= " $a=\"" . $this->contractQName($v) . '"'; |
|
| 588 | 588 | } elseif ($a == 'http://schemas.xmlsoap.org/wsdl/:arrayType') { |
| 589 | 589 | $this->usedNamespaces['wsdl'] = $this->namespaces['wsdl']; |
| 590 | - $contentStr .= ' wsdl:arrayType="'.$this->contractQName($v).'"'; |
|
| 590 | + $contentStr .= ' wsdl:arrayType="' . $this->contractQName($v) . '"'; |
|
| 591 | 591 | } else { |
| 592 | 592 | $contentStr .= " $a=\"$v\""; |
| 593 | 593 | } |
@@ -596,25 +596,25 @@ discard block |
||
| 596 | 596 | } |
| 597 | 597 | } |
| 598 | 598 | // if restriction |
| 599 | - if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != ''){ |
|
| 600 | - $contentStr = " <$schemaPrefix:restriction base=\"".$this->contractQName($attrs['restrictionBase'])."\">\n".$contentStr." </$schemaPrefix:restriction>\n"; |
|
| 599 | + if (isset($attrs['restrictionBase']) && $attrs['restrictionBase'] != '') { |
|
| 600 | + $contentStr = " <$schemaPrefix:restriction base=\"" . $this->contractQName($attrs['restrictionBase']) . "\">\n" . $contentStr . " </$schemaPrefix:restriction>\n"; |
|
| 601 | 601 | // complex or simple content |
| 602 | - if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)){ |
|
| 603 | - $contentStr = " <$schemaPrefix:complexContent>\n".$contentStr." </$schemaPrefix:complexContent>\n"; |
|
| 602 | + if ((isset($attrs['elements']) && count($attrs['elements']) > 0) || (isset($attrs['attrs']) && count($attrs['attrs']) > 0)) { |
|
| 603 | + $contentStr = " <$schemaPrefix:complexContent>\n" . $contentStr . " </$schemaPrefix:complexContent>\n"; |
|
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | // finalize complex type |
| 607 | - if($contentStr != ''){ |
|
| 608 | - $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n".$contentStr." </$schemaPrefix:complexType>\n"; |
|
| 607 | + if ($contentStr != '') { |
|
| 608 | + $contentStr = " <$schemaPrefix:complexType name=\"$typeName\">\n" . $contentStr . " </$schemaPrefix:complexType>\n"; |
|
| 609 | 609 | } else { |
| 610 | 610 | $contentStr = " <$schemaPrefix:complexType name=\"$typeName\"/>\n"; |
| 611 | 611 | } |
| 612 | 612 | $xml .= $contentStr; |
| 613 | 613 | } |
| 614 | 614 | // simple types |
| 615 | - if(isset($this->simpleTypes) && count($this->simpleTypes) > 0){ |
|
| 616 | - foreach($this->simpleTypes as $typeName => $eParts){ |
|
| 617 | - $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"".$this->contractQName($eParts['type'])."\">\n"; |
|
| 615 | + if (isset($this->simpleTypes) && count($this->simpleTypes) > 0) { |
|
| 616 | + foreach ($this->simpleTypes as $typeName => $eParts) { |
|
| 617 | + $xml .= " <$schemaPrefix:simpleType name=\"$typeName\">\n <$schemaPrefix:restriction base=\"" . $this->contractQName($eParts['type']) . "\">\n"; |
|
| 618 | 618 | if (isset($eParts['enumeration'])) { |
| 619 | 619 | foreach ($eParts['enumeration'] as $e) { |
| 620 | 620 | $xml .= " <$schemaPrefix:enumeration value=\"$e\"/>\n"; |
@@ -624,15 +624,15 @@ discard block |
||
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | // elements |
| 627 | - if(isset($this->elements) && count($this->elements) > 0){ |
|
| 628 | - foreach($this->elements as $element => $eParts){ |
|
| 629 | - $xml .= " <$schemaPrefix:element name=\"$element\" type=\"".$this->contractQName($eParts['type'])."\"/>\n"; |
|
| 627 | + if (isset($this->elements) && count($this->elements) > 0) { |
|
| 628 | + foreach ($this->elements as $element => $eParts) { |
|
| 629 | + $xml .= " <$schemaPrefix:element name=\"$element\" type=\"" . $this->contractQName($eParts['type']) . "\"/>\n"; |
|
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | // attributes |
| 633 | - if(isset($this->attributes) && count($this->attributes) > 0){ |
|
| 634 | - foreach($this->attributes as $attr => $aParts){ |
|
| 635 | - $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"".$this->contractQName($aParts['type'])."\"\n/>"; |
|
| 633 | + if (isset($this->attributes) && count($this->attributes) > 0) { |
|
| 634 | + foreach ($this->attributes as $attr => $aParts) { |
|
| 635 | + $xml .= " <$schemaPrefix:attribute name=\"$attr\" type=\"" . $this->contractQName($aParts['type']) . "\"\n/>"; |
|
| 636 | 636 | } |
| 637 | 637 | } |
| 638 | 638 | // finish 'er up |
@@ -646,7 +646,7 @@ discard block |
||
| 646 | 646 | foreach (array_diff($this->usedNamespaces, $this->enclosingNamespaces) as $nsp => $ns) { |
| 647 | 647 | $el .= " xmlns:$nsp=\"$ns\""; |
| 648 | 648 | } |
| 649 | - $xml = $el . ">\n".$xml."</$schemaPrefix:schema>\n"; |
|
| 649 | + $xml = $el . ">\n" . $xml . "</$schemaPrefix:schema>\n"; |
|
| 650 | 650 | return $xml; |
| 651 | 651 | } |
| 652 | 652 | |
@@ -656,8 +656,8 @@ discard block |
||
| 656 | 656 | * @param string $string debug data |
| 657 | 657 | * @access private |
| 658 | 658 | */ |
| 659 | - public function xdebug($string){ |
|
| 660 | - $this->debug('<' . $this->schemaTargetNamespace . '> '.$string); |
|
| 659 | + public function xdebug($string) { |
|
| 660 | + $this->debug('<' . $this->schemaTargetNamespace . '> ' . $string); |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -672,11 +672,11 @@ discard block |
||
| 672 | 672 | * @access public |
| 673 | 673 | * @deprecated |
| 674 | 674 | */ |
| 675 | - public function getPHPType($type,$ns){ |
|
| 676 | - if(isset($this->typemap[$ns][$type])){ |
|
| 675 | + public function getPHPType($type, $ns) { |
|
| 676 | + if (isset($this->typemap[$ns][$type])) { |
|
| 677 | 677 | //print "found type '$type' and ns $ns in typemap<br>"; |
| 678 | 678 | return $this->typemap[$ns][$type]; |
| 679 | - } elseif(isset($this->complexTypes[$type])){ |
|
| 679 | + } elseif (isset($this->complexTypes[$type])) { |
|
| 680 | 680 | //print "getting type '$type' and ns $ns from complexTypes array<br>"; |
| 681 | 681 | return $this->complexTypes[$type]['phpType']; |
| 682 | 682 | } |
@@ -705,7 +705,7 @@ discard block |
||
| 705 | 705 | * @see addSimpleType |
| 706 | 706 | * @see addElement |
| 707 | 707 | */ |
| 708 | - public function getTypeDef($type){ |
|
| 708 | + public function getTypeDef($type) { |
|
| 709 | 709 | if (substr($type, -1) == '^') { |
| 710 | 710 | $is_element = 1; |
| 711 | 711 | $type = substr($type, 0, -1); |
@@ -713,10 +713,10 @@ discard block |
||
| 713 | 713 | $is_element = 0; |
| 714 | 714 | } |
| 715 | 715 | |
| 716 | - if((! $is_element) && isset($this->complexTypes[$type])){ |
|
| 716 | + if ((!$is_element) && isset($this->complexTypes[$type])) { |
|
| 717 | 717 | $this->xdebug("in getTypeDef, found complexType $type"); |
| 718 | 718 | return $this->complexTypes[$type]; |
| 719 | - } elseif((! $is_element) && isset($this->simpleTypes[$type])){ |
|
| 719 | + } elseif ((!$is_element) && isset($this->simpleTypes[$type])) { |
|
| 720 | 720 | $this->xdebug("in getTypeDef, found simpleType $type"); |
| 721 | 721 | if (!isset($this->simpleTypes[$type]['phpType'])) { |
| 722 | 722 | // get info for type to tack onto the simple type |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | } |
| 737 | 737 | } |
| 738 | 738 | return $this->simpleTypes[$type]; |
| 739 | - } elseif(isset($this->elements[$type])){ |
|
| 739 | + } elseif (isset($this->elements[$type])) { |
|
| 740 | 740 | $this->xdebug("in getTypeDef, found element $type"); |
| 741 | 741 | if (!isset($this->elements[$type]['phpType'])) { |
| 742 | 742 | // get info for type to tack onto the element |
@@ -761,7 +761,7 @@ discard block |
||
| 761 | 761 | } |
| 762 | 762 | } |
| 763 | 763 | return $this->elements[$type]; |
| 764 | - } elseif(isset($this->attributes[$type])){ |
|
| 764 | + } elseif (isset($this->attributes[$type])) { |
|
| 765 | 765 | $this->xdebug("in getTypeDef, found attribute $type"); |
| 766 | 766 | return $this->attributes[$type]; |
| 767 | 767 | } elseif (preg_match('/_ContainedType$/', $type)) { |
@@ -783,23 +783,23 @@ discard block |
||
| 783 | 783 | * @access public |
| 784 | 784 | * @deprecated |
| 785 | 785 | */ |
| 786 | - function serializeTypeDef($type){ |
|
| 786 | + function serializeTypeDef($type) { |
|
| 787 | 787 | //print "in sTD() for type $type<br>"; |
| 788 | - if($typeDef = $this->getTypeDef($type)){ |
|
| 789 | - $str .= '<'.$type; |
|
| 790 | - if(is_array($typeDef['attrs'])){ |
|
| 791 | - foreach($typeDef['attrs'] as $attName => $data){ |
|
| 792 | - $str .= " $attName=\"{type = ".$data['type']."}\""; |
|
| 788 | + if ($typeDef = $this->getTypeDef($type)) { |
|
| 789 | + $str .= '<' . $type; |
|
| 790 | + if (is_array($typeDef['attrs'])) { |
|
| 791 | + foreach ($typeDef['attrs'] as $attName => $data) { |
|
| 792 | + $str .= " $attName=\"{type = " . $data['type'] . "}\""; |
|
| 793 | 793 | } |
| 794 | 794 | } |
| 795 | - $str .= " xmlns=\"".$this->schema['targetNamespace']."\""; |
|
| 796 | - if(count($typeDef['elements']) > 0){ |
|
| 795 | + $str .= " xmlns=\"" . $this->schema['targetNamespace'] . "\""; |
|
| 796 | + if (count($typeDef['elements']) > 0) { |
|
| 797 | 797 | $str .= ">"; |
| 798 | - foreach($typeDef['elements'] as $element => $eData){ |
|
| 798 | + foreach ($typeDef['elements'] as $element => $eData) { |
|
| 799 | 799 | $str .= $this->serializeTypeDef($element); |
| 800 | 800 | } |
| 801 | 801 | $str .= "</$type>"; |
| 802 | - } elseif($typeDef['typeClass'] == 'element') { |
|
| 802 | + } elseif ($typeDef['typeClass'] == 'element') { |
|
| 803 | 803 | $str .= "></$type>"; |
| 804 | 804 | } else { |
| 805 | 805 | $str .= "/>"; |
@@ -819,25 +819,25 @@ discard block |
||
| 819 | 819 | * @access public |
| 820 | 820 | * @deprecated |
| 821 | 821 | */ |
| 822 | - public function typeToForm($name,$type){ |
|
| 822 | + public function typeToForm($name, $type) { |
|
| 823 | 823 | // get typedef |
| 824 | - if($typeDef = $this->getTypeDef($type)){ |
|
| 824 | + if ($typeDef = $this->getTypeDef($type)) { |
|
| 825 | 825 | // if struct |
| 826 | - if($typeDef['phpType'] == 'struct'){ |
|
| 826 | + if ($typeDef['phpType'] == 'struct') { |
|
| 827 | 827 | $buffer .= '<table>'; |
| 828 | - foreach($typeDef['elements'] as $child => $childDef){ |
|
| 828 | + foreach ($typeDef['elements'] as $child => $childDef) { |
|
| 829 | 829 | $buffer .= " |
| 830 | - <tr><td align='right'>$childDef[name] (type: ".$this->getLocalPart($childDef['type'])."):</td> |
|
| 831 | - <td><input type='text' name='parameters[".$name."][$childDef[name]]'></td></tr>"; |
|
| 830 | + <tr><td align='right'>$childDef[name] (type: " . $this->getLocalPart($childDef['type']) . "):</td> |
|
| 831 | + <td><input type='text' name='parameters[".$name . "][$childDef[name]]'></td></tr>"; |
|
| 832 | 832 | } |
| 833 | 833 | $buffer .= '</table>'; |
| 834 | 834 | // if array |
| 835 | - } elseif($typeDef['phpType'] == 'array'){ |
|
| 835 | + } elseif ($typeDef['phpType'] == 'array') { |
|
| 836 | 836 | $buffer .= '<table>'; |
| 837 | - for($i=0;$i < 3; $i++){ |
|
| 837 | + for ($i = 0; $i < 3; $i++) { |
|
| 838 | 838 | $buffer .= " |
| 839 | 839 | <tr><td align='right'>array item (type: $typeDef[arrayType]):</td> |
| 840 | - <td><input type='text' name='parameters[".$name."][]'></td></tr>"; |
|
| 840 | + <td><input type='text' name='parameters[" . $name . "][]'></td></tr>"; |
|
| 841 | 841 | } |
| 842 | 842 | $buffer .= '</table>'; |
| 843 | 843 | // if scalar |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | * @access public |
| 892 | 892 | * @see getTypeDef |
| 893 | 893 | */ |
| 894 | - public function addComplexType($name,$typeClass='complexType',$phpType='array',$compositor='',$restrictionBase='',$elements=array(),$attrs=array(),$arrayType=''){ |
|
| 894 | + public function addComplexType($name, $typeClass = 'complexType', $phpType = 'array', $compositor = '', $restrictionBase = '', $elements = array(), $attrs = array(), $arrayType = '') { |
|
| 895 | 895 | $this->complexTypes[$name] = array( |
| 896 | 896 | 'name' => $name, |
| 897 | 897 | 'typeClass' => $typeClass, |
@@ -919,7 +919,7 @@ discard block |
||
| 919 | 919 | * @see nusoap_xmlschema |
| 920 | 920 | * @see getTypeDef |
| 921 | 921 | */ |
| 922 | - public function addSimpleType($name, $restrictionBase='', $typeClass='simpleType', $phpType='scalar', $enumeration=array()) { |
|
| 922 | + public function addSimpleType($name, $restrictionBase = '', $typeClass = 'simpleType', $phpType = 'scalar', $enumeration = array()) { |
|
| 923 | 923 | $this->simpleTypes[$name] = array( |
| 924 | 924 | 'name' => $name, |
| 925 | 925 | 'typeClass' => $typeClass, |
@@ -940,14 +940,14 @@ discard block |
||
| 940 | 940 | * @access public |
| 941 | 941 | */ |
| 942 | 942 | public function addElement($attrs) { |
| 943 | - if (! $this->getPrefix($attrs['type'])) { |
|
| 943 | + if (!$this->getPrefix($attrs['type'])) { |
|
| 944 | 944 | $attrs['type'] = $this->schemaTargetNamespace . ':' . $attrs['type']; |
| 945 | 945 | } |
| 946 | - $this->elements[ $attrs['name'] ] = $attrs; |
|
| 947 | - $this->elements[ $attrs['name'] ]['typeClass'] = 'element'; |
|
| 946 | + $this->elements[$attrs['name']] = $attrs; |
|
| 947 | + $this->elements[$attrs['name']]['typeClass'] = 'element'; |
|
| 948 | 948 | |
| 949 | 949 | $this->xdebug("addElement " . $attrs['name']); |
| 950 | - $this->appendDebug($this->varDump($this->elements[ $attrs['name'] ])); |
|
| 950 | + $this->appendDebug($this->varDump($this->elements[$attrs['name']])); |
|
| 951 | 951 | } |
| 952 | 952 | } |
| 953 | 953 | |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | /** |
| 327 | 327 | * gets the current debug data for this instance |
| 328 | 328 | * |
| 329 | - * @return debug data |
|
| 329 | + * @return string data |
|
| 330 | 330 | * @access public |
| 331 | 331 | */ |
| 332 | 332 | public function &getDebug() |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | * gets the current debug data for this instance as an XML comment |
| 341 | 341 | * this may change the contents of the debug data |
| 342 | 342 | * |
| 343 | - * @return debug data as an XML comment |
|
| 343 | + * @return string data as an XML comment |
|
| 344 | 344 | * @access public |
| 345 | 345 | */ |
| 346 | 346 | public function &getDebugAsXMLComment() |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | /** |
| 376 | 376 | * returns error string if present |
| 377 | 377 | * |
| 378 | - * @return mixed error string or false |
|
| 378 | + * @return string|false error string or false |
|
| 379 | 379 | * @access public |
| 380 | 380 | */ |
| 381 | 381 | public function getError() |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | /** |
| 390 | 390 | * sets error string |
| 391 | 391 | * |
| 392 | - * @return boolean $string error string |
|
| 392 | + * @return boolean|null $string error string |
|
| 393 | 393 | * @access private |
| 394 | 394 | */ |
| 395 | 395 | public function setError($str) |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | * returns false, if not prefixed |
| 833 | 833 | * |
| 834 | 834 | * @param string $str The prefixed string |
| 835 | - * @return mixed The prefix or false if there is no prefix |
|
| 835 | + * @return string|false The prefix or false if there is no prefix |
|
| 836 | 836 | * @access public |
| 837 | 837 | */ |
| 838 | 838 | public function getPrefix($str) |
@@ -864,7 +864,7 @@ discard block |
||
| 864 | 864 | * or false if no prefixes registered for the given namespace |
| 865 | 865 | * |
| 866 | 866 | * @param string $ns The namespace |
| 867 | - * @return mixed The prefix, false if the namespace has no prefixes |
|
| 867 | + * @return string The prefix, false if the namespace has no prefixes |
|
| 868 | 868 | * @access public |
| 869 | 869 | */ |
| 870 | 870 | public function getPrefixFromNamespace($ns) |
@@ -933,7 +933,7 @@ discard block |
||
| 933 | 933 | * |
| 934 | 934 | * @param int $timestamp Unix time stamp |
| 935 | 935 | * @param boolean $utc Whether the time stamp is UTC or local |
| 936 | - * @return mixed ISO 8601 date string or false |
|
| 936 | + * @return string|false ISO 8601 date string or false |
|
| 937 | 937 | * @access public |
| 938 | 938 | */ |
| 939 | 939 | function timestamp_to_iso8601($timestamp, $utc = true) |
@@ -1073,7 +1073,7 @@ discard block |
||
| 1073 | 1073 | * @param string $faultcode (SOAP-ENV:Client | SOAP-ENV:Server) |
| 1074 | 1074 | * @param string $faultactor only used when msg routed between multiple actors |
| 1075 | 1075 | * @param string $faultstring human readable error message |
| 1076 | - * @param mixed $faultdetail detail, typically a string or array of string |
|
| 1076 | + * @param string $faultdetail detail, typically a string or array of string |
|
| 1077 | 1077 | */ |
| 1078 | 1078 | public function nusoap_fault($faultcode, $faultactor = '', $faultstring = '', $faultdetail = '') |
| 1079 | 1079 | { |
@@ -1906,7 +1906,7 @@ discard block |
||
| 1906 | 1906 | * returns a sample serialization of a given type, or false if no type by the given name |
| 1907 | 1907 | * |
| 1908 | 1908 | * @param string $type name of type |
| 1909 | - * @return mixed |
|
| 1909 | + * @return string|false |
|
| 1910 | 1910 | * @access public |
| 1911 | 1911 | * @deprecated |
| 1912 | 1912 | */ |
@@ -2160,7 +2160,7 @@ discard block |
||
| 2160 | 2160 | * |
| 2161 | 2161 | * @param string $name optional name |
| 2162 | 2162 | * @param mixed $type optional type name |
| 2163 | - * @param mixed $value optional value |
|
| 2163 | + * @param integer $value optional value |
|
| 2164 | 2164 | * @param mixed $element_ns optional namespace of value |
| 2165 | 2165 | * @param mixed $type_ns optional namespace of type |
| 2166 | 2166 | * @param mixed $attributes associative array of attributes to add to element serialization |
@@ -2377,7 +2377,6 @@ discard block |
||
| 2377 | 2377 | /** |
| 2378 | 2378 | * establish an HTTP connection |
| 2379 | 2379 | * |
| 2380 | - * @param integer $timeout set connection timeout in seconds |
|
| 2381 | 2380 | * @param integer $response_timeout set response timeout in seconds |
| 2382 | 2381 | * @return boolean true if connected, false if not |
| 2383 | 2382 | * @access private |
@@ -2944,7 +2943,7 @@ discard block |
||
| 2944 | 2943 | * |
| 2945 | 2944 | * @param string $data message data |
| 2946 | 2945 | * @param array $cookies cookies to send |
| 2947 | - * @return boolean true if OK, false if problem |
|
| 2946 | + * @return boolean|null true if OK, false if problem |
|
| 2948 | 2947 | * @access private |
| 2949 | 2948 | */ |
| 2950 | 2949 | public function sendRequest($data, $cookies = NULL) |
@@ -3413,6 +3412,10 @@ discard block |
||
| 3413 | 3412 | /* |
| 3414 | 3413 | * TODO: allow a Set-Cookie string to be parsed into multiple cookies |
| 3415 | 3414 | */ |
| 3415 | + |
|
| 3416 | + /** |
|
| 3417 | + * @param string $cookie_str |
|
| 3418 | + */ |
|
| 3416 | 3419 | public function parseCookie($cookie_str) |
| 3417 | 3420 | { |
| 3418 | 3421 | $cookie_str = str_replace('; ', ';', $cookie_str) . ';'; |
@@ -4360,7 +4363,7 @@ discard block |
||
| 4360 | 4363 | * |
| 4361 | 4364 | * @param array $headers The HTTP headers |
| 4362 | 4365 | * @param string $data unprocessed request data from client |
| 4363 | - * @return mixed value of the message, decoded into a PHP type |
|
| 4366 | + * @return false|null value of the message, decoded into a PHP type |
|
| 4364 | 4367 | * @access private |
| 4365 | 4368 | */ |
| 4366 | 4369 | public function parseRequest($headers, $data) |
@@ -4742,6 +4745,7 @@ discard block |
||
| 4742 | 4745 | * fetches the WSDL document and parses it |
| 4743 | 4746 | * |
| 4744 | 4747 | * @access public |
| 4748 | + * @param string $wsdl |
|
| 4745 | 4749 | */ |
| 4746 | 4750 | public function fetchWSDL($wsdl) |
| 4747 | 4751 | { |
@@ -5539,7 +5543,7 @@ discard block |
||
| 5539 | 5543 | /** |
| 5540 | 5544 | * serialize the parsed wsdl |
| 5541 | 5545 | * |
| 5542 | - * @param mixed $debug whether to put debug=1 in endpoint URL |
|
| 5546 | + * @param integer $debug whether to put debug=1 in endpoint URL |
|
| 5543 | 5547 | * @return string serialization of WSDL |
| 5544 | 5548 | * @access public |
| 5545 | 5549 | */ |
@@ -5763,7 +5767,7 @@ discard block |
||
| 5763 | 5767 | * @param string $direction (input|output) |
| 5764 | 5768 | * @param mixed $parameters parameter value(s) |
| 5765 | 5769 | * @param string $bindingType (soap|soap12) |
| 5766 | - * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
| 5770 | + * @return false|string parameters serialized as XML or false on error (e.g. operation not found) |
|
| 5767 | 5771 | * @access public |
| 5768 | 5772 | */ |
| 5769 | 5773 | public function serializeRPCParameters($operation, $direction, $parameters, $bindingType = 'soap') |
@@ -5864,7 +5868,7 @@ discard block |
||
| 5864 | 5868 | * @param string $operation operation name |
| 5865 | 5869 | * @param string $direction (input|output) |
| 5866 | 5870 | * @param mixed $parameters parameter value(s) |
| 5867 | - * @return mixed parameters serialized as XML or false on error (e.g. operation not found) |
|
| 5871 | + * @return false|string parameters serialized as XML or false on error (e.g. operation not found) |
|
| 5868 | 5872 | * @access public |
| 5869 | 5873 | * @deprecated |
| 5870 | 5874 | */ |
@@ -2235,8 +2235,8 @@ discard block |
||
| 2235 | 2235 | var $persistentConnection = false; |
| 2236 | 2236 | var $ch = false; // cURL handle |
| 2237 | 2237 | var $ch_options = array(); // cURL custom options |
| 2238 | - var $use_curl = false; // force cURL use |
|
| 2239 | - var $proxy = null; // proxy information (associative array) |
|
| 2238 | + var $use_curl = false; // force cURL use |
|
| 2239 | + var $proxy = null; // proxy information (associative array) |
|
| 2240 | 2240 | var $username = ''; |
| 2241 | 2241 | var $password = ''; |
| 2242 | 2242 | var $authtype = ''; |
@@ -2684,7 +2684,7 @@ discard block |
||
| 2684 | 2684 | $this->setHeader('Authorization', 'Basic ' . base64_encode(str_replace(':', '', $username) . ':' . $password)); |
| 2685 | 2685 | } elseif ($authtype == 'digest') { |
| 2686 | 2686 | if (isset($digestRequest['nonce'])) { |
| 2687 | - $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc'] ++ : 1; |
|
| 2687 | + $digestRequest['nc'] = isset($digestRequest['nc']) ? $digestRequest['nc']++ : 1; |
|
| 2688 | 2688 | |
| 2689 | 2689 | // calculate the Digest hashes (calculate code based on digest implementation found at: http://www.rassoc.com/gregr/weblog/stories/2002/07/09/webServicesSecurityHttpDigestAuthenticationWithoutActiveDirectory.html) |
| 2690 | 2690 | // A1 = unq(username-value) ":" unq(realm-value) ":" passwd |
@@ -4140,7 +4140,7 @@ discard block |
||
| 4140 | 4140 | $call_arg = array($class, $method); |
| 4141 | 4141 | } else { |
| 4142 | 4142 | $this->debug('in invoke_method, calling instance method using call_user_func_array()'); |
| 4143 | - $instance = new $class (); |
|
| 4143 | + $instance = new $class(); |
|
| 4144 | 4144 | $call_arg = array(&$instance, $method); |
| 4145 | 4145 | } |
| 4146 | 4146 | if (is_array($this->methodparams)) { |
@@ -4700,12 +4700,12 @@ discard block |
||
| 4700 | 4700 | var $timeout = 0; |
| 4701 | 4701 | var $response_timeout = 30; |
| 4702 | 4702 | var $curl_options = array(); // User-specified cURL options |
| 4703 | - var $use_curl = false; // whether to always try to use cURL |
|
| 4703 | + var $use_curl = false; // whether to always try to use cURL |
|
| 4704 | 4704 | // for HTTP authentication |
| 4705 | 4705 | var $username = ''; // Username for HTTP authentication |
| 4706 | 4706 | var $password = ''; // Password for HTTP authentication |
| 4707 | 4707 | var $authtype = ''; // Type of HTTP authentication |
| 4708 | - var $certRequest = array(); // Certificate for HTTP SSL authentication |
|
| 4708 | + var $certRequest = array(); // Certificate for HTTP SSL authentication |
|
| 4709 | 4709 | |
| 4710 | 4710 | /** |
| 4711 | 4711 | * constructor |
@@ -4821,11 +4821,9 @@ discard block |
||
| 4821 | 4821 | foreach ($bindingData['operations'] as $operation => $data) { |
| 4822 | 4822 | $this->debug('post-parse data gathering for ' . $operation); |
| 4823 | 4823 | $this->bindings[$binding]['operations'][$operation]['input'] = isset($this->bindings[$binding]['operations'][$operation]['input']) ? |
| 4824 | - array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) : |
|
| 4825 | - $this->portTypes[$bindingData['portType']][$operation]['input']; |
|
| 4824 | + array_merge($this->bindings[$binding]['operations'][$operation]['input'], $this->portTypes[$bindingData['portType']][$operation]['input']) : $this->portTypes[$bindingData['portType']][$operation]['input']; |
|
| 4826 | 4825 | $this->bindings[$binding]['operations'][$operation]['output'] = isset($this->bindings[$binding]['operations'][$operation]['output']) ? |
| 4827 | - array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) : |
|
| 4828 | - $this->portTypes[$bindingData['portType']][$operation]['output']; |
|
| 4826 | + array_merge($this->bindings[$binding]['operations'][$operation]['output'], $this->portTypes[$bindingData['portType']][$operation]['output']) : $this->portTypes[$bindingData['portType']][$operation]['output']; |
|
| 4829 | 4827 | if (isset($this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']])) { |
| 4830 | 4828 | $this->bindings[$binding]['operations'][$operation]['input']['parts'] = $this->messages[$this->bindings[$binding]['operations'][$operation]['input']['message']]; |
| 4831 | 4829 | } |
@@ -6369,7 +6367,7 @@ discard block |
||
| 6369 | 6367 | } |
| 6370 | 6368 | } |
| 6371 | 6369 | // if user took advantage of a minOccurs=0, then only serialize named parameters |
| 6372 | - if (isset($optionals) && (!isset($xvalue[$eName])) && ( (!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
| 6370 | + if (isset($optionals) && (!isset($xvalue[$eName])) && ((!isset($attrs['nillable'])) || $attrs['nillable'] != 'true') |
|
| 6373 | 6371 | ) { |
| 6374 | 6372 | if (isset($attrs['minOccurs']) && $attrs['minOccurs'] <> '0') { |
| 6375 | 6373 | $this->debug("apparent error: no value provided for element $eName with minOccurs=" . $attrs['minOccurs']); |
@@ -6614,7 +6612,7 @@ discard block |
||
| 6614 | 6612 | var $root_struct_name = ''; |
| 6615 | 6613 | var $root_struct_namespace = ''; |
| 6616 | 6614 | var $root_header = ''; |
| 6617 | - var $document = ''; // incoming SOAP body (text) |
|
| 6615 | + var $document = ''; // incoming SOAP body (text) |
|
| 6618 | 6616 | // determines where in the message we are (envelope,header,body,method) |
| 6619 | 6617 | var $status = ''; |
| 6620 | 6618 | var $position = 0; |
@@ -6630,7 +6628,7 @@ discard block |
||
| 6630 | 6628 | var $depth_array = array(); |
| 6631 | 6629 | var $debug_flag = true; |
| 6632 | 6630 | var $soapresponse = NULL; // parsed SOAP Body |
| 6633 | - var $soapheader = NULL; // parsed SOAP Header |
|
| 6631 | + var $soapheader = NULL; // parsed SOAP Header |
|
| 6634 | 6632 | var $responseHeaders = ''; // incoming SOAP headers (text) |
| 6635 | 6633 | var $body_position = 0; |
| 6636 | 6634 | // for multiref parsing: |
@@ -2367,10 +2367,12 @@ discard block |
||
| 2367 | 2367 | */ |
| 2368 | 2368 | public function io_method() |
| 2369 | 2369 | { |
| 2370 | - if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) |
|
| 2371 | - return 'curl'; |
|
| 2372 | - if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) |
|
| 2373 | - return 'socket'; |
|
| 2370 | + if ($this->use_curl || ($this->scheme == 'https') || ($this->scheme == 'http' && $this->authtype == 'ntlm') || ($this->scheme == 'http' && is_array($this->proxy) && $this->proxy['authtype'] == 'ntlm')) { |
|
| 2371 | + return 'curl'; |
|
| 2372 | + } |
|
| 2373 | + if (($this->scheme == 'http' || $this->scheme == 'ssl') && $this->authtype != 'ntlm' && (!is_array($this->proxy) || $this->proxy['authtype'] != 'ntlm')) { |
|
| 2374 | + return 'socket'; |
|
| 2375 | + } |
|
| 2374 | 2376 | return 'unknown'; |
| 2375 | 2377 | } |
| 2376 | 2378 | |
@@ -2455,30 +2457,36 @@ discard block |
||
| 2455 | 2457 | return false; |
| 2456 | 2458 | } |
| 2457 | 2459 | // Avoid warnings when PHP does not have these options |
| 2458 | - if (defined('CURLOPT_CONNECTIONTIMEOUT')) |
|
| 2459 | - $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT; |
|
| 2460 | - else |
|
| 2461 | - $CURLOPT_CONNECTIONTIMEOUT = 78; |
|
| 2462 | - if (defined('CURLOPT_HTTPAUTH')) |
|
| 2463 | - $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH; |
|
| 2464 | - else |
|
| 2465 | - $CURLOPT_HTTPAUTH = 107; |
|
| 2466 | - if (defined('CURLOPT_PROXYAUTH')) |
|
| 2467 | - $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH; |
|
| 2468 | - else |
|
| 2469 | - $CURLOPT_PROXYAUTH = 111; |
|
| 2470 | - if (defined('CURLAUTH_BASIC')) |
|
| 2471 | - $CURLAUTH_BASIC = CURLAUTH_BASIC; |
|
| 2472 | - else |
|
| 2473 | - $CURLAUTH_BASIC = 1; |
|
| 2474 | - if (defined('CURLAUTH_DIGEST')) |
|
| 2475 | - $CURLAUTH_DIGEST = CURLAUTH_DIGEST; |
|
| 2476 | - else |
|
| 2477 | - $CURLAUTH_DIGEST = 2; |
|
| 2478 | - if (defined('CURLAUTH_NTLM')) |
|
| 2479 | - $CURLAUTH_NTLM = CURLAUTH_NTLM; |
|
| 2480 | - else |
|
| 2481 | - $CURLAUTH_NTLM = 8; |
|
| 2460 | + if (defined('CURLOPT_CONNECTIONTIMEOUT')) { |
|
| 2461 | + $CURLOPT_CONNECTIONTIMEOUT = CURLOPT_CONNECTIONTIMEOUT; |
|
| 2462 | + } else { |
|
| 2463 | + $CURLOPT_CONNECTIONTIMEOUT = 78; |
|
| 2464 | + } |
|
| 2465 | + if (defined('CURLOPT_HTTPAUTH')) { |
|
| 2466 | + $CURLOPT_HTTPAUTH = CURLOPT_HTTPAUTH; |
|
| 2467 | + } else { |
|
| 2468 | + $CURLOPT_HTTPAUTH = 107; |
|
| 2469 | + } |
|
| 2470 | + if (defined('CURLOPT_PROXYAUTH')) { |
|
| 2471 | + $CURLOPT_PROXYAUTH = CURLOPT_PROXYAUTH; |
|
| 2472 | + } else { |
|
| 2473 | + $CURLOPT_PROXYAUTH = 111; |
|
| 2474 | + } |
|
| 2475 | + if (defined('CURLAUTH_BASIC')) { |
|
| 2476 | + $CURLAUTH_BASIC = CURLAUTH_BASIC; |
|
| 2477 | + } else { |
|
| 2478 | + $CURLAUTH_BASIC = 1; |
|
| 2479 | + } |
|
| 2480 | + if (defined('CURLAUTH_DIGEST')) { |
|
| 2481 | + $CURLAUTH_DIGEST = CURLAUTH_DIGEST; |
|
| 2482 | + } else { |
|
| 2483 | + $CURLAUTH_DIGEST = 2; |
|
| 2484 | + } |
|
| 2485 | + if (defined('CURLAUTH_NTLM')) { |
|
| 2486 | + $CURLAUTH_NTLM = CURLAUTH_NTLM; |
|
| 2487 | + } else { |
|
| 2488 | + $CURLAUTH_NTLM = 8; |
|
| 2489 | + } |
|
| 2482 | 2490 | |
| 2483 | 2491 | $this->debug('connect using cURL'); |
| 2484 | 2492 | // init CURL |
@@ -2823,8 +2831,9 @@ discard block |
||
| 2823 | 2831 | 'HTTP/1.0 200 Connection established'); |
| 2824 | 2832 | foreach ($skipHeaders as $hd) { |
| 2825 | 2833 | $prefix = substr($data, 0, strlen($hd)); |
| 2826 | - if ($prefix == $hd) |
|
| 2827 | - return true; |
|
| 2834 | + if ($prefix == $hd) { |
|
| 2835 | + return true; |
|
| 2836 | + } |
|
| 2828 | 2837 | } |
| 2829 | 2838 | |
| 2830 | 2839 | return false; |
@@ -4732,8 +4741,9 @@ discard block |
||
| 4732 | 4741 | $this->proxypassword = $proxypassword; |
| 4733 | 4742 | $this->timeout = $timeout; |
| 4734 | 4743 | $this->response_timeout = $response_timeout; |
| 4735 | - if (is_array($curl_options)) |
|
| 4736 | - $this->curl_options = $curl_options; |
|
| 4744 | + if (is_array($curl_options)) { |
|
| 4745 | + $this->curl_options = $curl_options; |
|
| 4746 | + } |
|
| 4737 | 4747 | $this->use_curl = $use_curl; |
| 4738 | 4748 | $this->fetchWSDL($wsdl); |
| 4739 | 4749 | } |
@@ -6467,8 +6477,9 @@ discard block |
||
| 6467 | 6477 | $attrs = $eAttrs; |
| 6468 | 6478 | } |
| 6469 | 6479 | |
| 6470 | - if (!is_array($restrictionBase)) |
|
| 6471 | - $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
| 6480 | + if (!is_array($restrictionBase)) { |
|
| 6481 | + $restrictionBase = strpos($restrictionBase, ':') ? $this->expandQname($restrictionBase) : $restrictionBase; |
|
| 6482 | + } |
|
| 6472 | 6483 | $arrayType = strpos($arrayType, ':') ? $this->expandQname($arrayType) : $arrayType; |
| 6473 | 6484 | |
| 6474 | 6485 | $typens = isset($this->namespaces['types']) ? $this->namespaces['types'] : $this->namespaces['tns']; |
@@ -447,7 +447,7 @@ |
||
| 447 | 447 | * |
| 448 | 448 | * @param array $headers The HTTP headers |
| 449 | 449 | * @param string $data unprocessed request data from client |
| 450 | - * @return mixed value of the message, decoded into a PHP type |
|
| 450 | + * @return false|null value of the message, decoded into a PHP type |
|
| 451 | 451 | * @access private |
| 452 | 452 | */ |
| 453 | 453 | function parseRequest($headers, $data) { |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | var $mimeContentType; |
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | - * adds a MIME attachment to the current request. |
|
| 75 | - * |
|
| 76 | - * If the $data parameter contains an empty string, this method will read |
|
| 77 | - * the contents of the file named by the $filename parameter. |
|
| 78 | - * |
|
| 79 | - * If the $cid parameter is false, this method will generate the cid. |
|
| 80 | - * |
|
| 81 | - * @param string $data The data of the attachment |
|
| 82 | - * @param string $filename The filename of the attachment (default is empty string) |
|
| 83 | - * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
| 84 | - * @param string $cid The content-id (cid) of the attachment (default is false) |
|
| 85 | - * @return string The content-id (cid) of the attachment |
|
| 86 | - * @access public |
|
| 87 | - */ |
|
| 74 | + * adds a MIME attachment to the current request. |
|
| 75 | + * |
|
| 76 | + * If the $data parameter contains an empty string, this method will read |
|
| 77 | + * the contents of the file named by the $filename parameter. |
|
| 78 | + * |
|
| 79 | + * If the $cid parameter is false, this method will generate the cid. |
|
| 80 | + * |
|
| 81 | + * @param string $data The data of the attachment |
|
| 82 | + * @param string $filename The filename of the attachment (default is empty string) |
|
| 83 | + * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
| 84 | + * @param string $cid The content-id (cid) of the attachment (default is false) |
|
| 85 | + * @return string The content-id (cid) of the attachment |
|
| 86 | + * @access public |
|
| 87 | + */ |
|
| 88 | 88 | public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
| 89 | 89 | if (! $cid) { |
| 90 | 90 | $cid = md5(uniqid(time())); |
@@ -101,35 +101,35 @@ discard block |
||
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * clears the MIME attachments for the current request. |
|
| 105 | - * |
|
| 106 | - * @access public |
|
| 107 | - */ |
|
| 104 | + * clears the MIME attachments for the current request. |
|
| 105 | + * |
|
| 106 | + * @access public |
|
| 107 | + */ |
|
| 108 | 108 | public function clearAttachments() { |
| 109 | 109 | $this->requestAttachments = array(); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
| 113 | - * gets the MIME attachments from the current response. |
|
| 114 | - * |
|
| 115 | - * Each array element in the return is an associative array with keys |
|
| 116 | - * data, filename, contenttype, cid. These keys correspond to the parameters |
|
| 117 | - * for addAttachment. |
|
| 118 | - * |
|
| 119 | - * @return array The attachments. |
|
| 120 | - * @access public |
|
| 121 | - */ |
|
| 113 | + * gets the MIME attachments from the current response. |
|
| 114 | + * |
|
| 115 | + * Each array element in the return is an associative array with keys |
|
| 116 | + * data, filename, contenttype, cid. These keys correspond to the parameters |
|
| 117 | + * for addAttachment. |
|
| 118 | + * |
|
| 119 | + * @return array The attachments. |
|
| 120 | + * @access public |
|
| 121 | + */ |
|
| 122 | 122 | public function getAttachments() { |
| 123 | 123 | return $this->responseAttachments; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
| 127 | - * gets the HTTP body for the current request. |
|
| 128 | - * |
|
| 129 | - * @param string $soapmsg The SOAP payload |
|
| 130 | - * @return string The HTTP body, which includes the SOAP payload |
|
| 131 | - * @access private |
|
| 132 | - */ |
|
| 127 | + * gets the HTTP body for the current request. |
|
| 128 | + * |
|
| 129 | + * @param string $soapmsg The SOAP payload |
|
| 130 | + * @return string The HTTP body, which includes the SOAP payload |
|
| 131 | + * @access private |
|
| 132 | + */ |
|
| 133 | 133 | public function getHTTPBody($soapmsg) { |
| 134 | 134 | if (count($this->requestAttachments) > 0) { |
| 135 | 135 | $params['content_type'] = 'multipart/related; type="text/xml"'; |
@@ -182,13 +182,13 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
| 185 | - * gets the HTTP content type for the current request. |
|
| 186 | - * |
|
| 187 | - * Note: getHTTPBody must be called before this. |
|
| 188 | - * |
|
| 189 | - * @return string the HTTP content type for the current request. |
|
| 190 | - * @access private |
|
| 191 | - */ |
|
| 185 | + * gets the HTTP content type for the current request. |
|
| 186 | + * |
|
| 187 | + * Note: getHTTPBody must be called before this. |
|
| 188 | + * |
|
| 189 | + * @return string the HTTP content type for the current request. |
|
| 190 | + * @access private |
|
| 191 | + */ |
|
| 192 | 192 | public function getHTTPContentType() { |
| 193 | 193 | if (count($this->requestAttachments) > 0) { |
| 194 | 194 | return $this->mimeContentType; |
@@ -197,14 +197,14 @@ discard block |
||
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | /** |
| 200 | - * gets the HTTP content type charset for the current request. |
|
| 201 | - * returns false for non-text content types. |
|
| 202 | - * |
|
| 203 | - * Note: getHTTPBody must be called before this. |
|
| 204 | - * |
|
| 205 | - * @return string the HTTP content type charset for the current request. |
|
| 206 | - * @access private |
|
| 207 | - */ |
|
| 200 | + * gets the HTTP content type charset for the current request. |
|
| 201 | + * returns false for non-text content types. |
|
| 202 | + * |
|
| 203 | + * Note: getHTTPBody must be called before this. |
|
| 204 | + * |
|
| 205 | + * @return string the HTTP content type charset for the current request. |
|
| 206 | + * @access private |
|
| 207 | + */ |
|
| 208 | 208 | public function getHTTPContentTypeCharset() { |
| 209 | 209 | if (count($this->requestAttachments) > 0) { |
| 210 | 210 | return false; |
@@ -213,14 +213,14 @@ discard block |
||
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
| 216 | - * processes SOAP message returned from server |
|
| 217 | - * |
|
| 218 | - * @param array $headers The HTTP headers |
|
| 219 | - * @param string $data unprocessed response data from server |
|
| 220 | - * @return mixed value of the message, decoded into a PHP type |
|
| 221 | - * @access private |
|
| 222 | - */ |
|
| 223 | - function parseResponse($headers, $data) { |
|
| 216 | + * processes SOAP message returned from server |
|
| 217 | + * |
|
| 218 | + * @param array $headers The HTTP headers |
|
| 219 | + * @param string $data unprocessed response data from server |
|
| 220 | + * @return mixed value of the message, decoded into a PHP type |
|
| 221 | + * @access private |
|
| 222 | + */ |
|
| 223 | + function parseResponse($headers, $data) { |
|
| 224 | 224 | $this->debug('Entering parseResponse() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
| 225 | 225 | $this->responseAttachments = array(); |
| 226 | 226 | if (strstr($headers['content-type'], 'multipart/related')) { |
@@ -301,20 +301,20 @@ discard block |
||
| 301 | 301 | var $mimeContentType; |
| 302 | 302 | |
| 303 | 303 | /** |
| 304 | - * adds a MIME attachment to the current response. |
|
| 305 | - * |
|
| 306 | - * If the $data parameter contains an empty string, this method will read |
|
| 307 | - * the contents of the file named by the $filename parameter. |
|
| 308 | - * |
|
| 309 | - * If the $cid parameter is false, this method will generate the cid. |
|
| 310 | - * |
|
| 311 | - * @param string $data The data of the attachment |
|
| 312 | - * @param string $filename The filename of the attachment (default is empty string) |
|
| 313 | - * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
| 314 | - * @param string $cid The content-id (cid) of the attachment (default is false) |
|
| 315 | - * @return string The content-id (cid) of the attachment |
|
| 316 | - * @access public |
|
| 317 | - */ |
|
| 304 | + * adds a MIME attachment to the current response. |
|
| 305 | + * |
|
| 306 | + * If the $data parameter contains an empty string, this method will read |
|
| 307 | + * the contents of the file named by the $filename parameter. |
|
| 308 | + * |
|
| 309 | + * If the $cid parameter is false, this method will generate the cid. |
|
| 310 | + * |
|
| 311 | + * @param string $data The data of the attachment |
|
| 312 | + * @param string $filename The filename of the attachment (default is empty string) |
|
| 313 | + * @param string $contenttype The MIME Content-Type of the attachment (default is application/octet-stream) |
|
| 314 | + * @param string $cid The content-id (cid) of the attachment (default is false) |
|
| 315 | + * @return string The content-id (cid) of the attachment |
|
| 316 | + * @access public |
|
| 317 | + */ |
|
| 318 | 318 | public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
| 319 | 319 | if (! $cid) { |
| 320 | 320 | $cid = md5(uniqid(time())); |
@@ -331,35 +331,35 @@ discard block |
||
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
| 334 | - * clears the MIME attachments for the current response. |
|
| 335 | - * |
|
| 336 | - * @access public |
|
| 337 | - */ |
|
| 334 | + * clears the MIME attachments for the current response. |
|
| 335 | + * |
|
| 336 | + * @access public |
|
| 337 | + */ |
|
| 338 | 338 | public function clearAttachments() { |
| 339 | 339 | $this->responseAttachments = array(); |
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
| 343 | - * gets the MIME attachments from the current request. |
|
| 344 | - * |
|
| 345 | - * Each array element in the return is an associative array with keys |
|
| 346 | - * data, filename, contenttype, cid. These keys correspond to the parameters |
|
| 347 | - * for addAttachment. |
|
| 348 | - * |
|
| 349 | - * @return array The attachments. |
|
| 350 | - * @access public |
|
| 351 | - */ |
|
| 343 | + * gets the MIME attachments from the current request. |
|
| 344 | + * |
|
| 345 | + * Each array element in the return is an associative array with keys |
|
| 346 | + * data, filename, contenttype, cid. These keys correspond to the parameters |
|
| 347 | + * for addAttachment. |
|
| 348 | + * |
|
| 349 | + * @return array The attachments. |
|
| 350 | + * @access public |
|
| 351 | + */ |
|
| 352 | 352 | public function getAttachments() { |
| 353 | 353 | return $this->requestAttachments; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
| 357 | - * gets the HTTP body for the current response. |
|
| 358 | - * |
|
| 359 | - * @param string $soapmsg The SOAP payload |
|
| 360 | - * @return string The HTTP body, which includes the SOAP payload |
|
| 361 | - * @access private |
|
| 362 | - */ |
|
| 357 | + * gets the HTTP body for the current response. |
|
| 358 | + * |
|
| 359 | + * @param string $soapmsg The SOAP payload |
|
| 360 | + * @return string The HTTP body, which includes the SOAP payload |
|
| 361 | + * @access private |
|
| 362 | + */ |
|
| 363 | 363 | public function getHTTPBody($soapmsg) { |
| 364 | 364 | if (count($this->responseAttachments) > 0) { |
| 365 | 365 | $params['content_type'] = 'multipart/related; type="text/xml"'; |
@@ -412,13 +412,13 @@ discard block |
||
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
| 415 | - * gets the HTTP content type for the current response. |
|
| 416 | - * |
|
| 417 | - * Note: getHTTPBody must be called before this. |
|
| 418 | - * |
|
| 419 | - * @return string the HTTP content type for the current response. |
|
| 420 | - * @access private |
|
| 421 | - */ |
|
| 415 | + * gets the HTTP content type for the current response. |
|
| 416 | + * |
|
| 417 | + * Note: getHTTPBody must be called before this. |
|
| 418 | + * |
|
| 419 | + * @return string the HTTP content type for the current response. |
|
| 420 | + * @access private |
|
| 421 | + */ |
|
| 422 | 422 | public function getHTTPContentType() { |
| 423 | 423 | if (count($this->responseAttachments) > 0) { |
| 424 | 424 | return $this->mimeContentType; |
@@ -427,14 +427,14 @@ discard block |
||
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
| 430 | - * gets the HTTP content type charset for the current response. |
|
| 431 | - * returns false for non-text content types. |
|
| 432 | - * |
|
| 433 | - * Note: getHTTPBody must be called before this. |
|
| 434 | - * |
|
| 435 | - * @return string the HTTP content type charset for the current response. |
|
| 436 | - * @access private |
|
| 437 | - */ |
|
| 430 | + * gets the HTTP content type charset for the current response. |
|
| 431 | + * returns false for non-text content types. |
|
| 432 | + * |
|
| 433 | + * Note: getHTTPBody must be called before this. |
|
| 434 | + * |
|
| 435 | + * @return string the HTTP content type charset for the current response. |
|
| 436 | + * @access private |
|
| 437 | + */ |
|
| 438 | 438 | public function getHTTPContentTypeCharset() { |
| 439 | 439 | if (count($this->responseAttachments) > 0) { |
| 440 | 440 | return false; |
@@ -443,14 +443,14 @@ discard block |
||
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
| 446 | - * processes SOAP message received from client |
|
| 447 | - * |
|
| 448 | - * @param array $headers The HTTP headers |
|
| 449 | - * @param string $data unprocessed request data from client |
|
| 450 | - * @return mixed value of the message, decoded into a PHP type |
|
| 451 | - * @access private |
|
| 452 | - */ |
|
| 453 | - function parseRequest($headers, $data) { |
|
| 446 | + * processes SOAP message received from client |
|
| 447 | + * |
|
| 448 | + * @param array $headers The HTTP headers |
|
| 449 | + * @param string $data unprocessed request data from client |
|
| 450 | + * @return mixed value of the message, decoded into a PHP type |
|
| 451 | + * @access private |
|
| 452 | + */ |
|
| 453 | + function parseRequest($headers, $data) { |
|
| 454 | 454 | $this->debug('Entering parseRequest() for payload of length ' . strlen($data) . ' and type of ' . $headers['content-type']); |
| 455 | 455 | $this->requestAttachments = array(); |
| 456 | 456 | if (strstr($headers['content-type'], 'multipart/related')) { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @access public |
| 87 | 87 | */ |
| 88 | 88 | public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
| 89 | - if (! $cid) { |
|
| 89 | + if (!$cid) { |
|
| 90 | 90 | $cid = md5(uniqid(time())); |
| 91 | 91 | } |
| 92 | 92 | |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | * @access public |
| 317 | 317 | */ |
| 318 | 318 | public function addAttachment($data, $filename = '', $contenttype = 'application/octet-stream', $cid = false) { |
| 319 | - if (! $cid) { |
|
| 319 | + if (!$cid) { |
|
| 320 | 320 | $cid = md5(uniqid(time())); |
| 321 | 321 | } |
| 322 | 322 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * |
| 269 | 269 | * All the protected methods that do not start with _ (underscore) |
| 270 | 270 | * will exposed as protected api which will require authentication |
| 271 | - * @param string $class name of the service class |
|
| 272 | - * @param string $basePath optional url prefix for mapping, uses |
|
| 271 | + * @param string $base_path optional url prefix for mapping, uses |
|
| 273 | 272 | * lowercase version of the class name when not specified |
| 273 | + * @param string $class_name |
|
| 274 | 274 | * @throws Exception when supplied with invalid class name |
| 275 | 275 | */ |
| 276 | 276 | public function addAPIClass($class_name, $base_path = null) |
@@ -322,8 +322,8 @@ discard block |
||
| 322 | 322 | |
| 323 | 323 | /** |
| 324 | 324 | * Convenience method to respond with an error message |
| 325 | - * @param int $statusCode http error code |
|
| 326 | - * @param string $errorMessage optional custom error message |
|
| 325 | + * @param int $status_code http error code |
|
| 326 | + * @param string $error_message optional custom error message |
|
| 327 | 327 | */ |
| 328 | 328 | public function handleError($status_code, $error_message = null) |
| 329 | 329 | { |
@@ -916,6 +916,10 @@ discard block |
||
| 916 | 916 | { |
| 917 | 917 | |
| 918 | 918 | |
| 919 | + /** |
|
| 920 | + * @param integer $http_status_code |
|
| 921 | + * @param string $error_message |
|
| 922 | + */ |
|
| 919 | 923 | public function __construct($http_status_code, $error_message = null) |
| 920 | 924 | { |
| 921 | 925 | parent::__construct($error_message, $http_status_code); |
@@ -1033,12 +1037,14 @@ discard block |
||
| 1033 | 1037 | /** |
| 1034 | 1038 | * Set the selected MIME type |
| 1035 | 1039 | * @param string $mime MIME type |
| 1040 | + * @return void |
|
| 1036 | 1041 | */ |
| 1037 | 1042 | public function setMIME($mime); |
| 1038 | 1043 | |
| 1039 | 1044 | |
| 1040 | 1045 | /** |
| 1041 | 1046 | * Get selected MIME type |
| 1047 | + * @return string |
|
| 1042 | 1048 | */ |
| 1043 | 1049 | public function getMIME(); |
| 1044 | 1050 | |
@@ -1046,6 +1052,7 @@ discard block |
||
| 1046 | 1052 | /** |
| 1047 | 1053 | * Set the selected file extension |
| 1048 | 1054 | * @param string $extension file extension |
| 1055 | + * @return void |
|
| 1049 | 1056 | */ |
| 1050 | 1057 | public function setExtension($extension); |
| 1051 | 1058 | |
@@ -1349,6 +1356,9 @@ discard block |
||
| 1349 | 1356 | } |
| 1350 | 1357 | |
| 1351 | 1358 | |
| 1359 | + /** |
|
| 1360 | + * @param string[] $lines |
|
| 1361 | + */ |
|
| 1352 | 1362 | private function parseLines($lines) |
| 1353 | 1363 | { |
| 1354 | 1364 | foreach ($lines as $line) { |
@@ -1398,6 +1408,10 @@ discard block |
||
| 1398 | 1408 | } |
| 1399 | 1409 | |
| 1400 | 1410 | |
| 1411 | + /** |
|
| 1412 | + * @param string $param |
|
| 1413 | + * @param string $value |
|
| 1414 | + */ |
|
| 1401 | 1415 | private function setParam($param, $value) |
| 1402 | 1416 | { |
| 1403 | 1417 | if ($param == 'param' || $param == 'return') { |
@@ -1454,6 +1468,9 @@ discard block |
||
| 1454 | 1468 | // |
| 1455 | 1469 | // ------------------------------------------------------------------ |
| 1456 | 1470 | |
| 1471 | +/** |
|
| 1472 | + * @param string $php_doc_comment |
|
| 1473 | + */ |
|
| 1457 | 1474 | function parse_doc($php_doc_comment) |
| 1458 | 1475 | { |
| 1459 | 1476 | $p = new DocParser(); |
@@ -16,883 +16,883 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | class Restler |
| 18 | 18 | { |
| 19 | - // ================================================================== |
|
| 20 | - // |
|
| 21 | - // Public variables |
|
| 22 | - // |
|
| 23 | - // ------------------------------------------------------------------ |
|
| 24 | - |
|
| 25 | - const VERSION = '2.2.1'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * URL of the currently mapped service |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - public $url; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Http request method of the current request. |
|
| 35 | - * Any value between [GET, PUT, POST, DELETE] |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $request_method; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Requested data format. Instance of the current format class |
|
| 42 | - * which implements the iFormat interface |
|
| 43 | - * @var iFormat |
|
| 44 | - * @example jsonFormat, xmlFormat, yamlFormat etc |
|
| 45 | - */ |
|
| 46 | - public $request_format; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Data sent to the service |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - public $request_data = array(); |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Used in production mode to store the URL Map to disk |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - public $cache_dir; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * base directory to locate format and auth files |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - public $base_dir; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Name of an iRespond implementation class |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - public $response = 'DefaultResponse'; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Response data format. Instance of the current format class |
|
| 74 | - * which implements the iFormat interface |
|
| 75 | - * @var iFormat |
|
| 76 | - * @example jsonFormat, xmlFormat, yamlFormat etc |
|
| 77 | - */ |
|
| 78 | - public $response_format; |
|
| 79 | - |
|
| 80 | - // ================================================================== |
|
| 81 | - // |
|
| 82 | - // Private & Protected variables |
|
| 83 | - // |
|
| 84 | - // ------------------------------------------------------------------ |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * When set to false, it will run in debug mode and parse the |
|
| 88 | - * class files every time to map it to the URL |
|
| 89 | - * @var boolean |
|
| 90 | - */ |
|
| 91 | - protected $production_mode; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Associated array that maps urls to their respective class and method |
|
| 95 | - * @var array |
|
| 96 | - */ |
|
| 97 | - protected $routes = array(); |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Associated array that maps formats to their respective format class name |
|
| 101 | - * @var array |
|
| 102 | - */ |
|
| 103 | - protected $format_map = array(); |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Instance of the current api service class |
|
| 107 | - * @var object |
|
| 108 | - */ |
|
| 109 | - protected $service_class_instance; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Name of the api method being called |
|
| 113 | - * @var string |
|
| 114 | - */ |
|
| 115 | - protected $service_method; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * list of authentication classes |
|
| 119 | - * @var array |
|
| 120 | - */ |
|
| 121 | - protected $auth_classes = array(); |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * list of error handling classes |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - protected $error_classes = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * HTTP status codes |
|
| 131 | - * @var array |
|
| 132 | - */ |
|
| 133 | - private $codes = array( |
|
| 134 | - 100 => 'Continue', |
|
| 135 | - 101 => 'Switching Protocols', |
|
| 136 | - 200 => 'OK', |
|
| 137 | - 201 => 'Created', |
|
| 138 | - 202 => 'Accepted', |
|
| 139 | - 203 => 'Non-Authoritative Information', |
|
| 140 | - 204 => 'No Content', |
|
| 141 | - 205 => 'Reset Content', |
|
| 142 | - 206 => 'Partial Content', |
|
| 143 | - 300 => 'Multiple Choices', |
|
| 144 | - 301 => 'Moved Permanently', |
|
| 145 | - 302 => 'Found', |
|
| 146 | - 303 => 'See Other', |
|
| 147 | - 304 => 'Not Modified', |
|
| 148 | - 305 => 'Use Proxy', |
|
| 149 | - 306 => '(Unused)', |
|
| 150 | - 307 => 'Temporary Redirect', |
|
| 151 | - 400 => 'Bad Request', |
|
| 152 | - 401 => 'Unauthorized', |
|
| 153 | - 402 => 'Payment Required', |
|
| 154 | - 403 => 'Forbidden', |
|
| 155 | - 404 => 'Not Found', |
|
| 156 | - 405 => 'Method Not Allowed', |
|
| 157 | - 406 => 'Not Acceptable', |
|
| 158 | - 407 => 'Proxy Authentication Required', |
|
| 159 | - 408 => 'Request Timeout', |
|
| 160 | - 409 => 'Conflict', |
|
| 161 | - 410 => 'Gone', |
|
| 162 | - 411 => 'Length Required', |
|
| 163 | - 412 => 'Precondition Failed', |
|
| 164 | - 413 => 'Request Entity Too Large', |
|
| 165 | - 414 => 'Request-URI Too Long', |
|
| 166 | - 415 => 'Unsupported Media Type', |
|
| 167 | - 416 => 'Requested Range Not Satisfiable', |
|
| 168 | - 417 => 'Expectation Failed', |
|
| 169 | - 500 => 'Internal Server Error', |
|
| 170 | - 501 => 'Not Implemented', |
|
| 171 | - 502 => 'Bad Gateway', |
|
| 172 | - 503 => 'Service Unavailable', |
|
| 173 | - 504 => 'Gateway Timeout', |
|
| 174 | - 505 => 'HTTP Version Not Supported' |
|
| 175 | - ); |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Caching of url map is enabled or not |
|
| 179 | - * @var boolean |
|
| 180 | - */ |
|
| 181 | - protected $cached; |
|
| 182 | - |
|
| 183 | - // ================================================================== |
|
| 184 | - // |
|
| 185 | - // Public functions |
|
| 186 | - // |
|
| 187 | - // ------------------------------------------------------------------ |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Constructor |
|
| 192 | - * @param boolean $production_mode When set to false, it will run in |
|
| 193 | - * debug mode and parse the class files every time to map it to the URL |
|
| 194 | - */ |
|
| 195 | - public function __construct($production_mode = false) |
|
| 196 | - { |
|
| 197 | - $this->production_mode = $production_mode; |
|
| 198 | - $this->cache_dir = getcwd(); |
|
| 199 | - $this->base_dir = RESTLER_PATH; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Store the url map cache if needed |
|
| 205 | - */ |
|
| 206 | - public function __destruct() |
|
| 207 | - { |
|
| 208 | - if ($this->production_mode && !($this->cached)) { |
|
| 209 | - $this->saveCache(); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Use it in production mode to refresh the url map cache |
|
| 216 | - */ |
|
| 217 | - public function refreshCache() |
|
| 218 | - { |
|
| 219 | - $this->routes = array(); |
|
| 220 | - $this->cached = false; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Call this method and pass all the formats that should be |
|
| 226 | - * supported by the API. Accepts multiple parameters |
|
| 227 | - * @param string class name of the format class that implements iFormat |
|
| 228 | - * @example $restler->setSupportedFormats('JsonFormat', 'XmlFormat'...); |
|
| 229 | - */ |
|
| 230 | - public function setSupportedFormats() |
|
| 231 | - { |
|
| 232 | - $args = func_get_args(); |
|
| 233 | - $extensions = array(); |
|
| 234 | - foreach ($args as $class_name) { |
|
| 235 | - if (!is_string($class_name) || !class_exists($class_name)) { |
|
| 236 | - throw new Exception("$class_name is not a vaild Format Class."); |
|
| 237 | - } |
|
| 238 | - $obj = new $class_name; |
|
| 239 | - if (!($obj instanceof iFormat)) { |
|
| 240 | - throw new Exception('Invalid format class; must implement ' |
|
| 241 | - . 'iFormat interface'); |
|
| 242 | - } |
|
| 243 | - foreach ($obj->getMIMEMap() as $extension => $mime) { |
|
| 244 | - if (!isset($this->format_map[$extension])) { |
|
| 245 | - $this->format_map[$extension] = $class_name; |
|
| 246 | - } |
|
| 247 | - $mime = explode(',', $mime); |
|
| 248 | - if (!is_array($mime)) { |
|
| 249 | - $mime = array($mime); |
|
| 250 | - } |
|
| 251 | - foreach ($mime as $value) { |
|
| 252 | - if (!isset($this->format_map[$value])) { |
|
| 253 | - $this->format_map[$value] = $class_name; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - $extensions[".$extension"] = true; |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - $this->format_map['default'] = $args[0]; |
|
| 260 | - $this->format_map['extensions'] = array_keys($extensions); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Add api classes throgh this method. All the public methods |
|
| 266 | - * that do not start with _ (underscore) will be will be exposed |
|
| 267 | - * as the public api by default. |
|
| 268 | - * |
|
| 269 | - * All the protected methods that do not start with _ (underscore) |
|
| 270 | - * will exposed as protected api which will require authentication |
|
| 271 | - * @param string $class name of the service class |
|
| 272 | - * @param string $basePath optional url prefix for mapping, uses |
|
| 273 | - * lowercase version of the class name when not specified |
|
| 274 | - * @throws Exception when supplied with invalid class name |
|
| 275 | - */ |
|
| 276 | - public function addAPIClass($class_name, $base_path = null) |
|
| 277 | - { |
|
| 278 | - if (!class_exists($class_name)) { |
|
| 279 | - throw new Exception("API class $class_name is missing."); |
|
| 280 | - } |
|
| 281 | - $this->loadCache(); |
|
| 282 | - if (!$this->cached) { |
|
| 283 | - if (is_null($base_path)) { |
|
| 284 | - $base_path = strtolower($class_name); |
|
| 285 | - $index = strrpos($class_name, '\\'); |
|
| 286 | - if ($index !== false) { |
|
| 287 | - $base_path = substr($base_path, $index + 1); |
|
| 288 | - } |
|
| 289 | - } else { |
|
| 290 | - $base_path = trim($base_path, '/'); |
|
| 291 | - } |
|
| 292 | - if (strlen($base_path) > 0) { |
|
| 293 | - $base_path .= '/'; |
|
| 294 | - } |
|
| 295 | - $this->generateMap($class_name, $base_path); |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * protected methods will need atleast one authentication class to be set |
|
| 302 | - * in order to allow that method to be executed |
|
| 303 | - * @param string $class_name of the authentication class |
|
| 304 | - * @param string $base_path optional url prefix for mapping |
|
| 305 | - */ |
|
| 306 | - public function addAuthenticationClass($class_name, $base_path = null) |
|
| 307 | - { |
|
| 308 | - $this->auth_classes[] = $class_name; |
|
| 309 | - $this->addAPIClass($class_name, $base_path); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Add class for custom error handling |
|
| 315 | - * @param string $class_name of the error handling class |
|
| 316 | - */ |
|
| 317 | - public function addErrorClass($class_name) |
|
| 318 | - { |
|
| 319 | - $this->error_classes[] = $class_name; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * Convenience method to respond with an error message |
|
| 325 | - * @param int $statusCode http error code |
|
| 326 | - * @param string $errorMessage optional custom error message |
|
| 327 | - */ |
|
| 328 | - public function handleError($status_code, $error_message = null) |
|
| 329 | - { |
|
| 330 | - $method = "handle$status_code"; |
|
| 331 | - $handled = false; |
|
| 332 | - foreach ($this->error_classes as $class_name) { |
|
| 333 | - if (method_exists($class_name, $method)) { |
|
| 334 | - $obj = new $class_name(); |
|
| 335 | - $obj->restler = $this; |
|
| 336 | - $obj->$method(); |
|
| 337 | - $handled = true; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - if ($handled) { |
|
| 341 | - return; |
|
| 342 | - } |
|
| 343 | - $message = $this->codes[$status_code] |
|
| 344 | - . (!$error_message ? '' : ': ' . $error_message); |
|
| 345 | - $this->setStatus($status_code); |
|
| 346 | - $responder = new $this->response(); |
|
| 347 | - $responder->restler = $this; |
|
| 348 | - $this->sendData($responder->__formatError($status_code, $message)); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * An initialize function to allow use of the restler error generation |
|
| 354 | - * functions for pre-processing and pre-routing of requests. |
|
| 355 | - */ |
|
| 356 | - public function init() |
|
| 357 | - { |
|
| 358 | - if (empty($this->format_map)) { |
|
| 359 | - $this->setSupportedFormats('JsonFormat'); |
|
| 360 | - } |
|
| 361 | - $this->url = $this->getPath(); |
|
| 362 | - $this->request_method = $this->getRequestMethod(); |
|
| 363 | - $this->response_format = $this->getResponseFormat(); |
|
| 364 | - $this->request_format = $this->getRequestFormat(); |
|
| 365 | - if (is_null($this->request_format)) { |
|
| 366 | - $this->request_format = $this->response_format; |
|
| 367 | - } |
|
| 368 | - if ($this->request_method == 'PUT' || $this->request_method == 'POST') { |
|
| 369 | - $this->request_data = $this->getRequestData(); |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Main function for processing the api request |
|
| 376 | - * and return the response |
|
| 377 | - * @throws Exception when the api service class is missing |
|
| 378 | - * @throws RestException to send error response |
|
| 379 | - */ |
|
| 380 | - public function handle() |
|
| 381 | - { |
|
| 382 | - $this->init(); |
|
| 383 | - $o = $this->mapUrlToMethod(); |
|
| 384 | - |
|
| 385 | - if (!isset($o->class_name)) { |
|
| 386 | - $this->handleError(404); |
|
| 387 | - } else { |
|
| 388 | - try { |
|
| 389 | - if ($o->method_flag) { |
|
| 390 | - $auth_method = '__isAuthenticated'; |
|
| 391 | - if (!count($this->auth_classes)) { |
|
| 392 | - throw new RestException(401); |
|
| 393 | - } |
|
| 394 | - foreach ($this->auth_classes as $auth_class) { |
|
| 395 | - $auth_obj = new $auth_class(); |
|
| 396 | - $auth_obj->restler = $this; |
|
| 397 | - $this->applyClassMetadata($auth_class, $auth_obj, $o); |
|
| 398 | - if (!method_exists($auth_obj, $auth_method)) { |
|
| 399 | - throw new RestException(401, 'Authentication Class ' |
|
| 400 | - . 'should implement iAuthenticate'); |
|
| 401 | - } else if (!$auth_obj->$auth_method()) { |
|
| 402 | - throw new RestException(401); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - $this->applyClassMetadata(get_class($this->request_format), |
|
| 407 | - $this->request_format, $o); |
|
| 408 | - $pre_process = '_' . $this->request_format->getExtension() . '_' |
|
| 409 | - . $o->method_name; |
|
| 410 | - $this->service_method = $o->method_name; |
|
| 411 | - if ($o->method_flag == 2) { |
|
| 412 | - $o = unprotect($o); |
|
| 413 | - } |
|
| 414 | - $object = $this->service_class_instance = new $o->class_name(); |
|
| 415 | - $object->restler = $this; |
|
| 416 | - if (method_exists($o->class_name, $pre_process)) { |
|
| 417 | - call_user_func_array( |
|
| 418 | - array($object, $pre_process), $o->arguments |
|
| 419 | - ); |
|
| 420 | - } |
|
| 421 | - switch ($o->method_flag) { |
|
| 422 | - case 3: |
|
| 423 | - $reflection_method = new ReflectionMethod($object, |
|
| 424 | - $o->method_name); |
|
| 425 | - $reflection_method->setAccessible(true); |
|
| 426 | - $result = $reflection_method->invokeArgs($object, |
|
| 427 | - $o->arguments); |
|
| 428 | - break; |
|
| 429 | - case 2: |
|
| 430 | - case 1: |
|
| 431 | - default: |
|
| 432 | - $result = call_user_func_array(array( |
|
| 433 | - $object, |
|
| 434 | - $o->method_name), $o->arguments |
|
| 435 | - ); |
|
| 436 | - break; |
|
| 437 | - } |
|
| 438 | - } catch (RestException $e) { |
|
| 439 | - $this->handleError($e->getCode(), $e->getMessage()); |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - $responder = new $this->response(); |
|
| 443 | - $responder->restler = $this; |
|
| 444 | - $this->applyClassMetadata($this->response, $responder, $o); |
|
| 445 | - if (isset($result) && $result !== null) { |
|
| 446 | - $result = $responder->__formatResponse($result); |
|
| 447 | - $this->sendData($result); |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Encodes the response in the prefered format |
|
| 454 | - * and sends back |
|
| 455 | - * @param $data array php data |
|
| 456 | - */ |
|
| 457 | - public function sendData($data) |
|
| 458 | - { |
|
| 459 | - $data = $this->response_format->encode($data, |
|
| 460 | - !($this->production_mode) |
|
| 461 | - ); |
|
| 462 | - $post_process = '_' . $this->service_method . '_' |
|
| 463 | - . $this->response_format->getExtension(); |
|
| 464 | - if (isset($this->service_class_instance) |
|
| 465 | - && method_exists($this->service_class_instance, $post_process) |
|
| 466 | - ) { |
|
| 467 | - $data = call_user_func(array($this->service_class_instance, |
|
| 468 | - $post_process), $data); |
|
| 469 | - } |
|
| 470 | - header("Cache-Control: no-cache, must-revalidate"); |
|
| 471 | - header("Expires: 0"); |
|
| 472 | - header('Content-Type: ' . $this->response_format->getMIME()); |
|
| 473 | - //.'; charset=utf-8'); |
|
| 474 | - header("X-Powered-By: Luracast Restler v" . Restler::VERSION); |
|
| 19 | + // ================================================================== |
|
| 20 | + // |
|
| 21 | + // Public variables |
|
| 22 | + // |
|
| 23 | + // ------------------------------------------------------------------ |
|
| 24 | + |
|
| 25 | + const VERSION = '2.2.1'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * URL of the currently mapped service |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + public $url; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Http request method of the current request. |
|
| 35 | + * Any value between [GET, PUT, POST, DELETE] |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $request_method; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Requested data format. Instance of the current format class |
|
| 42 | + * which implements the iFormat interface |
|
| 43 | + * @var iFormat |
|
| 44 | + * @example jsonFormat, xmlFormat, yamlFormat etc |
|
| 45 | + */ |
|
| 46 | + public $request_format; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Data sent to the service |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + public $request_data = array(); |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Used in production mode to store the URL Map to disk |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + public $cache_dir; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * base directory to locate format and auth files |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + public $base_dir; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Name of an iRespond implementation class |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + public $response = 'DefaultResponse'; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Response data format. Instance of the current format class |
|
| 74 | + * which implements the iFormat interface |
|
| 75 | + * @var iFormat |
|
| 76 | + * @example jsonFormat, xmlFormat, yamlFormat etc |
|
| 77 | + */ |
|
| 78 | + public $response_format; |
|
| 79 | + |
|
| 80 | + // ================================================================== |
|
| 81 | + // |
|
| 82 | + // Private & Protected variables |
|
| 83 | + // |
|
| 84 | + // ------------------------------------------------------------------ |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * When set to false, it will run in debug mode and parse the |
|
| 88 | + * class files every time to map it to the URL |
|
| 89 | + * @var boolean |
|
| 90 | + */ |
|
| 91 | + protected $production_mode; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Associated array that maps urls to their respective class and method |
|
| 95 | + * @var array |
|
| 96 | + */ |
|
| 97 | + protected $routes = array(); |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Associated array that maps formats to their respective format class name |
|
| 101 | + * @var array |
|
| 102 | + */ |
|
| 103 | + protected $format_map = array(); |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Instance of the current api service class |
|
| 107 | + * @var object |
|
| 108 | + */ |
|
| 109 | + protected $service_class_instance; |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Name of the api method being called |
|
| 113 | + * @var string |
|
| 114 | + */ |
|
| 115 | + protected $service_method; |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * list of authentication classes |
|
| 119 | + * @var array |
|
| 120 | + */ |
|
| 121 | + protected $auth_classes = array(); |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * list of error handling classes |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + protected $error_classes = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * HTTP status codes |
|
| 131 | + * @var array |
|
| 132 | + */ |
|
| 133 | + private $codes = array( |
|
| 134 | + 100 => 'Continue', |
|
| 135 | + 101 => 'Switching Protocols', |
|
| 136 | + 200 => 'OK', |
|
| 137 | + 201 => 'Created', |
|
| 138 | + 202 => 'Accepted', |
|
| 139 | + 203 => 'Non-Authoritative Information', |
|
| 140 | + 204 => 'No Content', |
|
| 141 | + 205 => 'Reset Content', |
|
| 142 | + 206 => 'Partial Content', |
|
| 143 | + 300 => 'Multiple Choices', |
|
| 144 | + 301 => 'Moved Permanently', |
|
| 145 | + 302 => 'Found', |
|
| 146 | + 303 => 'See Other', |
|
| 147 | + 304 => 'Not Modified', |
|
| 148 | + 305 => 'Use Proxy', |
|
| 149 | + 306 => '(Unused)', |
|
| 150 | + 307 => 'Temporary Redirect', |
|
| 151 | + 400 => 'Bad Request', |
|
| 152 | + 401 => 'Unauthorized', |
|
| 153 | + 402 => 'Payment Required', |
|
| 154 | + 403 => 'Forbidden', |
|
| 155 | + 404 => 'Not Found', |
|
| 156 | + 405 => 'Method Not Allowed', |
|
| 157 | + 406 => 'Not Acceptable', |
|
| 158 | + 407 => 'Proxy Authentication Required', |
|
| 159 | + 408 => 'Request Timeout', |
|
| 160 | + 409 => 'Conflict', |
|
| 161 | + 410 => 'Gone', |
|
| 162 | + 411 => 'Length Required', |
|
| 163 | + 412 => 'Precondition Failed', |
|
| 164 | + 413 => 'Request Entity Too Large', |
|
| 165 | + 414 => 'Request-URI Too Long', |
|
| 166 | + 415 => 'Unsupported Media Type', |
|
| 167 | + 416 => 'Requested Range Not Satisfiable', |
|
| 168 | + 417 => 'Expectation Failed', |
|
| 169 | + 500 => 'Internal Server Error', |
|
| 170 | + 501 => 'Not Implemented', |
|
| 171 | + 502 => 'Bad Gateway', |
|
| 172 | + 503 => 'Service Unavailable', |
|
| 173 | + 504 => 'Gateway Timeout', |
|
| 174 | + 505 => 'HTTP Version Not Supported' |
|
| 175 | + ); |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Caching of url map is enabled or not |
|
| 179 | + * @var boolean |
|
| 180 | + */ |
|
| 181 | + protected $cached; |
|
| 182 | + |
|
| 183 | + // ================================================================== |
|
| 184 | + // |
|
| 185 | + // Public functions |
|
| 186 | + // |
|
| 187 | + // ------------------------------------------------------------------ |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Constructor |
|
| 192 | + * @param boolean $production_mode When set to false, it will run in |
|
| 193 | + * debug mode and parse the class files every time to map it to the URL |
|
| 194 | + */ |
|
| 195 | + public function __construct($production_mode = false) |
|
| 196 | + { |
|
| 197 | + $this->production_mode = $production_mode; |
|
| 198 | + $this->cache_dir = getcwd(); |
|
| 199 | + $this->base_dir = RESTLER_PATH; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Store the url map cache if needed |
|
| 205 | + */ |
|
| 206 | + public function __destruct() |
|
| 207 | + { |
|
| 208 | + if ($this->production_mode && !($this->cached)) { |
|
| 209 | + $this->saveCache(); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Use it in production mode to refresh the url map cache |
|
| 216 | + */ |
|
| 217 | + public function refreshCache() |
|
| 218 | + { |
|
| 219 | + $this->routes = array(); |
|
| 220 | + $this->cached = false; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Call this method and pass all the formats that should be |
|
| 226 | + * supported by the API. Accepts multiple parameters |
|
| 227 | + * @param string class name of the format class that implements iFormat |
|
| 228 | + * @example $restler->setSupportedFormats('JsonFormat', 'XmlFormat'...); |
|
| 229 | + */ |
|
| 230 | + public function setSupportedFormats() |
|
| 231 | + { |
|
| 232 | + $args = func_get_args(); |
|
| 233 | + $extensions = array(); |
|
| 234 | + foreach ($args as $class_name) { |
|
| 235 | + if (!is_string($class_name) || !class_exists($class_name)) { |
|
| 236 | + throw new Exception("$class_name is not a vaild Format Class."); |
|
| 237 | + } |
|
| 238 | + $obj = new $class_name; |
|
| 239 | + if (!($obj instanceof iFormat)) { |
|
| 240 | + throw new Exception('Invalid format class; must implement ' |
|
| 241 | + . 'iFormat interface'); |
|
| 242 | + } |
|
| 243 | + foreach ($obj->getMIMEMap() as $extension => $mime) { |
|
| 244 | + if (!isset($this->format_map[$extension])) { |
|
| 245 | + $this->format_map[$extension] = $class_name; |
|
| 246 | + } |
|
| 247 | + $mime = explode(',', $mime); |
|
| 248 | + if (!is_array($mime)) { |
|
| 249 | + $mime = array($mime); |
|
| 250 | + } |
|
| 251 | + foreach ($mime as $value) { |
|
| 252 | + if (!isset($this->format_map[$value])) { |
|
| 253 | + $this->format_map[$value] = $class_name; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + $extensions[".$extension"] = true; |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + $this->format_map['default'] = $args[0]; |
|
| 260 | + $this->format_map['extensions'] = array_keys($extensions); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Add api classes throgh this method. All the public methods |
|
| 266 | + * that do not start with _ (underscore) will be will be exposed |
|
| 267 | + * as the public api by default. |
|
| 268 | + * |
|
| 269 | + * All the protected methods that do not start with _ (underscore) |
|
| 270 | + * will exposed as protected api which will require authentication |
|
| 271 | + * @param string $class name of the service class |
|
| 272 | + * @param string $basePath optional url prefix for mapping, uses |
|
| 273 | + * lowercase version of the class name when not specified |
|
| 274 | + * @throws Exception when supplied with invalid class name |
|
| 275 | + */ |
|
| 276 | + public function addAPIClass($class_name, $base_path = null) |
|
| 277 | + { |
|
| 278 | + if (!class_exists($class_name)) { |
|
| 279 | + throw new Exception("API class $class_name is missing."); |
|
| 280 | + } |
|
| 281 | + $this->loadCache(); |
|
| 282 | + if (!$this->cached) { |
|
| 283 | + if (is_null($base_path)) { |
|
| 284 | + $base_path = strtolower($class_name); |
|
| 285 | + $index = strrpos($class_name, '\\'); |
|
| 286 | + if ($index !== false) { |
|
| 287 | + $base_path = substr($base_path, $index + 1); |
|
| 288 | + } |
|
| 289 | + } else { |
|
| 290 | + $base_path = trim($base_path, '/'); |
|
| 291 | + } |
|
| 292 | + if (strlen($base_path) > 0) { |
|
| 293 | + $base_path .= '/'; |
|
| 294 | + } |
|
| 295 | + $this->generateMap($class_name, $base_path); |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * protected methods will need atleast one authentication class to be set |
|
| 302 | + * in order to allow that method to be executed |
|
| 303 | + * @param string $class_name of the authentication class |
|
| 304 | + * @param string $base_path optional url prefix for mapping |
|
| 305 | + */ |
|
| 306 | + public function addAuthenticationClass($class_name, $base_path = null) |
|
| 307 | + { |
|
| 308 | + $this->auth_classes[] = $class_name; |
|
| 309 | + $this->addAPIClass($class_name, $base_path); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Add class for custom error handling |
|
| 315 | + * @param string $class_name of the error handling class |
|
| 316 | + */ |
|
| 317 | + public function addErrorClass($class_name) |
|
| 318 | + { |
|
| 319 | + $this->error_classes[] = $class_name; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * Convenience method to respond with an error message |
|
| 325 | + * @param int $statusCode http error code |
|
| 326 | + * @param string $errorMessage optional custom error message |
|
| 327 | + */ |
|
| 328 | + public function handleError($status_code, $error_message = null) |
|
| 329 | + { |
|
| 330 | + $method = "handle$status_code"; |
|
| 331 | + $handled = false; |
|
| 332 | + foreach ($this->error_classes as $class_name) { |
|
| 333 | + if (method_exists($class_name, $method)) { |
|
| 334 | + $obj = new $class_name(); |
|
| 335 | + $obj->restler = $this; |
|
| 336 | + $obj->$method(); |
|
| 337 | + $handled = true; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + if ($handled) { |
|
| 341 | + return; |
|
| 342 | + } |
|
| 343 | + $message = $this->codes[$status_code] |
|
| 344 | + . (!$error_message ? '' : ': ' . $error_message); |
|
| 345 | + $this->setStatus($status_code); |
|
| 346 | + $responder = new $this->response(); |
|
| 347 | + $responder->restler = $this; |
|
| 348 | + $this->sendData($responder->__formatError($status_code, $message)); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * An initialize function to allow use of the restler error generation |
|
| 354 | + * functions for pre-processing and pre-routing of requests. |
|
| 355 | + */ |
|
| 356 | + public function init() |
|
| 357 | + { |
|
| 358 | + if (empty($this->format_map)) { |
|
| 359 | + $this->setSupportedFormats('JsonFormat'); |
|
| 360 | + } |
|
| 361 | + $this->url = $this->getPath(); |
|
| 362 | + $this->request_method = $this->getRequestMethod(); |
|
| 363 | + $this->response_format = $this->getResponseFormat(); |
|
| 364 | + $this->request_format = $this->getRequestFormat(); |
|
| 365 | + if (is_null($this->request_format)) { |
|
| 366 | + $this->request_format = $this->response_format; |
|
| 367 | + } |
|
| 368 | + if ($this->request_method == 'PUT' || $this->request_method == 'POST') { |
|
| 369 | + $this->request_data = $this->getRequestData(); |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Main function for processing the api request |
|
| 376 | + * and return the response |
|
| 377 | + * @throws Exception when the api service class is missing |
|
| 378 | + * @throws RestException to send error response |
|
| 379 | + */ |
|
| 380 | + public function handle() |
|
| 381 | + { |
|
| 382 | + $this->init(); |
|
| 383 | + $o = $this->mapUrlToMethod(); |
|
| 384 | + |
|
| 385 | + if (!isset($o->class_name)) { |
|
| 386 | + $this->handleError(404); |
|
| 387 | + } else { |
|
| 388 | + try { |
|
| 389 | + if ($o->method_flag) { |
|
| 390 | + $auth_method = '__isAuthenticated'; |
|
| 391 | + if (!count($this->auth_classes)) { |
|
| 392 | + throw new RestException(401); |
|
| 393 | + } |
|
| 394 | + foreach ($this->auth_classes as $auth_class) { |
|
| 395 | + $auth_obj = new $auth_class(); |
|
| 396 | + $auth_obj->restler = $this; |
|
| 397 | + $this->applyClassMetadata($auth_class, $auth_obj, $o); |
|
| 398 | + if (!method_exists($auth_obj, $auth_method)) { |
|
| 399 | + throw new RestException(401, 'Authentication Class ' |
|
| 400 | + . 'should implement iAuthenticate'); |
|
| 401 | + } else if (!$auth_obj->$auth_method()) { |
|
| 402 | + throw new RestException(401); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + $this->applyClassMetadata(get_class($this->request_format), |
|
| 407 | + $this->request_format, $o); |
|
| 408 | + $pre_process = '_' . $this->request_format->getExtension() . '_' |
|
| 409 | + . $o->method_name; |
|
| 410 | + $this->service_method = $o->method_name; |
|
| 411 | + if ($o->method_flag == 2) { |
|
| 412 | + $o = unprotect($o); |
|
| 413 | + } |
|
| 414 | + $object = $this->service_class_instance = new $o->class_name(); |
|
| 415 | + $object->restler = $this; |
|
| 416 | + if (method_exists($o->class_name, $pre_process)) { |
|
| 417 | + call_user_func_array( |
|
| 418 | + array($object, $pre_process), $o->arguments |
|
| 419 | + ); |
|
| 420 | + } |
|
| 421 | + switch ($o->method_flag) { |
|
| 422 | + case 3: |
|
| 423 | + $reflection_method = new ReflectionMethod($object, |
|
| 424 | + $o->method_name); |
|
| 425 | + $reflection_method->setAccessible(true); |
|
| 426 | + $result = $reflection_method->invokeArgs($object, |
|
| 427 | + $o->arguments); |
|
| 428 | + break; |
|
| 429 | + case 2: |
|
| 430 | + case 1: |
|
| 431 | + default: |
|
| 432 | + $result = call_user_func_array(array( |
|
| 433 | + $object, |
|
| 434 | + $o->method_name), $o->arguments |
|
| 435 | + ); |
|
| 436 | + break; |
|
| 437 | + } |
|
| 438 | + } catch (RestException $e) { |
|
| 439 | + $this->handleError($e->getCode(), $e->getMessage()); |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + $responder = new $this->response(); |
|
| 443 | + $responder->restler = $this; |
|
| 444 | + $this->applyClassMetadata($this->response, $responder, $o); |
|
| 445 | + if (isset($result) && $result !== null) { |
|
| 446 | + $result = $responder->__formatResponse($result); |
|
| 447 | + $this->sendData($result); |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Encodes the response in the prefered format |
|
| 454 | + * and sends back |
|
| 455 | + * @param $data array php data |
|
| 456 | + */ |
|
| 457 | + public function sendData($data) |
|
| 458 | + { |
|
| 459 | + $data = $this->response_format->encode($data, |
|
| 460 | + !($this->production_mode) |
|
| 461 | + ); |
|
| 462 | + $post_process = '_' . $this->service_method . '_' |
|
| 463 | + . $this->response_format->getExtension(); |
|
| 464 | + if (isset($this->service_class_instance) |
|
| 465 | + && method_exists($this->service_class_instance, $post_process) |
|
| 466 | + ) { |
|
| 467 | + $data = call_user_func(array($this->service_class_instance, |
|
| 468 | + $post_process), $data); |
|
| 469 | + } |
|
| 470 | + header("Cache-Control: no-cache, must-revalidate"); |
|
| 471 | + header("Expires: 0"); |
|
| 472 | + header('Content-Type: ' . $this->response_format->getMIME()); |
|
| 473 | + //.'; charset=utf-8'); |
|
| 474 | + header("X-Powered-By: Luracast Restler v" . Restler::VERSION); |
|
| 475 | 475 | if($this->production_mode){ |
| 476 | 476 | die($data); |
| 477 | 477 | }else{ |
| 478 | 478 | echo $data; |
| 479 | 479 | } |
| 480 | - } |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Sets the HTTP response status |
|
| 485 | - * @param int $code response code |
|
| 486 | - */ |
|
| 487 | - public function setStatus($code) |
|
| 488 | - { |
|
| 489 | - header("{$_SERVER['SERVER_PROTOCOL']} $code " . |
|
| 490 | - $this->codes[strval($code)]); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Compare two strings and remove the common |
|
| 496 | - * sub string from the first string and return it |
|
| 497 | - * @param string $first |
|
| 498 | - * @param string $second |
|
| 499 | - * @param string $char optional, set it as |
|
| 500 | - * blank string for char by char comparison |
|
| 501 | - * @return string |
|
| 502 | - */ |
|
| 503 | - public function removeCommonPath($first, $second, $char = '/') |
|
| 504 | - { |
|
| 505 | - $first = explode($char, $first); |
|
| 506 | - $second = explode($char, $second); |
|
| 507 | - while (count($second)) { |
|
| 508 | - if ($first[0] == $second[0]) { |
|
| 509 | - array_shift($first); |
|
| 510 | - } else { |
|
| 511 | - break; |
|
| 512 | - } |
|
| 513 | - array_shift($second); |
|
| 514 | - } |
|
| 515 | - return implode($char, $first); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * Save cache to file |
|
| 521 | - */ |
|
| 522 | - public function saveCache() |
|
| 523 | - { |
|
| 524 | - $file = $this->cache_dir . '/routes.php'; |
|
| 525 | - $s = '$o=array();' . PHP_EOL; |
|
| 526 | - foreach ($this->routes as $key => $value) { |
|
| 527 | - $s .= PHP_EOL . PHP_EOL . PHP_EOL . |
|
| 528 | - "############### $key ###############" . PHP_EOL . PHP_EOL; |
|
| 529 | - $s .= '$o[\'' . $key . '\']=array();'; |
|
| 530 | - foreach ($value as $ke => $va) { |
|
| 531 | - $s .= PHP_EOL . PHP_EOL . "#==== $key $ke" . PHP_EOL . PHP_EOL; |
|
| 532 | - $s .= '$o[\'' . $key . '\'][\'' . $ke . '\']=' . str_replace( |
|
| 533 | - PHP_EOL, PHP_EOL . "\t", var_export($va, true) |
|
| 534 | - ) . ';'; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - $s .= PHP_EOL . 'return $o;'; |
|
| 538 | - $r = @file_put_contents($file, "<?php $s"); |
|
| 539 | - @chmod($file, 0777); |
|
| 540 | - if ($r === false) { |
|
| 541 | - throw new Exception( |
|
| 542 | - "The cache directory located at '$this->cache_dir' needs to " |
|
| 543 | - . "have the permissions set to read/write/execute for everyone" |
|
| 544 | - . " in order to save cache and improve performance."); |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // ================================================================== |
|
| 549 | - // |
|
| 550 | - // Protected functions |
|
| 551 | - // |
|
| 552 | - // ------------------------------------------------------------------ |
|
| 553 | - |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Parses the requst url and get the api path |
|
| 557 | - * @return string api path |
|
| 558 | - */ |
|
| 559 | - protected function getPath() |
|
| 560 | - { |
|
| 561 | - $path = urldecode($this->removeCommonPath($_SERVER['REQUEST_URI'], |
|
| 562 | - $_SERVER['SCRIPT_NAME'])); |
|
| 563 | - $path = preg_replace('/(\/*\?.*$)|(\/$)/', '', $path); |
|
| 564 | - $path = str_replace($this->format_map['extensions'], '', $path); |
|
| 565 | - return $path; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Parses the request to figure out the http request type |
|
| 571 | - * @return string which will be one of the following |
|
| 572 | - * [GET, POST, PUT, DELETE] |
|
| 573 | - * @example GET |
|
| 574 | - */ |
|
| 575 | - protected function getRequestMethod() |
|
| 576 | - { |
|
| 577 | - $method = $_SERVER['REQUEST_METHOD']; |
|
| 578 | - if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
|
| 579 | - $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; |
|
| 580 | - } |
|
| 581 | - //support for HEAD request |
|
| 582 | - if ($method == 'HEAD') { |
|
| 583 | - $method = 'GET'; |
|
| 584 | - } |
|
| 585 | - return $method; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Parses the request to figure out format of the request data |
|
| 591 | - * @return iFormat any class that implements iFormat |
|
| 592 | - * @example JsonFormat |
|
| 593 | - */ |
|
| 594 | - protected function getRequestFormat() |
|
| 595 | - { |
|
| 596 | - $format = null; |
|
| 597 | - //check if client has sent any information on request format |
|
| 598 | - if (isset($_SERVER['CONTENT_TYPE'])) { |
|
| 599 | - $mime = explode(';', $_SERVER['CONTENT_TYPE']); |
|
| 600 | - $mime = $mime[0]; |
|
| 601 | - if ($mime == UrlEncodedFormat::MIME) { |
|
| 602 | - $format = new UrlEncodedFormat(); |
|
| 603 | - } else { |
|
| 604 | - if (isset($this->format_map[$mime])) { |
|
| 605 | - $format = $this->format_map[$mime]; |
|
| 606 | - $format = is_string($format) ? new $format : $format; |
|
| 607 | - $format->setMIME($mime); |
|
| 608 | - } |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - return $format; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Parses the request to figure out the best format for response |
|
| 617 | - * @return iFormat any class that implements iFormat |
|
| 618 | - * @example JsonFormat |
|
| 619 | - */ |
|
| 620 | - protected function getResponseFormat() |
|
| 621 | - { |
|
| 622 | - //check if client has specified an extension |
|
| 623 | - /** |
|
| 624 | - * @var iFormat |
|
| 625 | - */ |
|
| 626 | - $format = null; |
|
| 627 | - $extensions = explode('.', |
|
| 628 | - parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); |
|
| 629 | - while ($extensions) { |
|
| 630 | - $extension = array_pop($extensions); |
|
| 631 | - $extension = explode('/', $extension); |
|
| 632 | - $extension = array_shift($extension); |
|
| 633 | - if ($extension && isset($this->format_map[$extension])) { |
|
| 634 | - $format = $this->format_map[$extension]; |
|
| 635 | - $format = is_string($format) ? new $format : $format; |
|
| 636 | - $format->setExtension($extension); |
|
| 637 | - //echo "Extension $extension"; |
|
| 638 | - return $format; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - //check if client has sent list of accepted data formats |
|
| 642 | - if (isset($_SERVER['HTTP_ACCEPT'])) { |
|
| 643 | - $acceptList = array(); |
|
| 644 | - $accepts = explode(',', strtolower($_SERVER['HTTP_ACCEPT'])); |
|
| 645 | - if (!is_array($accepts)) { |
|
| 646 | - $accepts = array($accepts); |
|
| 647 | - } |
|
| 648 | - foreach ($accepts as $pos => $accept) { |
|
| 649 | - $parts = explode(';q=', trim($accept)); |
|
| 650 | - $type = array_shift($parts); |
|
| 651 | - $quality = count($parts) ? |
|
| 652 | - floatval(array_shift($parts)) : |
|
| 653 | - (1000 - $pos) / 1000; |
|
| 654 | - $acceptList[$type] = $quality; |
|
| 655 | - } |
|
| 656 | - arsort($acceptList); |
|
| 657 | - foreach ($acceptList as $accept => $quality) { |
|
| 658 | - if (isset($this->format_map[$accept])) { |
|
| 659 | - $format = $this->format_map[$accept]; |
|
| 660 | - $format = is_string($format) ? new $format : $format; |
|
| 661 | - $format->setMIME($accept); |
|
| 662 | - //echo "MIME $accept"; |
|
| 663 | - // Tell cache content is based on Accept header |
|
| 664 | - header("Vary: Accept"); |
|
| 665 | - return $format; |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } else { |
|
| 669 | - // RFC 2616: If no Accept header field is |
|
| 670 | - // present, then it is assumed that the |
|
| 671 | - // client accepts all media types. |
|
| 672 | - $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 673 | - } |
|
| 674 | - if (strpos($_SERVER['HTTP_ACCEPT'], '*') !== false) { |
|
| 675 | - if (strpos($_SERVER['HTTP_ACCEPT'], 'application/*') !== false) { |
|
| 676 | - $format = new JsonFormat; |
|
| 677 | - } else if (strpos($_SERVER['HTTP_ACCEPT'], 'text/*') !== false) { |
|
| 678 | - $format = new XmlFormat; |
|
| 679 | - } else if (strpos($_SERVER['HTTP_ACCEPT'], '*/*') !== false) { |
|
| 680 | - $format = new $this->format_map['default']; |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - if (empty($format)) { |
|
| 684 | - // RFC 2616: If an Accept header field is present, and if the |
|
| 685 | - // server cannot send a response which is acceptable according to |
|
| 686 | - // the combined Accept field value, then the server SHOULD send |
|
| 687 | - // a 406 (not acceptable) response. |
|
| 688 | - header('HTTP/1.1 406 Not Acceptable'); |
|
| 689 | - die('406 Not Acceptable: The server was unable to ' . |
|
| 690 | - 'negotiate content for this request.'); |
|
| 691 | - } else { |
|
| 692 | - // Tell cache content is based ot Accept header |
|
| 693 | - header("Vary: Accept"); |
|
| 694 | - return $format; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * Parses the request data and returns it |
|
| 701 | - * @return array php data |
|
| 702 | - */ |
|
| 703 | - protected function getRequestData() |
|
| 704 | - { |
|
| 705 | - try { |
|
| 706 | - $r = file_get_contents('php://input'); |
|
| 707 | - if (is_null($r)) { |
|
| 708 | - return $_GET; |
|
| 709 | - } |
|
| 710 | - $r = $this->request_format->decode($r); |
|
| 711 | - return is_null($r) ? array() : $r; |
|
| 712 | - } catch (RestException $e) { |
|
| 713 | - $this->handleError($e->getCode(), $e->getMessage()); |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - |
|
| 718 | - protected function mapUrlToMethod() |
|
| 719 | - { |
|
| 720 | - if (!isset($this->routes[$this->request_method])) { |
|
| 721 | - return array(); |
|
| 722 | - } |
|
| 723 | - $urls = $this->routes[$this->request_method]; |
|
| 724 | - if (!$urls) { |
|
| 725 | - return array(); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - $found = false; |
|
| 729 | - $this->request_data += $_GET; |
|
| 730 | - $params = array('request_data' => $this->request_data); |
|
| 731 | - $params += $this->request_data; |
|
| 732 | - $lc = strtolower($this->url); |
|
| 733 | - foreach ($urls as $url => $call) { |
|
| 734 | - //echo PHP_EOL.$url.' = '.$this->url.PHP_EOL; |
|
| 735 | - $call = (object) $call; |
|
| 736 | - if (strstr($url, ':')) { |
|
| 737 | - $regex = preg_replace('/\\\:([^\/]+)/', '(?P<$1>[^/]+)', |
|
| 738 | - preg_quote($url)); |
|
| 739 | - if (preg_match(":^$regex$:i", $this->url, $matches)) { |
|
| 740 | - foreach ($matches as $arg => $match) { |
|
| 741 | - if (isset($call->arguments[$arg])) { |
|
| 742 | - //flog("$arg => $match $args[$arg]"); |
|
| 743 | - $params[$arg] = $match; |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - $found = true; |
|
| 747 | - break; |
|
| 748 | - } |
|
| 749 | - } else if ($url == $lc) { |
|
| 750 | - $found = true; |
|
| 751 | - break; |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - if ($found) { |
|
| 755 | - //echo PHP_EOL."Found $url "; |
|
| 756 | - //print_r($call); |
|
| 757 | - $p = $call->defaults; |
|
| 758 | - foreach ($call->arguments as $key => $value) { |
|
| 759 | - //echo "$key => $value \n"; |
|
| 760 | - if (isset($params[$key])) { |
|
| 761 | - $p[$value] = $params[$key]; |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - $call->arguments = $p; |
|
| 765 | - return $call; |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * Apply static and non-static properties defined in |
|
| 772 | - * the method information anotation |
|
| 773 | - * @param String $class_name |
|
| 774 | - * @param Object $instance instance of that class |
|
| 775 | - * @param Object $method_info method information and metadata |
|
| 776 | - */ |
|
| 777 | - protected function applyClassMetadata($class_name, $instance, $method_info) |
|
| 778 | - { |
|
| 779 | - if (isset($method_info->metadata[$class_name]) |
|
| 780 | - && is_array($method_info->metadata[$class_name]) |
|
| 781 | - ) { |
|
| 782 | - foreach ($method_info->metadata[$class_name] as |
|
| 783 | - $property => $value) { |
|
| 784 | - if (property_exists($class_name, $property)) { |
|
| 785 | - $reflection_property = |
|
| 786 | - new ReflectionProperty($class_name, $property); |
|
| 787 | - $reflection_property->setValue($instance, $value); |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - protected function loadCache() |
|
| 795 | - { |
|
| 796 | - if ($this->cached !== null) { |
|
| 797 | - return; |
|
| 798 | - } |
|
| 799 | - $file = $this->cache_dir . '/routes.php'; |
|
| 800 | - $this->cached = false; |
|
| 801 | - |
|
| 802 | - if ($this->production_mode) { |
|
| 803 | - if (file_exists($file)) { |
|
| 804 | - $routes = include($file); |
|
| 805 | - } |
|
| 806 | - if (isset($routes) && is_array($routes)) { |
|
| 807 | - $this->routes = $routes; |
|
| 808 | - $this->cached = true; |
|
| 809 | - } |
|
| 810 | - } else { |
|
| 811 | - //@unlink($this->cache_dir . "/$name.php"); |
|
| 812 | - } |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * Generates cachable url to method mapping |
|
| 818 | - * @param string $class_name |
|
| 819 | - * @param string $base_path |
|
| 820 | - */ |
|
| 821 | - protected function generateMap($class_name, $base_path = '') |
|
| 822 | - { |
|
| 823 | - $reflection = new ReflectionClass($class_name); |
|
| 824 | - $class_metadata = parse_doc($reflection->getDocComment()); |
|
| 825 | - $methods = $reflection->getMethods( |
|
| 826 | - ReflectionMethod::IS_PUBLIC + ReflectionMethod::IS_PROTECTED |
|
| 827 | - ); |
|
| 828 | - foreach ($methods as $method) { |
|
| 829 | - $doc = $method->getDocComment(); |
|
| 830 | - $arguments = array(); |
|
| 831 | - $defaults = array(); |
|
| 832 | - $metadata = $class_metadata + parse_doc($doc); |
|
| 833 | - $params = $method->getParameters(); |
|
| 834 | - $position = 0; |
|
| 835 | - foreach ($params as $param) { |
|
| 836 | - $arguments[$param->getName()] = $position; |
|
| 837 | - $defaults[$position] = $param->isDefaultValueAvailable() ? |
|
| 838 | - $param->getDefaultValue() : null; |
|
| 839 | - $position++; |
|
| 840 | - } |
|
| 841 | - $method_flag = $method->isProtected() ? |
|
| 842 | - (isRestlerCompatibilityModeEnabled() ? 2 : 3) : |
|
| 843 | - (isset($metadata['protected']) ? 1 : 0); |
|
| 844 | - |
|
| 845 | - //take note of the order |
|
| 846 | - $call = array( |
|
| 847 | - 'class_name' => $class_name, |
|
| 848 | - 'method_name' => $method->getName(), |
|
| 849 | - 'arguments' => $arguments, |
|
| 850 | - 'defaults' => $defaults, |
|
| 851 | - 'metadata' => $metadata, |
|
| 852 | - 'method_flag' => $method_flag |
|
| 853 | - ); |
|
| 854 | - $method_url = strtolower($method->getName()); |
|
| 855 | - if (preg_match_all( |
|
| 856 | - '/@url\s+(GET|POST|PUT|DELETE|HEAD|OPTIONS)[ \t]*\/?(\S*)/s', |
|
| 857 | - $doc, $matches, PREG_SET_ORDER) |
|
| 858 | - ) { |
|
| 859 | - foreach ($matches as $match) { |
|
| 860 | - $http_method = $match[1]; |
|
| 861 | - $url = rtrim($base_path . $match[2], '/'); |
|
| 862 | - $this->routes[$http_method][$url] = $call; |
|
| 863 | - } |
|
| 864 | - } elseif ($method_url[0] != '_') { |
|
| 865 | - //not prefixed with underscore |
|
| 866 | - // no configuration found so use convention |
|
| 867 | - if (preg_match_all('/^(GET|POST|PUT|DELETE|HEAD|OPTIONS)/i', |
|
| 868 | - $method_url, $matches) |
|
| 869 | - ) { |
|
| 870 | - $http_method = strtoupper($matches[0][0]); |
|
| 871 | - $method_url = substr($method_url, strlen($http_method)); |
|
| 872 | - } else { |
|
| 873 | - $http_method = 'GET'; |
|
| 874 | - } |
|
| 875 | - $url = $base_path |
|
| 876 | - . ($method_url == 'index' || $method_url == 'default' ? '' : |
|
| 877 | - $method_url); |
|
| 878 | - $url = rtrim($url, '/'); |
|
| 879 | - $this->routes[$http_method][$url] = $call; |
|
| 880 | - foreach ($params as $param) { |
|
| 881 | - if ($param->getName() == 'request_data') { |
|
| 882 | - break; |
|
| 883 | - } |
|
| 884 | - $url .= $url == '' ? ':' : '/:'; |
|
| 885 | - $url .= $param->getName(); |
|
| 886 | - $this->routes[$http_method][$url] = $call; |
|
| 887 | - } |
|
| 888 | - } |
|
| 889 | - } |
|
| 890 | - } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Sets the HTTP response status |
|
| 485 | + * @param int $code response code |
|
| 486 | + */ |
|
| 487 | + public function setStatus($code) |
|
| 488 | + { |
|
| 489 | + header("{$_SERVER['SERVER_PROTOCOL']} $code " . |
|
| 490 | + $this->codes[strval($code)]); |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * Compare two strings and remove the common |
|
| 496 | + * sub string from the first string and return it |
|
| 497 | + * @param string $first |
|
| 498 | + * @param string $second |
|
| 499 | + * @param string $char optional, set it as |
|
| 500 | + * blank string for char by char comparison |
|
| 501 | + * @return string |
|
| 502 | + */ |
|
| 503 | + public function removeCommonPath($first, $second, $char = '/') |
|
| 504 | + { |
|
| 505 | + $first = explode($char, $first); |
|
| 506 | + $second = explode($char, $second); |
|
| 507 | + while (count($second)) { |
|
| 508 | + if ($first[0] == $second[0]) { |
|
| 509 | + array_shift($first); |
|
| 510 | + } else { |
|
| 511 | + break; |
|
| 512 | + } |
|
| 513 | + array_shift($second); |
|
| 514 | + } |
|
| 515 | + return implode($char, $first); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * Save cache to file |
|
| 521 | + */ |
|
| 522 | + public function saveCache() |
|
| 523 | + { |
|
| 524 | + $file = $this->cache_dir . '/routes.php'; |
|
| 525 | + $s = '$o=array();' . PHP_EOL; |
|
| 526 | + foreach ($this->routes as $key => $value) { |
|
| 527 | + $s .= PHP_EOL . PHP_EOL . PHP_EOL . |
|
| 528 | + "############### $key ###############" . PHP_EOL . PHP_EOL; |
|
| 529 | + $s .= '$o[\'' . $key . '\']=array();'; |
|
| 530 | + foreach ($value as $ke => $va) { |
|
| 531 | + $s .= PHP_EOL . PHP_EOL . "#==== $key $ke" . PHP_EOL . PHP_EOL; |
|
| 532 | + $s .= '$o[\'' . $key . '\'][\'' . $ke . '\']=' . str_replace( |
|
| 533 | + PHP_EOL, PHP_EOL . "\t", var_export($va, true) |
|
| 534 | + ) . ';'; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + $s .= PHP_EOL . 'return $o;'; |
|
| 538 | + $r = @file_put_contents($file, "<?php $s"); |
|
| 539 | + @chmod($file, 0777); |
|
| 540 | + if ($r === false) { |
|
| 541 | + throw new Exception( |
|
| 542 | + "The cache directory located at '$this->cache_dir' needs to " |
|
| 543 | + . "have the permissions set to read/write/execute for everyone" |
|
| 544 | + . " in order to save cache and improve performance."); |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // ================================================================== |
|
| 549 | + // |
|
| 550 | + // Protected functions |
|
| 551 | + // |
|
| 552 | + // ------------------------------------------------------------------ |
|
| 553 | + |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Parses the requst url and get the api path |
|
| 557 | + * @return string api path |
|
| 558 | + */ |
|
| 559 | + protected function getPath() |
|
| 560 | + { |
|
| 561 | + $path = urldecode($this->removeCommonPath($_SERVER['REQUEST_URI'], |
|
| 562 | + $_SERVER['SCRIPT_NAME'])); |
|
| 563 | + $path = preg_replace('/(\/*\?.*$)|(\/$)/', '', $path); |
|
| 564 | + $path = str_replace($this->format_map['extensions'], '', $path); |
|
| 565 | + return $path; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Parses the request to figure out the http request type |
|
| 571 | + * @return string which will be one of the following |
|
| 572 | + * [GET, POST, PUT, DELETE] |
|
| 573 | + * @example GET |
|
| 574 | + */ |
|
| 575 | + protected function getRequestMethod() |
|
| 576 | + { |
|
| 577 | + $method = $_SERVER['REQUEST_METHOD']; |
|
| 578 | + if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { |
|
| 579 | + $method = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; |
|
| 580 | + } |
|
| 581 | + //support for HEAD request |
|
| 582 | + if ($method == 'HEAD') { |
|
| 583 | + $method = 'GET'; |
|
| 584 | + } |
|
| 585 | + return $method; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Parses the request to figure out format of the request data |
|
| 591 | + * @return iFormat any class that implements iFormat |
|
| 592 | + * @example JsonFormat |
|
| 593 | + */ |
|
| 594 | + protected function getRequestFormat() |
|
| 595 | + { |
|
| 596 | + $format = null; |
|
| 597 | + //check if client has sent any information on request format |
|
| 598 | + if (isset($_SERVER['CONTENT_TYPE'])) { |
|
| 599 | + $mime = explode(';', $_SERVER['CONTENT_TYPE']); |
|
| 600 | + $mime = $mime[0]; |
|
| 601 | + if ($mime == UrlEncodedFormat::MIME) { |
|
| 602 | + $format = new UrlEncodedFormat(); |
|
| 603 | + } else { |
|
| 604 | + if (isset($this->format_map[$mime])) { |
|
| 605 | + $format = $this->format_map[$mime]; |
|
| 606 | + $format = is_string($format) ? new $format : $format; |
|
| 607 | + $format->setMIME($mime); |
|
| 608 | + } |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + return $format; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Parses the request to figure out the best format for response |
|
| 617 | + * @return iFormat any class that implements iFormat |
|
| 618 | + * @example JsonFormat |
|
| 619 | + */ |
|
| 620 | + protected function getResponseFormat() |
|
| 621 | + { |
|
| 622 | + //check if client has specified an extension |
|
| 623 | + /** |
|
| 624 | + * @var iFormat |
|
| 625 | + */ |
|
| 626 | + $format = null; |
|
| 627 | + $extensions = explode('.', |
|
| 628 | + parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); |
|
| 629 | + while ($extensions) { |
|
| 630 | + $extension = array_pop($extensions); |
|
| 631 | + $extension = explode('/', $extension); |
|
| 632 | + $extension = array_shift($extension); |
|
| 633 | + if ($extension && isset($this->format_map[$extension])) { |
|
| 634 | + $format = $this->format_map[$extension]; |
|
| 635 | + $format = is_string($format) ? new $format : $format; |
|
| 636 | + $format->setExtension($extension); |
|
| 637 | + //echo "Extension $extension"; |
|
| 638 | + return $format; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + //check if client has sent list of accepted data formats |
|
| 642 | + if (isset($_SERVER['HTTP_ACCEPT'])) { |
|
| 643 | + $acceptList = array(); |
|
| 644 | + $accepts = explode(',', strtolower($_SERVER['HTTP_ACCEPT'])); |
|
| 645 | + if (!is_array($accepts)) { |
|
| 646 | + $accepts = array($accepts); |
|
| 647 | + } |
|
| 648 | + foreach ($accepts as $pos => $accept) { |
|
| 649 | + $parts = explode(';q=', trim($accept)); |
|
| 650 | + $type = array_shift($parts); |
|
| 651 | + $quality = count($parts) ? |
|
| 652 | + floatval(array_shift($parts)) : |
|
| 653 | + (1000 - $pos) / 1000; |
|
| 654 | + $acceptList[$type] = $quality; |
|
| 655 | + } |
|
| 656 | + arsort($acceptList); |
|
| 657 | + foreach ($acceptList as $accept => $quality) { |
|
| 658 | + if (isset($this->format_map[$accept])) { |
|
| 659 | + $format = $this->format_map[$accept]; |
|
| 660 | + $format = is_string($format) ? new $format : $format; |
|
| 661 | + $format->setMIME($accept); |
|
| 662 | + //echo "MIME $accept"; |
|
| 663 | + // Tell cache content is based on Accept header |
|
| 664 | + header("Vary: Accept"); |
|
| 665 | + return $format; |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } else { |
|
| 669 | + // RFC 2616: If no Accept header field is |
|
| 670 | + // present, then it is assumed that the |
|
| 671 | + // client accepts all media types. |
|
| 672 | + $_SERVER['HTTP_ACCEPT'] = '*/*'; |
|
| 673 | + } |
|
| 674 | + if (strpos($_SERVER['HTTP_ACCEPT'], '*') !== false) { |
|
| 675 | + if (strpos($_SERVER['HTTP_ACCEPT'], 'application/*') !== false) { |
|
| 676 | + $format = new JsonFormat; |
|
| 677 | + } else if (strpos($_SERVER['HTTP_ACCEPT'], 'text/*') !== false) { |
|
| 678 | + $format = new XmlFormat; |
|
| 679 | + } else if (strpos($_SERVER['HTTP_ACCEPT'], '*/*') !== false) { |
|
| 680 | + $format = new $this->format_map['default']; |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + if (empty($format)) { |
|
| 684 | + // RFC 2616: If an Accept header field is present, and if the |
|
| 685 | + // server cannot send a response which is acceptable according to |
|
| 686 | + // the combined Accept field value, then the server SHOULD send |
|
| 687 | + // a 406 (not acceptable) response. |
|
| 688 | + header('HTTP/1.1 406 Not Acceptable'); |
|
| 689 | + die('406 Not Acceptable: The server was unable to ' . |
|
| 690 | + 'negotiate content for this request.'); |
|
| 691 | + } else { |
|
| 692 | + // Tell cache content is based ot Accept header |
|
| 693 | + header("Vary: Accept"); |
|
| 694 | + return $format; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * Parses the request data and returns it |
|
| 701 | + * @return array php data |
|
| 702 | + */ |
|
| 703 | + protected function getRequestData() |
|
| 704 | + { |
|
| 705 | + try { |
|
| 706 | + $r = file_get_contents('php://input'); |
|
| 707 | + if (is_null($r)) { |
|
| 708 | + return $_GET; |
|
| 709 | + } |
|
| 710 | + $r = $this->request_format->decode($r); |
|
| 711 | + return is_null($r) ? array() : $r; |
|
| 712 | + } catch (RestException $e) { |
|
| 713 | + $this->handleError($e->getCode(), $e->getMessage()); |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + |
|
| 718 | + protected function mapUrlToMethod() |
|
| 719 | + { |
|
| 720 | + if (!isset($this->routes[$this->request_method])) { |
|
| 721 | + return array(); |
|
| 722 | + } |
|
| 723 | + $urls = $this->routes[$this->request_method]; |
|
| 724 | + if (!$urls) { |
|
| 725 | + return array(); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + $found = false; |
|
| 729 | + $this->request_data += $_GET; |
|
| 730 | + $params = array('request_data' => $this->request_data); |
|
| 731 | + $params += $this->request_data; |
|
| 732 | + $lc = strtolower($this->url); |
|
| 733 | + foreach ($urls as $url => $call) { |
|
| 734 | + //echo PHP_EOL.$url.' = '.$this->url.PHP_EOL; |
|
| 735 | + $call = (object) $call; |
|
| 736 | + if (strstr($url, ':')) { |
|
| 737 | + $regex = preg_replace('/\\\:([^\/]+)/', '(?P<$1>[^/]+)', |
|
| 738 | + preg_quote($url)); |
|
| 739 | + if (preg_match(":^$regex$:i", $this->url, $matches)) { |
|
| 740 | + foreach ($matches as $arg => $match) { |
|
| 741 | + if (isset($call->arguments[$arg])) { |
|
| 742 | + //flog("$arg => $match $args[$arg]"); |
|
| 743 | + $params[$arg] = $match; |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + $found = true; |
|
| 747 | + break; |
|
| 748 | + } |
|
| 749 | + } else if ($url == $lc) { |
|
| 750 | + $found = true; |
|
| 751 | + break; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + if ($found) { |
|
| 755 | + //echo PHP_EOL."Found $url "; |
|
| 756 | + //print_r($call); |
|
| 757 | + $p = $call->defaults; |
|
| 758 | + foreach ($call->arguments as $key => $value) { |
|
| 759 | + //echo "$key => $value \n"; |
|
| 760 | + if (isset($params[$key])) { |
|
| 761 | + $p[$value] = $params[$key]; |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + $call->arguments = $p; |
|
| 765 | + return $call; |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * Apply static and non-static properties defined in |
|
| 772 | + * the method information anotation |
|
| 773 | + * @param String $class_name |
|
| 774 | + * @param Object $instance instance of that class |
|
| 775 | + * @param Object $method_info method information and metadata |
|
| 776 | + */ |
|
| 777 | + protected function applyClassMetadata($class_name, $instance, $method_info) |
|
| 778 | + { |
|
| 779 | + if (isset($method_info->metadata[$class_name]) |
|
| 780 | + && is_array($method_info->metadata[$class_name]) |
|
| 781 | + ) { |
|
| 782 | + foreach ($method_info->metadata[$class_name] as |
|
| 783 | + $property => $value) { |
|
| 784 | + if (property_exists($class_name, $property)) { |
|
| 785 | + $reflection_property = |
|
| 786 | + new ReflectionProperty($class_name, $property); |
|
| 787 | + $reflection_property->setValue($instance, $value); |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + protected function loadCache() |
|
| 795 | + { |
|
| 796 | + if ($this->cached !== null) { |
|
| 797 | + return; |
|
| 798 | + } |
|
| 799 | + $file = $this->cache_dir . '/routes.php'; |
|
| 800 | + $this->cached = false; |
|
| 801 | + |
|
| 802 | + if ($this->production_mode) { |
|
| 803 | + if (file_exists($file)) { |
|
| 804 | + $routes = include($file); |
|
| 805 | + } |
|
| 806 | + if (isset($routes) && is_array($routes)) { |
|
| 807 | + $this->routes = $routes; |
|
| 808 | + $this->cached = true; |
|
| 809 | + } |
|
| 810 | + } else { |
|
| 811 | + //@unlink($this->cache_dir . "/$name.php"); |
|
| 812 | + } |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * Generates cachable url to method mapping |
|
| 818 | + * @param string $class_name |
|
| 819 | + * @param string $base_path |
|
| 820 | + */ |
|
| 821 | + protected function generateMap($class_name, $base_path = '') |
|
| 822 | + { |
|
| 823 | + $reflection = new ReflectionClass($class_name); |
|
| 824 | + $class_metadata = parse_doc($reflection->getDocComment()); |
|
| 825 | + $methods = $reflection->getMethods( |
|
| 826 | + ReflectionMethod::IS_PUBLIC + ReflectionMethod::IS_PROTECTED |
|
| 827 | + ); |
|
| 828 | + foreach ($methods as $method) { |
|
| 829 | + $doc = $method->getDocComment(); |
|
| 830 | + $arguments = array(); |
|
| 831 | + $defaults = array(); |
|
| 832 | + $metadata = $class_metadata + parse_doc($doc); |
|
| 833 | + $params = $method->getParameters(); |
|
| 834 | + $position = 0; |
|
| 835 | + foreach ($params as $param) { |
|
| 836 | + $arguments[$param->getName()] = $position; |
|
| 837 | + $defaults[$position] = $param->isDefaultValueAvailable() ? |
|
| 838 | + $param->getDefaultValue() : null; |
|
| 839 | + $position++; |
|
| 840 | + } |
|
| 841 | + $method_flag = $method->isProtected() ? |
|
| 842 | + (isRestlerCompatibilityModeEnabled() ? 2 : 3) : |
|
| 843 | + (isset($metadata['protected']) ? 1 : 0); |
|
| 844 | + |
|
| 845 | + //take note of the order |
|
| 846 | + $call = array( |
|
| 847 | + 'class_name' => $class_name, |
|
| 848 | + 'method_name' => $method->getName(), |
|
| 849 | + 'arguments' => $arguments, |
|
| 850 | + 'defaults' => $defaults, |
|
| 851 | + 'metadata' => $metadata, |
|
| 852 | + 'method_flag' => $method_flag |
|
| 853 | + ); |
|
| 854 | + $method_url = strtolower($method->getName()); |
|
| 855 | + if (preg_match_all( |
|
| 856 | + '/@url\s+(GET|POST|PUT|DELETE|HEAD|OPTIONS)[ \t]*\/?(\S*)/s', |
|
| 857 | + $doc, $matches, PREG_SET_ORDER) |
|
| 858 | + ) { |
|
| 859 | + foreach ($matches as $match) { |
|
| 860 | + $http_method = $match[1]; |
|
| 861 | + $url = rtrim($base_path . $match[2], '/'); |
|
| 862 | + $this->routes[$http_method][$url] = $call; |
|
| 863 | + } |
|
| 864 | + } elseif ($method_url[0] != '_') { |
|
| 865 | + //not prefixed with underscore |
|
| 866 | + // no configuration found so use convention |
|
| 867 | + if (preg_match_all('/^(GET|POST|PUT|DELETE|HEAD|OPTIONS)/i', |
|
| 868 | + $method_url, $matches) |
|
| 869 | + ) { |
|
| 870 | + $http_method = strtoupper($matches[0][0]); |
|
| 871 | + $method_url = substr($method_url, strlen($http_method)); |
|
| 872 | + } else { |
|
| 873 | + $http_method = 'GET'; |
|
| 874 | + } |
|
| 875 | + $url = $base_path |
|
| 876 | + . ($method_url == 'index' || $method_url == 'default' ? '' : |
|
| 877 | + $method_url); |
|
| 878 | + $url = rtrim($url, '/'); |
|
| 879 | + $this->routes[$http_method][$url] = $call; |
|
| 880 | + foreach ($params as $param) { |
|
| 881 | + if ($param->getName() == 'request_data') { |
|
| 882 | + break; |
|
| 883 | + } |
|
| 884 | + $url .= $url == '' ? ':' : '/:'; |
|
| 885 | + $url .= $param->getName(); |
|
| 886 | + $this->routes[$http_method][$url] = $call; |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | + } |
|
| 890 | + } |
|
| 891 | 891 | |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | 894 | if (version_compare(PHP_VERSION, '5.3.0') < 0) { |
| 895 | - require_once 'compat.php'; |
|
| 895 | + require_once 'compat.php'; |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | // ================================================================== |
@@ -916,10 +916,10 @@ discard block |
||
| 916 | 916 | { |
| 917 | 917 | |
| 918 | 918 | |
| 919 | - public function __construct($http_status_code, $error_message = null) |
|
| 920 | - { |
|
| 921 | - parent::__construct($error_message, $http_status_code); |
|
| 922 | - } |
|
| 919 | + public function __construct($http_status_code, $error_message = null) |
|
| 920 | + { |
|
| 921 | + parent::__construct($error_message, $http_status_code); |
|
| 922 | + } |
|
| 923 | 923 | |
| 924 | 924 | } |
| 925 | 925 | |
@@ -937,21 +937,21 @@ discard block |
||
| 937 | 937 | { |
| 938 | 938 | |
| 939 | 939 | |
| 940 | - /** |
|
| 941 | - * Result of an api call is passed to this method |
|
| 942 | - * to create a standard structure for the data |
|
| 943 | - * @param unknown_type $result can be a primitive or array or object |
|
| 944 | - */ |
|
| 945 | - public function __formatResponse($result); |
|
| 940 | + /** |
|
| 941 | + * Result of an api call is passed to this method |
|
| 942 | + * to create a standard structure for the data |
|
| 943 | + * @param unknown_type $result can be a primitive or array or object |
|
| 944 | + */ |
|
| 945 | + public function __formatResponse($result); |
|
| 946 | 946 | |
| 947 | 947 | |
| 948 | - /** |
|
| 949 | - * When the api call results in RestException this method |
|
| 950 | - * will be called to return the error message |
|
| 951 | - * @param int $status_code |
|
| 952 | - * @param String $message |
|
| 953 | - */ |
|
| 954 | - public function __formatError($status_code, $message); |
|
| 948 | + /** |
|
| 949 | + * When the api call results in RestException this method |
|
| 950 | + * will be called to return the error message |
|
| 951 | + * @param int $status_code |
|
| 952 | + * @param String $message |
|
| 953 | + */ |
|
| 954 | + public function __formatError($status_code, $message); |
|
| 955 | 955 | } |
| 956 | 956 | |
| 957 | 957 | /** |
@@ -968,21 +968,21 @@ discard block |
||
| 968 | 968 | { |
| 969 | 969 | |
| 970 | 970 | |
| 971 | - function __formatResponse($result) |
|
| 972 | - { |
|
| 973 | - return $result; |
|
| 974 | - } |
|
| 971 | + function __formatResponse($result) |
|
| 972 | + { |
|
| 973 | + return $result; |
|
| 974 | + } |
|
| 975 | 975 | |
| 976 | 976 | |
| 977 | - function __formatError($statusCode, $message) |
|
| 978 | - { |
|
| 979 | - return array( |
|
| 980 | - 'error' => array( |
|
| 981 | - 'code' => $statusCode, |
|
| 982 | - 'message' => $message |
|
| 983 | - ) |
|
| 984 | - ); |
|
| 985 | - } |
|
| 977 | + function __formatError($statusCode, $message) |
|
| 978 | + { |
|
| 979 | + return array( |
|
| 980 | + 'error' => array( |
|
| 981 | + 'code' => $statusCode, |
|
| 982 | + 'message' => $message |
|
| 983 | + ) |
|
| 984 | + ); |
|
| 985 | + } |
|
| 986 | 986 | |
| 987 | 987 | } |
| 988 | 988 | |
@@ -1000,11 +1000,11 @@ discard block |
||
| 1000 | 1000 | { |
| 1001 | 1001 | |
| 1002 | 1002 | |
| 1003 | - /** |
|
| 1004 | - * Auth function that is called when a protected method is requested |
|
| 1005 | - * @return boolean true or false |
|
| 1006 | - */ |
|
| 1007 | - public function __isAuthenticated(); |
|
| 1003 | + /** |
|
| 1004 | + * Auth function that is called when a protected method is requested |
|
| 1005 | + * @return boolean true or false |
|
| 1006 | + */ |
|
| 1007 | + public function __isAuthenticated(); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1022,60 +1022,60 @@ discard block |
||
| 1022 | 1022 | { |
| 1023 | 1023 | |
| 1024 | 1024 | |
| 1025 | - /** |
|
| 1026 | - * Get Extension => MIME type mappings as an associative array |
|
| 1027 | - * @return array list of mime strings for the format |
|
| 1028 | - * @example array('json'=>'application/json'); |
|
| 1029 | - */ |
|
| 1030 | - public function getMIMEMap(); |
|
| 1025 | + /** |
|
| 1026 | + * Get Extension => MIME type mappings as an associative array |
|
| 1027 | + * @return array list of mime strings for the format |
|
| 1028 | + * @example array('json'=>'application/json'); |
|
| 1029 | + */ |
|
| 1030 | + public function getMIMEMap(); |
|
| 1031 | 1031 | |
| 1032 | 1032 | |
| 1033 | - /** |
|
| 1034 | - * Set the selected MIME type |
|
| 1035 | - * @param string $mime MIME type |
|
| 1036 | - */ |
|
| 1037 | - public function setMIME($mime); |
|
| 1033 | + /** |
|
| 1034 | + * Set the selected MIME type |
|
| 1035 | + * @param string $mime MIME type |
|
| 1036 | + */ |
|
| 1037 | + public function setMIME($mime); |
|
| 1038 | 1038 | |
| 1039 | 1039 | |
| 1040 | - /** |
|
| 1041 | - * Get selected MIME type |
|
| 1042 | - */ |
|
| 1043 | - public function getMIME(); |
|
| 1040 | + /** |
|
| 1041 | + * Get selected MIME type |
|
| 1042 | + */ |
|
| 1043 | + public function getMIME(); |
|
| 1044 | 1044 | |
| 1045 | 1045 | |
| 1046 | - /** |
|
| 1047 | - * Set the selected file extension |
|
| 1048 | - * @param string $extension file extension |
|
| 1049 | - */ |
|
| 1050 | - public function setExtension($extension); |
|
| 1046 | + /** |
|
| 1047 | + * Set the selected file extension |
|
| 1048 | + * @param string $extension file extension |
|
| 1049 | + */ |
|
| 1050 | + public function setExtension($extension); |
|
| 1051 | 1051 | |
| 1052 | 1052 | |
| 1053 | - /** |
|
| 1054 | - * Get the selected file extension |
|
| 1055 | - * @return string file extension |
|
| 1056 | - */ |
|
| 1057 | - public function getExtension(); |
|
| 1053 | + /** |
|
| 1054 | + * Get the selected file extension |
|
| 1055 | + * @return string file extension |
|
| 1056 | + */ |
|
| 1057 | + public function getExtension(); |
|
| 1058 | 1058 | |
| 1059 | 1059 | |
| 1060 | - /** |
|
| 1061 | - * Encode the given data in the format |
|
| 1062 | - * @param array $data resulting data that needs to |
|
| 1063 | - * be encoded in the given format |
|
| 1064 | - * @param boolean $human_readable set to true when restler |
|
| 1065 | - * is not running in production mode. Formatter has to |
|
| 1066 | - * make the encoded output more human readable |
|
| 1067 | - * @return string encoded string |
|
| 1068 | - */ |
|
| 1069 | - public function encode($data, $human_readable = false); |
|
| 1060 | + /** |
|
| 1061 | + * Encode the given data in the format |
|
| 1062 | + * @param array $data resulting data that needs to |
|
| 1063 | + * be encoded in the given format |
|
| 1064 | + * @param boolean $human_readable set to true when restler |
|
| 1065 | + * is not running in production mode. Formatter has to |
|
| 1066 | + * make the encoded output more human readable |
|
| 1067 | + * @return string encoded string |
|
| 1068 | + */ |
|
| 1069 | + public function encode($data, $human_readable = false); |
|
| 1070 | 1070 | |
| 1071 | 1071 | |
| 1072 | - /** |
|
| 1073 | - * Decode the given data from the format |
|
| 1074 | - * @param string $data data sent from client to |
|
| 1075 | - * the api in the given format. |
|
| 1076 | - * @return array associative array of the parsed data |
|
| 1077 | - */ |
|
| 1078 | - public function decode($data); |
|
| 1072 | + /** |
|
| 1073 | + * Decode the given data from the format |
|
| 1074 | + * @param string $data data sent from client to |
|
| 1075 | + * the api in the given format. |
|
| 1076 | + * @return array associative array of the parsed data |
|
| 1077 | + */ |
|
| 1078 | + public function decode($data); |
|
| 1079 | 1079 | } |
| 1080 | 1080 | |
| 1081 | 1081 | /** |
@@ -1091,57 +1091,57 @@ discard block |
||
| 1091 | 1091 | class UrlEncodedFormat implements iFormat |
| 1092 | 1092 | { |
| 1093 | 1093 | |
| 1094 | - const MIME = 'application/x-www-form-urlencoded'; |
|
| 1095 | - const EXTENSION = 'post'; |
|
| 1094 | + const MIME = 'application/x-www-form-urlencoded'; |
|
| 1095 | + const EXTENSION = 'post'; |
|
| 1096 | 1096 | |
| 1097 | 1097 | |
| 1098 | - public function getMIMEMap() |
|
| 1099 | - { |
|
| 1100 | - return array(self::EXTENSION => self::MIME); |
|
| 1101 | - } |
|
| 1098 | + public function getMIMEMap() |
|
| 1099 | + { |
|
| 1100 | + return array(self::EXTENSION => self::MIME); |
|
| 1101 | + } |
|
| 1102 | 1102 | |
| 1103 | 1103 | |
| 1104 | - public function getMIME() |
|
| 1105 | - { |
|
| 1106 | - return self::MIME; |
|
| 1107 | - } |
|
| 1104 | + public function getMIME() |
|
| 1105 | + { |
|
| 1106 | + return self::MIME; |
|
| 1107 | + } |
|
| 1108 | 1108 | |
| 1109 | 1109 | |
| 1110 | - public function getExtension() |
|
| 1111 | - { |
|
| 1112 | - return self::EXTENSION; |
|
| 1113 | - } |
|
| 1110 | + public function getExtension() |
|
| 1111 | + { |
|
| 1112 | + return self::EXTENSION; |
|
| 1113 | + } |
|
| 1114 | 1114 | |
| 1115 | 1115 | |
| 1116 | - public function setMIME($mime) |
|
| 1117 | - { |
|
| 1118 | - //do nothing |
|
| 1119 | - } |
|
| 1116 | + public function setMIME($mime) |
|
| 1117 | + { |
|
| 1118 | + //do nothing |
|
| 1119 | + } |
|
| 1120 | 1120 | |
| 1121 | 1121 | |
| 1122 | - public function setExtension($extension) |
|
| 1123 | - { |
|
| 1124 | - //do nothing |
|
| 1125 | - } |
|
| 1122 | + public function setExtension($extension) |
|
| 1123 | + { |
|
| 1124 | + //do nothing |
|
| 1125 | + } |
|
| 1126 | 1126 | |
| 1127 | 1127 | |
| 1128 | - public function encode($data, $human_readable = false) |
|
| 1129 | - { |
|
| 1130 | - return http_build_query($data); |
|
| 1131 | - } |
|
| 1128 | + public function encode($data, $human_readable = false) |
|
| 1129 | + { |
|
| 1130 | + return http_build_query($data); |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | 1133 | |
| 1134 | - public function decode($data) |
|
| 1135 | - { |
|
| 1136 | - parse_str($data, $r); |
|
| 1137 | - return $r; |
|
| 1138 | - } |
|
| 1134 | + public function decode($data) |
|
| 1135 | + { |
|
| 1136 | + parse_str($data, $r); |
|
| 1137 | + return $r; |
|
| 1138 | + } |
|
| 1139 | 1139 | |
| 1140 | 1140 | |
| 1141 | - public function __toString() |
|
| 1142 | - { |
|
| 1143 | - return $this->getExtension(); |
|
| 1144 | - } |
|
| 1141 | + public function __toString() |
|
| 1142 | + { |
|
| 1143 | + return $this->getExtension(); |
|
| 1144 | + } |
|
| 1145 | 1145 | |
| 1146 | 1146 | } |
| 1147 | 1147 | |
@@ -1158,158 +1158,158 @@ discard block |
||
| 1158 | 1158 | class JsonFormat implements iFormat |
| 1159 | 1159 | { |
| 1160 | 1160 | |
| 1161 | - const MIME = 'application/json,application/javascript'; |
|
| 1162 | - |
|
| 1163 | - static $mime = 'application/json'; |
|
| 1164 | - |
|
| 1165 | - const EXTENSION = 'json'; |
|
| 1166 | - |
|
| 1167 | - |
|
| 1168 | - public function getMIMEMap() |
|
| 1169 | - { |
|
| 1170 | - return array(self::EXTENSION => self::MIME); |
|
| 1171 | - } |
|
| 1172 | - |
|
| 1173 | - |
|
| 1174 | - public function getMIME() |
|
| 1175 | - { |
|
| 1176 | - return self::$mime; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - |
|
| 1180 | - public function getExtension() |
|
| 1181 | - { |
|
| 1182 | - return self::EXTENSION; |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - |
|
| 1186 | - public function setMIME($mime) |
|
| 1187 | - { |
|
| 1188 | - self::$mime = $mime; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - public function setExtension($extension) |
|
| 1193 | - { |
|
| 1194 | - //do nothing |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - |
|
| 1198 | - public function encode($data, $human_readable = false) |
|
| 1199 | - { |
|
| 1200 | - return $human_readable ? |
|
| 1201 | - $this->json_format(json_encode(object_to_array($data))) : |
|
| 1202 | - json_encode(object_to_array($data)); |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - |
|
| 1206 | - public function decode($data) |
|
| 1207 | - { |
|
| 1208 | - $decoded = json_decode($data); |
|
| 1209 | - if (function_exists('json_last_error')) { |
|
| 1210 | - $message = ''; |
|
| 1211 | - switch (json_last_error()) { |
|
| 1212 | - case JSON_ERROR_NONE: |
|
| 1213 | - return object_to_array($decoded); |
|
| 1214 | - break; |
|
| 1215 | - case JSON_ERROR_DEPTH: |
|
| 1216 | - $message = 'maximum stack depth exceeded'; |
|
| 1217 | - break; |
|
| 1218 | - case JSON_ERROR_STATE_MISMATCH: |
|
| 1219 | - $message = 'underflow or the modes mismatch'; |
|
| 1220 | - break; |
|
| 1221 | - case JSON_ERROR_CTRL_CHAR: |
|
| 1222 | - $message = 'unexpected control character found'; |
|
| 1223 | - break; |
|
| 1224 | - case JSON_ERROR_SYNTAX: |
|
| 1225 | - $message = 'malformed JSON'; |
|
| 1226 | - break; |
|
| 1227 | - case JSON_ERROR_UTF8: |
|
| 1228 | - $message = 'malformed UTF-8 characters, '. |
|
| 1229 | - 'possibly incorrectly encoded'; |
|
| 1230 | - break; |
|
| 1231 | - default: |
|
| 1232 | - $message = 'unknown error'; |
|
| 1233 | - break; |
|
| 1234 | - } |
|
| 1235 | - throw new RestException(400, 'Error parsing JSON, ' . $message); |
|
| 1236 | - } else if (strlen($data) && $decoded === null || $decoded === $data) { |
|
| 1237 | - throw new RestException(400, 'Error parsing JSON'); |
|
| 1238 | - } |
|
| 1239 | - return object_to_array($decoded); |
|
| 1240 | - } |
|
| 1241 | - |
|
| 1242 | - |
|
| 1243 | - /** |
|
| 1244 | - * Pretty print JSON string |
|
| 1245 | - * @param string $json |
|
| 1246 | - * @return string formated json |
|
| 1247 | - */ |
|
| 1248 | - private function json_format($json) |
|
| 1249 | - { |
|
| 1250 | - $tab = " "; |
|
| 1251 | - $new_json = ""; |
|
| 1252 | - $indent_level = 0; |
|
| 1253 | - $in_string = false; |
|
| 1254 | - $len = strlen($json); |
|
| 1255 | - |
|
| 1256 | - for ($c = 0; $c < $len; $c++) { |
|
| 1257 | - $char = $json[$c]; |
|
| 1258 | - switch ($char) { |
|
| 1259 | - case '{': |
|
| 1260 | - case '[': |
|
| 1261 | - if (!$in_string) { |
|
| 1262 | - $new_json .= $char . "\n" . |
|
| 1263 | - str_repeat($tab, $indent_level + 1); |
|
| 1264 | - $indent_level++; |
|
| 1265 | - } else { |
|
| 1266 | - $new_json .= $char; |
|
| 1267 | - } |
|
| 1268 | - break; |
|
| 1269 | - case '}': |
|
| 1270 | - case ']': |
|
| 1271 | - if (!$in_string) { |
|
| 1272 | - $indent_level--; |
|
| 1273 | - $new_json .= "\n" . str_repeat($tab, $indent_level) |
|
| 1274 | - . $char; |
|
| 1275 | - } else { |
|
| 1276 | - $new_json .= $char; |
|
| 1277 | - } |
|
| 1278 | - break; |
|
| 1279 | - case ',': |
|
| 1280 | - if (!$in_string) { |
|
| 1281 | - $new_json .= ",\n" . str_repeat($tab, $indent_level); |
|
| 1282 | - } else { |
|
| 1283 | - $new_json .= $char; |
|
| 1284 | - } |
|
| 1285 | - break; |
|
| 1286 | - case ':': |
|
| 1287 | - if (!$in_string) { |
|
| 1288 | - $new_json .= ": "; |
|
| 1289 | - } else { |
|
| 1290 | - $new_json .= $char; |
|
| 1291 | - } |
|
| 1292 | - break; |
|
| 1293 | - case '"': |
|
| 1294 | - if ($c == 0) { |
|
| 1295 | - $in_string = true; |
|
| 1296 | - } else if ($c > 0 && $json[$c - 1] != '\\') { |
|
| 1297 | - $in_string = !$in_string; |
|
| 1298 | - } |
|
| 1299 | - default: |
|
| 1300 | - $new_json .= $char; |
|
| 1301 | - break; |
|
| 1302 | - } |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - return $new_json; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - public function __toString() |
|
| 1310 | - { |
|
| 1311 | - return $this->getExtension(); |
|
| 1312 | - } |
|
| 1161 | + const MIME = 'application/json,application/javascript'; |
|
| 1162 | + |
|
| 1163 | + static $mime = 'application/json'; |
|
| 1164 | + |
|
| 1165 | + const EXTENSION = 'json'; |
|
| 1166 | + |
|
| 1167 | + |
|
| 1168 | + public function getMIMEMap() |
|
| 1169 | + { |
|
| 1170 | + return array(self::EXTENSION => self::MIME); |
|
| 1171 | + } |
|
| 1172 | + |
|
| 1173 | + |
|
| 1174 | + public function getMIME() |
|
| 1175 | + { |
|
| 1176 | + return self::$mime; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + |
|
| 1180 | + public function getExtension() |
|
| 1181 | + { |
|
| 1182 | + return self::EXTENSION; |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + |
|
| 1186 | + public function setMIME($mime) |
|
| 1187 | + { |
|
| 1188 | + self::$mime = $mime; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + public function setExtension($extension) |
|
| 1193 | + { |
|
| 1194 | + //do nothing |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + |
|
| 1198 | + public function encode($data, $human_readable = false) |
|
| 1199 | + { |
|
| 1200 | + return $human_readable ? |
|
| 1201 | + $this->json_format(json_encode(object_to_array($data))) : |
|
| 1202 | + json_encode(object_to_array($data)); |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + |
|
| 1206 | + public function decode($data) |
|
| 1207 | + { |
|
| 1208 | + $decoded = json_decode($data); |
|
| 1209 | + if (function_exists('json_last_error')) { |
|
| 1210 | + $message = ''; |
|
| 1211 | + switch (json_last_error()) { |
|
| 1212 | + case JSON_ERROR_NONE: |
|
| 1213 | + return object_to_array($decoded); |
|
| 1214 | + break; |
|
| 1215 | + case JSON_ERROR_DEPTH: |
|
| 1216 | + $message = 'maximum stack depth exceeded'; |
|
| 1217 | + break; |
|
| 1218 | + case JSON_ERROR_STATE_MISMATCH: |
|
| 1219 | + $message = 'underflow or the modes mismatch'; |
|
| 1220 | + break; |
|
| 1221 | + case JSON_ERROR_CTRL_CHAR: |
|
| 1222 | + $message = 'unexpected control character found'; |
|
| 1223 | + break; |
|
| 1224 | + case JSON_ERROR_SYNTAX: |
|
| 1225 | + $message = 'malformed JSON'; |
|
| 1226 | + break; |
|
| 1227 | + case JSON_ERROR_UTF8: |
|
| 1228 | + $message = 'malformed UTF-8 characters, '. |
|
| 1229 | + 'possibly incorrectly encoded'; |
|
| 1230 | + break; |
|
| 1231 | + default: |
|
| 1232 | + $message = 'unknown error'; |
|
| 1233 | + break; |
|
| 1234 | + } |
|
| 1235 | + throw new RestException(400, 'Error parsing JSON, ' . $message); |
|
| 1236 | + } else if (strlen($data) && $decoded === null || $decoded === $data) { |
|
| 1237 | + throw new RestException(400, 'Error parsing JSON'); |
|
| 1238 | + } |
|
| 1239 | + return object_to_array($decoded); |
|
| 1240 | + } |
|
| 1241 | + |
|
| 1242 | + |
|
| 1243 | + /** |
|
| 1244 | + * Pretty print JSON string |
|
| 1245 | + * @param string $json |
|
| 1246 | + * @return string formated json |
|
| 1247 | + */ |
|
| 1248 | + private function json_format($json) |
|
| 1249 | + { |
|
| 1250 | + $tab = " "; |
|
| 1251 | + $new_json = ""; |
|
| 1252 | + $indent_level = 0; |
|
| 1253 | + $in_string = false; |
|
| 1254 | + $len = strlen($json); |
|
| 1255 | + |
|
| 1256 | + for ($c = 0; $c < $len; $c++) { |
|
| 1257 | + $char = $json[$c]; |
|
| 1258 | + switch ($char) { |
|
| 1259 | + case '{': |
|
| 1260 | + case '[': |
|
| 1261 | + if (!$in_string) { |
|
| 1262 | + $new_json .= $char . "\n" . |
|
| 1263 | + str_repeat($tab, $indent_level + 1); |
|
| 1264 | + $indent_level++; |
|
| 1265 | + } else { |
|
| 1266 | + $new_json .= $char; |
|
| 1267 | + } |
|
| 1268 | + break; |
|
| 1269 | + case '}': |
|
| 1270 | + case ']': |
|
| 1271 | + if (!$in_string) { |
|
| 1272 | + $indent_level--; |
|
| 1273 | + $new_json .= "\n" . str_repeat($tab, $indent_level) |
|
| 1274 | + . $char; |
|
| 1275 | + } else { |
|
| 1276 | + $new_json .= $char; |
|
| 1277 | + } |
|
| 1278 | + break; |
|
| 1279 | + case ',': |
|
| 1280 | + if (!$in_string) { |
|
| 1281 | + $new_json .= ",\n" . str_repeat($tab, $indent_level); |
|
| 1282 | + } else { |
|
| 1283 | + $new_json .= $char; |
|
| 1284 | + } |
|
| 1285 | + break; |
|
| 1286 | + case ':': |
|
| 1287 | + if (!$in_string) { |
|
| 1288 | + $new_json .= ": "; |
|
| 1289 | + } else { |
|
| 1290 | + $new_json .= $char; |
|
| 1291 | + } |
|
| 1292 | + break; |
|
| 1293 | + case '"': |
|
| 1294 | + if ($c == 0) { |
|
| 1295 | + $in_string = true; |
|
| 1296 | + } else if ($c > 0 && $json[$c - 1] != '\\') { |
|
| 1297 | + $in_string = !$in_string; |
|
| 1298 | + } |
|
| 1299 | + default: |
|
| 1300 | + $new_json .= $char; |
|
| 1301 | + break; |
|
| 1302 | + } |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + return $new_json; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + public function __toString() |
|
| 1310 | + { |
|
| 1311 | + return $this->getExtension(); |
|
| 1312 | + } |
|
| 1313 | 1313 | |
| 1314 | 1314 | } |
| 1315 | 1315 | |
@@ -1327,123 +1327,123 @@ discard block |
||
| 1327 | 1327 | class DocParser |
| 1328 | 1328 | { |
| 1329 | 1329 | |
| 1330 | - private $params = array(); |
|
| 1331 | - |
|
| 1332 | - |
|
| 1333 | - function parse($doc = '') |
|
| 1334 | - { |
|
| 1335 | - if ($doc == '') { |
|
| 1336 | - return $this->params; |
|
| 1337 | - } |
|
| 1338 | - //Get the comment |
|
| 1339 | - if (preg_match('#^/\*\*(.*)\*/#s', $doc, $comment) === false) { |
|
| 1340 | - return $this->params; |
|
| 1341 | - } |
|
| 1342 | - $comment = trim($comment[1]); |
|
| 1343 | - //Get all the lines and strip the * from the first character |
|
| 1344 | - if (preg_match_all('#^\s*\*(.*)#m', $comment, $lines) === false) { |
|
| 1345 | - return $this->params; |
|
| 1346 | - } |
|
| 1347 | - $this->parseLines($lines[1]); |
|
| 1348 | - return $this->params; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - |
|
| 1352 | - private function parseLines($lines) |
|
| 1353 | - { |
|
| 1354 | - foreach ($lines as $line) { |
|
| 1355 | - $parsedLine = $this->parseLine($line); //Parse the line |
|
| 1356 | - |
|
| 1357 | - if ($parsedLine === false && !isset($this->params['description'])) { |
|
| 1358 | - if (isset($desc)) { |
|
| 1359 | - //Store the first line in the short description |
|
| 1360 | - $this->params['description'] = implode(PHP_EOL, $desc); |
|
| 1361 | - } |
|
| 1362 | - $desc = array(); |
|
| 1363 | - } else if ($parsedLine !== false) { |
|
| 1364 | - $desc[] = $parsedLine; //Store the line in the long description |
|
| 1365 | - } |
|
| 1366 | - } |
|
| 1367 | - $desc = implode(' ', $desc); |
|
| 1368 | - if (!empty($desc)) { |
|
| 1369 | - $this->params['long_description'] = $desc; |
|
| 1370 | - } |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - |
|
| 1374 | - private function parseLine($line) |
|
| 1375 | - { |
|
| 1376 | - //trim the whitespace from the line |
|
| 1377 | - $line = trim($line); |
|
| 1378 | - |
|
| 1379 | - if (empty($line)) { |
|
| 1380 | - return false; //Empty line |
|
| 1381 | - } |
|
| 1382 | - |
|
| 1383 | - if (strpos($line, '@') === 0) { |
|
| 1384 | - if (strpos($line, ' ') > 0) { |
|
| 1385 | - //Get the parameter name |
|
| 1386 | - $param = substr($line, 1, strpos($line, ' ') - 1); |
|
| 1387 | - $value = substr($line, strlen($param) + 2); //Get the value |
|
| 1388 | - } else { |
|
| 1389 | - $param = substr($line, 1); |
|
| 1390 | - $value = ''; |
|
| 1391 | - } |
|
| 1392 | - //Parse the line and return false if the parameter is valid |
|
| 1393 | - if ($this->setParam($param, $value)) { |
|
| 1394 | - return false; |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - return $line; |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - private function setParam($param, $value) |
|
| 1402 | - { |
|
| 1403 | - if ($param == 'param' || $param == 'return') { |
|
| 1404 | - $value = $this->formatParamOrReturn($value); |
|
| 1405 | - } |
|
| 1406 | - if ($param == 'class') { |
|
| 1407 | - list($param, $value) = $this->formatClass($value); |
|
| 1408 | - } |
|
| 1409 | - |
|
| 1410 | - if (empty($this->params[$param])) { |
|
| 1411 | - $this->params[$param] = $value; |
|
| 1412 | - } else if ($param == 'param') { |
|
| 1413 | - $arr = array($this->params[$param], $value); |
|
| 1414 | - $this->params[$param] = $arr; |
|
| 1415 | - } else { |
|
| 1416 | - $this->params[$param] = $value + $this->params[$param]; |
|
| 1417 | - } |
|
| 1418 | - return true; |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - |
|
| 1422 | - private function formatClass($value) |
|
| 1423 | - { |
|
| 1424 | - $r = preg_split("[\(|\)]", $value); |
|
| 1425 | - if (count($r) > 1) { |
|
| 1426 | - $param = $r[0]; |
|
| 1427 | - parse_str($r[1], $value); |
|
| 1428 | - foreach ($value as $key => $val) { |
|
| 1429 | - $val = explode(',', $val); |
|
| 1430 | - if (count($val) > 1) { |
|
| 1431 | - $value[$key] = $val; |
|
| 1432 | - } |
|
| 1433 | - } |
|
| 1434 | - } else { |
|
| 1435 | - $param = 'Unknown'; |
|
| 1436 | - } |
|
| 1437 | - return array($param, $value); |
|
| 1438 | - } |
|
| 1439 | - |
|
| 1440 | - |
|
| 1441 | - private function formatParamOrReturn($string) |
|
| 1442 | - { |
|
| 1443 | - $pos = strpos($string, ' '); |
|
| 1444 | - $type = substr($string, 0, $pos); |
|
| 1445 | - return '(' . $type . ')' . substr($string, $pos + 1); |
|
| 1446 | - } |
|
| 1330 | + private $params = array(); |
|
| 1331 | + |
|
| 1332 | + |
|
| 1333 | + function parse($doc = '') |
|
| 1334 | + { |
|
| 1335 | + if ($doc == '') { |
|
| 1336 | + return $this->params; |
|
| 1337 | + } |
|
| 1338 | + //Get the comment |
|
| 1339 | + if (preg_match('#^/\*\*(.*)\*/#s', $doc, $comment) === false) { |
|
| 1340 | + return $this->params; |
|
| 1341 | + } |
|
| 1342 | + $comment = trim($comment[1]); |
|
| 1343 | + //Get all the lines and strip the * from the first character |
|
| 1344 | + if (preg_match_all('#^\s*\*(.*)#m', $comment, $lines) === false) { |
|
| 1345 | + return $this->params; |
|
| 1346 | + } |
|
| 1347 | + $this->parseLines($lines[1]); |
|
| 1348 | + return $this->params; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + |
|
| 1352 | + private function parseLines($lines) |
|
| 1353 | + { |
|
| 1354 | + foreach ($lines as $line) { |
|
| 1355 | + $parsedLine = $this->parseLine($line); //Parse the line |
|
| 1356 | + |
|
| 1357 | + if ($parsedLine === false && !isset($this->params['description'])) { |
|
| 1358 | + if (isset($desc)) { |
|
| 1359 | + //Store the first line in the short description |
|
| 1360 | + $this->params['description'] = implode(PHP_EOL, $desc); |
|
| 1361 | + } |
|
| 1362 | + $desc = array(); |
|
| 1363 | + } else if ($parsedLine !== false) { |
|
| 1364 | + $desc[] = $parsedLine; //Store the line in the long description |
|
| 1365 | + } |
|
| 1366 | + } |
|
| 1367 | + $desc = implode(' ', $desc); |
|
| 1368 | + if (!empty($desc)) { |
|
| 1369 | + $this->params['long_description'] = $desc; |
|
| 1370 | + } |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + |
|
| 1374 | + private function parseLine($line) |
|
| 1375 | + { |
|
| 1376 | + //trim the whitespace from the line |
|
| 1377 | + $line = trim($line); |
|
| 1378 | + |
|
| 1379 | + if (empty($line)) { |
|
| 1380 | + return false; //Empty line |
|
| 1381 | + } |
|
| 1382 | + |
|
| 1383 | + if (strpos($line, '@') === 0) { |
|
| 1384 | + if (strpos($line, ' ') > 0) { |
|
| 1385 | + //Get the parameter name |
|
| 1386 | + $param = substr($line, 1, strpos($line, ' ') - 1); |
|
| 1387 | + $value = substr($line, strlen($param) + 2); //Get the value |
|
| 1388 | + } else { |
|
| 1389 | + $param = substr($line, 1); |
|
| 1390 | + $value = ''; |
|
| 1391 | + } |
|
| 1392 | + //Parse the line and return false if the parameter is valid |
|
| 1393 | + if ($this->setParam($param, $value)) { |
|
| 1394 | + return false; |
|
| 1395 | + } |
|
| 1396 | + } |
|
| 1397 | + return $line; |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + private function setParam($param, $value) |
|
| 1402 | + { |
|
| 1403 | + if ($param == 'param' || $param == 'return') { |
|
| 1404 | + $value = $this->formatParamOrReturn($value); |
|
| 1405 | + } |
|
| 1406 | + if ($param == 'class') { |
|
| 1407 | + list($param, $value) = $this->formatClass($value); |
|
| 1408 | + } |
|
| 1409 | + |
|
| 1410 | + if (empty($this->params[$param])) { |
|
| 1411 | + $this->params[$param] = $value; |
|
| 1412 | + } else if ($param == 'param') { |
|
| 1413 | + $arr = array($this->params[$param], $value); |
|
| 1414 | + $this->params[$param] = $arr; |
|
| 1415 | + } else { |
|
| 1416 | + $this->params[$param] = $value + $this->params[$param]; |
|
| 1417 | + } |
|
| 1418 | + return true; |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + |
|
| 1422 | + private function formatClass($value) |
|
| 1423 | + { |
|
| 1424 | + $r = preg_split("[\(|\)]", $value); |
|
| 1425 | + if (count($r) > 1) { |
|
| 1426 | + $param = $r[0]; |
|
| 1427 | + parse_str($r[1], $value); |
|
| 1428 | + foreach ($value as $key => $val) { |
|
| 1429 | + $val = explode(',', $val); |
|
| 1430 | + if (count($val) > 1) { |
|
| 1431 | + $value[$key] = $val; |
|
| 1432 | + } |
|
| 1433 | + } |
|
| 1434 | + } else { |
|
| 1435 | + $param = 'Unknown'; |
|
| 1436 | + } |
|
| 1437 | + return array($param, $value); |
|
| 1438 | + } |
|
| 1439 | + |
|
| 1440 | + |
|
| 1441 | + private function formatParamOrReturn($string) |
|
| 1442 | + { |
|
| 1443 | + $pos = strpos($string, ' '); |
|
| 1444 | + $type = substr($string, 0, $pos); |
|
| 1445 | + return '(' . $type . ')' . substr($string, $pos + 1); |
|
| 1446 | + } |
|
| 1447 | 1447 | |
| 1448 | 1448 | } |
| 1449 | 1449 | |
@@ -1456,30 +1456,30 @@ discard block |
||
| 1456 | 1456 | |
| 1457 | 1457 | function parse_doc($php_doc_comment) |
| 1458 | 1458 | { |
| 1459 | - $p = new DocParser(); |
|
| 1460 | - return $p->parse($php_doc_comment); |
|
| 1459 | + $p = new DocParser(); |
|
| 1460 | + return $p->parse($php_doc_comment); |
|
| 1461 | 1461 | |
| 1462 | - $p = new Parser($php_doc_comment); |
|
| 1463 | - return $p; |
|
| 1462 | + $p = new Parser($php_doc_comment); |
|
| 1463 | + return $p; |
|
| 1464 | 1464 | |
| 1465 | - $php_doc_comment = preg_replace( |
|
| 1466 | - "/(^[\\s]*\\/\\*\\*) |
|
| 1465 | + $php_doc_comment = preg_replace( |
|
| 1466 | + "/(^[\\s]*\\/\\*\\*) |
|
| 1467 | 1467 | |(^[\\s]\\*\\/) |
| 1468 | 1468 | |(^[\\s]*\\*?\\s) |
| 1469 | 1469 | |(^[\\s]*) |
| 1470 | 1470 | |(^[\\t]*)/ixm", |
| 1471 | - "", $php_doc_comment); |
|
| 1472 | - $php_doc_comment = str_replace("\r", "", $php_doc_comment); |
|
| 1473 | - $php_doc_comment = preg_replace("/([\\t])+/", "\t", $php_doc_comment); |
|
| 1474 | - return explode("\n", $php_doc_comment); |
|
| 1475 | - |
|
| 1476 | - $php_doc_comment = trim(preg_replace('/\r?\n *\* */', ' ', |
|
| 1477 | - $php_doc_comment)); |
|
| 1478 | - return $php_doc_comment; |
|
| 1479 | - |
|
| 1480 | - preg_match_all('/@([a-z]+)\s+(.*?)\s*(?=$|@[a-z]+\s)/s', $php_doc_comment, |
|
| 1481 | - $matches); |
|
| 1482 | - return array_combine($matches[1], $matches[2]); |
|
| 1471 | + "", $php_doc_comment); |
|
| 1472 | + $php_doc_comment = str_replace("\r", "", $php_doc_comment); |
|
| 1473 | + $php_doc_comment = preg_replace("/([\\t])+/", "\t", $php_doc_comment); |
|
| 1474 | + return explode("\n", $php_doc_comment); |
|
| 1475 | + |
|
| 1476 | + $php_doc_comment = trim(preg_replace('/\r?\n *\* */', ' ', |
|
| 1477 | + $php_doc_comment)); |
|
| 1478 | + return $php_doc_comment; |
|
| 1479 | + |
|
| 1480 | + preg_match_all('/@([a-z]+)\s+(.*?)\s*(?=$|@[a-z]+\s)/s', $php_doc_comment, |
|
| 1481 | + $matches); |
|
| 1482 | + return array_combine($matches[1], $matches[2]); |
|
| 1483 | 1483 | } |
| 1484 | 1484 | |
| 1485 | 1485 | |
@@ -1498,21 +1498,21 @@ discard block |
||
| 1498 | 1498 | */ |
| 1499 | 1499 | function object_to_array($object, $utf_encode = false) |
| 1500 | 1500 | { |
| 1501 | - if (is_array($object) |
|
| 1502 | - || (is_object($object) |
|
| 1503 | - && !($object instanceof JsonSerializable)) |
|
| 1504 | - ) { |
|
| 1505 | - $array = array(); |
|
| 1506 | - foreach ($object as $key => $value) { |
|
| 1507 | - $value = object_to_array($value, $utf_encode); |
|
| 1508 | - if ($utf_encode && is_string($value)) { |
|
| 1509 | - $value = utf8_encode($value); |
|
| 1510 | - } |
|
| 1511 | - $array[$key] = $value; |
|
| 1512 | - } |
|
| 1513 | - return $array; |
|
| 1514 | - } |
|
| 1515 | - return $object; |
|
| 1501 | + if (is_array($object) |
|
| 1502 | + || (is_object($object) |
|
| 1503 | + && !($object instanceof JsonSerializable)) |
|
| 1504 | + ) { |
|
| 1505 | + $array = array(); |
|
| 1506 | + foreach ($object as $key => $value) { |
|
| 1507 | + $value = object_to_array($value, $utf_encode); |
|
| 1508 | + if ($utf_encode && is_string($value)) { |
|
| 1509 | + $value = utf8_encode($value); |
|
| 1510 | + } |
|
| 1511 | + $array[$key] = $value; |
|
| 1512 | + } |
|
| 1513 | + return $array; |
|
| 1514 | + } |
|
| 1515 | + return $object; |
|
| 1516 | 1516 | } |
| 1517 | 1517 | |
| 1518 | 1518 | |
@@ -1522,21 +1522,21 @@ discard block |
||
| 1522 | 1522 | */ |
| 1523 | 1523 | function autoload_formats($class_name) |
| 1524 | 1524 | { |
| 1525 | - $class_name = strtolower($class_name); |
|
| 1525 | + $class_name = strtolower($class_name); |
|
| 1526 | 1526 | |
| 1527 | - $file = RESTLER_PATH . "../../../api/mobile_services/$class_name.php"; |
|
| 1528 | - if (file_exists($file)) { |
|
| 1529 | - require_once ($file); |
|
| 1530 | - } else { |
|
| 1527 | + $file = RESTLER_PATH . "../../../api/mobile_services/$class_name.php"; |
|
| 1528 | + if (file_exists($file)) { |
|
| 1529 | + require_once ($file); |
|
| 1530 | + } else { |
|
| 1531 | 1531 | $file = RESTLER_PATH . "/../../api/mobile_services/$class_name.php"; |
| 1532 | - if (file_exists($file)) { |
|
| 1533 | - require_once ($file); |
|
| 1534 | - } elseif (file_exists(RESTLER_PATH . "/../api/mobile_services/$class_name.php")) { |
|
| 1535 | - require_once ("/../api/mobile_services/$class_name.php"); |
|
| 1536 | - } elseif (file_exists("$class_name.php")) { |
|
| 1537 | - require_once ("$class_name.php"); |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1532 | + if (file_exists($file)) { |
|
| 1533 | + require_once ($file); |
|
| 1534 | + } elseif (file_exists(RESTLER_PATH . "/../api/mobile_services/$class_name.php")) { |
|
| 1535 | + require_once ("/../api/mobile_services/$class_name.php"); |
|
| 1536 | + } elseif (file_exists("$class_name.php")) { |
|
| 1537 | + require_once ("$class_name.php"); |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | 1540 | } |
| 1541 | 1541 | |
| 1542 | 1542 | // ================================================================== |
@@ -1553,10 +1553,10 @@ discard block |
||
| 1553 | 1553 | if (!function_exists('isRestlerCompatibilityModeEnabled')) { |
| 1554 | 1554 | |
| 1555 | 1555 | |
| 1556 | - function isRestlerCompatibilityModeEnabled() |
|
| 1557 | - { |
|
| 1558 | - return false; |
|
| 1559 | - } |
|
| 1556 | + function isRestlerCompatibilityModeEnabled() |
|
| 1557 | + { |
|
| 1558 | + return false; |
|
| 1559 | + } |
|
| 1560 | 1560 | |
| 1561 | 1561 | } |
| 1562 | 1562 | define('RESTLER_PATH', dirname(__FILE__)); |
| 1563 | 1563 | \ No newline at end of file |
@@ -472,9 +472,9 @@ discard block |
||
| 472 | 472 | header('Content-Type: ' . $this->response_format->getMIME()); |
| 473 | 473 | //.'; charset=utf-8'); |
| 474 | 474 | header("X-Powered-By: Luracast Restler v" . Restler::VERSION); |
| 475 | - if($this->production_mode){ |
|
| 475 | + if ($this->production_mode) { |
|
| 476 | 476 | die($data); |
| 477 | - }else{ |
|
| 477 | + } else { |
|
| 478 | 478 | echo $data; |
| 479 | 479 | } |
| 480 | 480 | } |
@@ -649,8 +649,7 @@ discard block |
||
| 649 | 649 | $parts = explode(';q=', trim($accept)); |
| 650 | 650 | $type = array_shift($parts); |
| 651 | 651 | $quality = count($parts) ? |
| 652 | - floatval(array_shift($parts)) : |
|
| 653 | - (1000 - $pos) / 1000; |
|
| 652 | + floatval(array_shift($parts)) : (1000 - $pos) / 1000; |
|
| 654 | 653 | $acceptList[$type] = $quality; |
| 655 | 654 | } |
| 656 | 655 | arsort($acceptList); |
@@ -839,8 +838,7 @@ discard block |
||
| 839 | 838 | $position++; |
| 840 | 839 | } |
| 841 | 840 | $method_flag = $method->isProtected() ? |
| 842 | - (isRestlerCompatibilityModeEnabled() ? 2 : 3) : |
|
| 843 | - (isset($metadata['protected']) ? 1 : 0); |
|
| 841 | + (isRestlerCompatibilityModeEnabled() ? 2 : 3) : (isset($metadata['protected']) ? 1 : 0); |
|
| 844 | 842 | |
| 845 | 843 | //take note of the order |
| 846 | 844 | $call = array( |
@@ -873,8 +871,7 @@ discard block |
||
| 873 | 871 | $http_method = 'GET'; |
| 874 | 872 | } |
| 875 | 873 | $url = $base_path |
| 876 | - . ($method_url == 'index' || $method_url == 'default' ? '' : |
|
| 877 | - $method_url); |
|
| 874 | + . ($method_url == 'index' || $method_url == 'default' ? '' : $method_url); |
|
| 878 | 875 | $url = rtrim($url, '/'); |
| 879 | 876 | $this->routes[$http_method][$url] = $call; |
| 880 | 877 | foreach ($params as $param) { |
@@ -1198,8 +1195,7 @@ discard block |
||
| 1198 | 1195 | public function encode($data, $human_readable = false) |
| 1199 | 1196 | { |
| 1200 | 1197 | return $human_readable ? |
| 1201 | - $this->json_format(json_encode(object_to_array($data))) : |
|
| 1202 | - json_encode(object_to_array($data)); |
|
| 1198 | + $this->json_format(json_encode(object_to_array($data))) : json_encode(object_to_array($data)); |
|
| 1203 | 1199 | } |
| 1204 | 1200 | |
| 1205 | 1201 | |
@@ -1225,7 +1221,7 @@ discard block |
||
| 1225 | 1221 | $message = 'malformed JSON'; |
| 1226 | 1222 | break; |
| 1227 | 1223 | case JSON_ERROR_UTF8: |
| 1228 | - $message = 'malformed UTF-8 characters, '. |
|
| 1224 | + $message = 'malformed UTF-8 characters, ' . |
|
| 1229 | 1225 | 'possibly incorrectly encoded'; |
| 1230 | 1226 | break; |
| 1231 | 1227 | default: |
@@ -474,7 +474,7 @@ |
||
| 474 | 474 | header("X-Powered-By: Luracast Restler v" . Restler::VERSION); |
| 475 | 475 | if($this->production_mode){ |
| 476 | 476 | die($data); |
| 477 | - }else{ |
|
| 477 | + } else{ |
|
| 478 | 478 | echo $data; |
| 479 | 479 | } |
| 480 | 480 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | * supplied by the authentication backend. |
| 71 | 71 | * |
| 72 | 72 | * @param array $principalInfo |
| 73 | - * @return void |
|
| 73 | + * @return Collection |
|
| 74 | 74 | */ |
| 75 | 75 | function getChildForPrincipal(array $principalInfo) { |
| 76 | 76 | |
@@ -21,168 +21,168 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class HomeCollection extends AbstractPrincipalCollection implements IACL { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Name of this collection. |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - public $collectionName = 'home'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Path to where the users' files are actually stored. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $storagePath; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Creates the home collection. |
|
| 40 | - * |
|
| 41 | - * @param BackendInterface $principalBackend |
|
| 42 | - * @param string $storagePath Where the actual files are stored. |
|
| 43 | - * @param string $principalPrefix list of principals to iterate. |
|
| 44 | - */ |
|
| 45 | - function __construct(BackendInterface $principalBackend, $storagePath, $principalPrefix = 'principals') { |
|
| 46 | - |
|
| 47 | - parent::__construct($principalBackend, $principalPrefix); |
|
| 48 | - $this->storagePath = $storagePath; |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Returns the name of the node. |
|
| 54 | - * |
|
| 55 | - * This is used to generate the url. |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - function getName() { |
|
| 60 | - |
|
| 61 | - return $this->collectionName; |
|
| 62 | - |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Returns a principals' collection of files. |
|
| 67 | - * |
|
| 68 | - * The passed array contains principal information, and is guaranteed to |
|
| 69 | - * at least contain a uri item. Other properties may or may not be |
|
| 70 | - * supplied by the authentication backend. |
|
| 71 | - * |
|
| 72 | - * @param array $principalInfo |
|
| 73 | - * @return void |
|
| 74 | - */ |
|
| 75 | - function getChildForPrincipal(array $principalInfo) { |
|
| 76 | - |
|
| 77 | - $owner = $principalInfo['uri']; |
|
| 78 | - $acl = [ |
|
| 79 | - [ |
|
| 80 | - 'privilege' => '{DAV:}read', |
|
| 81 | - 'principal' => $owner, |
|
| 82 | - 'protected' => true, |
|
| 83 | - ], |
|
| 84 | - [ |
|
| 85 | - 'privilege' => '{DAV:}write', |
|
| 86 | - 'principal' => $owner, |
|
| 87 | - 'protected' => true, |
|
| 88 | - ], |
|
| 89 | - ]; |
|
| 90 | - |
|
| 91 | - list(, $principalBaseName) = Uri\split($owner); |
|
| 92 | - |
|
| 93 | - $path = $this->storagePath . '/' . $principalBaseName; |
|
| 94 | - |
|
| 95 | - if (!is_dir($path)) { |
|
| 96 | - mkdir($path, 0777, true); |
|
| 97 | - } |
|
| 98 | - return new Collection( |
|
| 99 | - $path, |
|
| 100 | - $acl, |
|
| 101 | - $owner |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Returns the owner principal |
|
| 108 | - * |
|
| 109 | - * This must be a url to a principal, or null if there's no owner |
|
| 110 | - * |
|
| 111 | - * @return string|null |
|
| 112 | - */ |
|
| 113 | - function getOwner() { |
|
| 114 | - |
|
| 115 | - return null; |
|
| 116 | - |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Returns a group principal |
|
| 121 | - * |
|
| 122 | - * This must be a url to a principal, or null if there's no owner |
|
| 123 | - * |
|
| 124 | - * @return string|null |
|
| 125 | - */ |
|
| 126 | - function getGroup() { |
|
| 127 | - |
|
| 128 | - return null; |
|
| 129 | - |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Returns a list of ACE's for this node. |
|
| 134 | - * |
|
| 135 | - * Each ACE has the following properties: |
|
| 136 | - * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 137 | - * currently the only supported privileges |
|
| 138 | - * * 'principal', a url to the principal who owns the node |
|
| 139 | - * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 140 | - * be updated. |
|
| 141 | - * |
|
| 142 | - * @return array |
|
| 143 | - */ |
|
| 144 | - function getACL() { |
|
| 145 | - |
|
| 146 | - return [ |
|
| 147 | - [ |
|
| 148 | - 'principal' => '{DAV:}authenticated', |
|
| 149 | - 'privilege' => '{DAV:}read', |
|
| 150 | - 'protected' => true, |
|
| 151 | - ] |
|
| 152 | - ]; |
|
| 153 | - |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Updates the ACL |
|
| 158 | - * |
|
| 159 | - * This method will receive a list of new ACE's as an array argument. |
|
| 160 | - * |
|
| 161 | - * @param array $acl |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - function setACL(array $acl) { |
|
| 165 | - |
|
| 166 | - throw new Forbidden('Setting ACL is not allowed here'); |
|
| 167 | - |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Returns the list of supported privileges for this node. |
|
| 172 | - * |
|
| 173 | - * The returned data structure is a list of nested privileges. |
|
| 174 | - * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple |
|
| 175 | - * standard structure. |
|
| 176 | - * |
|
| 177 | - * If null is returned from this method, the default privilege set is used, |
|
| 178 | - * which is fine for most common usecases. |
|
| 179 | - * |
|
| 180 | - * @return array|null |
|
| 181 | - */ |
|
| 182 | - function getSupportedPrivilegeSet() { |
|
| 183 | - |
|
| 184 | - return null; |
|
| 185 | - |
|
| 186 | - } |
|
| 24 | + /** |
|
| 25 | + * Name of this collection. |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + public $collectionName = 'home'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Path to where the users' files are actually stored. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $storagePath; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Creates the home collection. |
|
| 40 | + * |
|
| 41 | + * @param BackendInterface $principalBackend |
|
| 42 | + * @param string $storagePath Where the actual files are stored. |
|
| 43 | + * @param string $principalPrefix list of principals to iterate. |
|
| 44 | + */ |
|
| 45 | + function __construct(BackendInterface $principalBackend, $storagePath, $principalPrefix = 'principals') { |
|
| 46 | + |
|
| 47 | + parent::__construct($principalBackend, $principalPrefix); |
|
| 48 | + $this->storagePath = $storagePath; |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Returns the name of the node. |
|
| 54 | + * |
|
| 55 | + * This is used to generate the url. |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + function getName() { |
|
| 60 | + |
|
| 61 | + return $this->collectionName; |
|
| 62 | + |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Returns a principals' collection of files. |
|
| 67 | + * |
|
| 68 | + * The passed array contains principal information, and is guaranteed to |
|
| 69 | + * at least contain a uri item. Other properties may or may not be |
|
| 70 | + * supplied by the authentication backend. |
|
| 71 | + * |
|
| 72 | + * @param array $principalInfo |
|
| 73 | + * @return void |
|
| 74 | + */ |
|
| 75 | + function getChildForPrincipal(array $principalInfo) { |
|
| 76 | + |
|
| 77 | + $owner = $principalInfo['uri']; |
|
| 78 | + $acl = [ |
|
| 79 | + [ |
|
| 80 | + 'privilege' => '{DAV:}read', |
|
| 81 | + 'principal' => $owner, |
|
| 82 | + 'protected' => true, |
|
| 83 | + ], |
|
| 84 | + [ |
|
| 85 | + 'privilege' => '{DAV:}write', |
|
| 86 | + 'principal' => $owner, |
|
| 87 | + 'protected' => true, |
|
| 88 | + ], |
|
| 89 | + ]; |
|
| 90 | + |
|
| 91 | + list(, $principalBaseName) = Uri\split($owner); |
|
| 92 | + |
|
| 93 | + $path = $this->storagePath . '/' . $principalBaseName; |
|
| 94 | + |
|
| 95 | + if (!is_dir($path)) { |
|
| 96 | + mkdir($path, 0777, true); |
|
| 97 | + } |
|
| 98 | + return new Collection( |
|
| 99 | + $path, |
|
| 100 | + $acl, |
|
| 101 | + $owner |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Returns the owner principal |
|
| 108 | + * |
|
| 109 | + * This must be a url to a principal, or null if there's no owner |
|
| 110 | + * |
|
| 111 | + * @return string|null |
|
| 112 | + */ |
|
| 113 | + function getOwner() { |
|
| 114 | + |
|
| 115 | + return null; |
|
| 116 | + |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Returns a group principal |
|
| 121 | + * |
|
| 122 | + * This must be a url to a principal, or null if there's no owner |
|
| 123 | + * |
|
| 124 | + * @return string|null |
|
| 125 | + */ |
|
| 126 | + function getGroup() { |
|
| 127 | + |
|
| 128 | + return null; |
|
| 129 | + |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Returns a list of ACE's for this node. |
|
| 134 | + * |
|
| 135 | + * Each ACE has the following properties: |
|
| 136 | + * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are |
|
| 137 | + * currently the only supported privileges |
|
| 138 | + * * 'principal', a url to the principal who owns the node |
|
| 139 | + * * 'protected' (optional), indicating that this ACE is not allowed to |
|
| 140 | + * be updated. |
|
| 141 | + * |
|
| 142 | + * @return array |
|
| 143 | + */ |
|
| 144 | + function getACL() { |
|
| 145 | + |
|
| 146 | + return [ |
|
| 147 | + [ |
|
| 148 | + 'principal' => '{DAV:}authenticated', |
|
| 149 | + 'privilege' => '{DAV:}read', |
|
| 150 | + 'protected' => true, |
|
| 151 | + ] |
|
| 152 | + ]; |
|
| 153 | + |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Updates the ACL |
|
| 158 | + * |
|
| 159 | + * This method will receive a list of new ACE's as an array argument. |
|
| 160 | + * |
|
| 161 | + * @param array $acl |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + function setACL(array $acl) { |
|
| 165 | + |
|
| 166 | + throw new Forbidden('Setting ACL is not allowed here'); |
|
| 167 | + |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Returns the list of supported privileges for this node. |
|
| 172 | + * |
|
| 173 | + * The returned data structure is a list of nested privileges. |
|
| 174 | + * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple |
|
| 175 | + * standard structure. |
|
| 176 | + * |
|
| 177 | + * If null is returned from this method, the default privilege set is used, |
|
| 178 | + * which is fine for most common usecases. |
|
| 179 | + * |
|
| 180 | + * @return array|null |
|
| 181 | + */ |
|
| 182 | + function getSupportedPrivilegeSet() { |
|
| 183 | + |
|
| 184 | + return null; |
|
| 185 | + |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | } |
@@ -2,10 +2,10 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Sabre\DAVACL\FS; |
| 4 | 4 | |
| 5 | -use Sabre\DAV\Exception\Forbidden; |
|
| 6 | 5 | use Sabre\DAVACL\AbstractPrincipalCollection; |
| 7 | 6 | use Sabre\DAVACL\IACL; |
| 8 | 7 | use Sabre\DAVACL\PrincipalBackend\BackendInterface; |
| 8 | +use Sabre\DAV\Exception\Forbidden; |
|
| 9 | 9 | use Sabre\Uri; |
| 10 | 10 | |
| 11 | 11 | /** |