From 4a81986352f7d0759116e6172bb1c92b356430a1 Mon Sep 17 00:00:00 2001 From: gggeek Date: Sun, 29 Mar 2015 16:57:01 +0100 Subject: [PATCH] CamelCase everywhere! --- src/Client.php | 365 +++++++++++++++++++++++++------------------- src/Encoder.php | 138 ++++++++--------- src/Request.php | 69 ++++----- src/Server.php | 134 ++++++++-------- src/Value.php | 52 +++---- src/Wrapper.php | 394 ++++++++++++++++++++++++------------------------ 6 files changed, 609 insertions(+), 543 deletions(-) diff --git a/src/Client.php b/src/Client.php index 5fe3f02..a13c31b 100644 --- a/src/Client.php +++ b/src/Client.php @@ -167,27 +167,27 @@ class Client * Add a client-side https certificate. * * @param string $cert - * @param string $certpass + * @param string $certPass */ - public function setCertificate($cert, $certpass) + public function setCertificate($cert, $certPass) { $this->cert = $cert; - $this->certpass = $certpass; + $this->certpass = $certPass; } /** * Add a CA certificate to verify server with (see man page about * CURLOPT_CAINFO for more details). * - * @param string $cacert certificate file name (or dir holding certificates) - * @param bool $is_dir set to true to indicate cacert is a dir. defaults to false + * @param string $caCert certificate file name (or dir holding certificates) + * @param bool $isDir set to true to indicate cacert is a dir. defaults to false */ - public function setCaCertificate($cacert, $is_dir = false) + public function setCaCertificate($caCert, $isDir = false) { - if ($is_dir) { - $this->cacertdir = $cacert; + if ($isDir) { + $this->cacertdir = $caCert; } else { - $this->cacert = $cacert; + $this->cacert = $caCert; } } @@ -197,12 +197,12 @@ class Client * Thanks to Daniel Convissor. * * @param string $key The name of a file containing a private SSL key - * @param string $keypass The secret password needed to use the private SSL key + * @param string $keyPass The secret password needed to use the private SSL key */ - public function setKey($key, $keypass) + public function setKey($key, $keyPass) { $this->key = $key; - $this->keypass = $keypass; + $this->keypass = $keyPass; } /** @@ -238,19 +238,19 @@ class Client /** * Set proxy info. * - * @param string $proxyhost - * @param string $proxyport Defaults to 8080 for HTTP and 443 for HTTPS - * @param string $proxyusername Leave blank if proxy has public access - * @param string $proxypassword Leave blank if proxy has public access - * @param int $proxyauthtype set to constant CURLAUTH_NTLM to use NTLM auth with proxy + * @param string $proxyHost + * @param string $proxyPort Defaults to 8080 for HTTP and 443 for HTTPS + * @param string $proxyUsername Leave blank if proxy has public access + * @param string $proxyPassword Leave blank if proxy has public access + * @param int $proxyAuthType set to constant CURLAUTH_NTLM to use NTLM auth with proxy */ - public function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1) + public function setProxy($proxyHost, $proxyPort, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1) { - $this->proxy = $proxyhost; - $this->proxyport = $proxyport; - $this->proxy_user = $proxyusername; - $this->proxy_pass = $proxypassword; - $this->proxy_authtype = $proxyauthtype; + $this->proxy = $proxyHost; + $this->proxyport = $proxyPort; + $this->proxy_user = $proxyUsername; + $this->proxy_pass = $proxyPassword; + $this->proxy_authtype = $proxyAuthType; } /** @@ -259,16 +259,16 @@ class Client * http headers to xmlrpc requests. It is up to the xmlrpc server to return * compressed responses when receiving such requests. * - * @param string $compmethod either 'gzip', 'deflate', 'any' or '' + * @param string $compMethod either 'gzip', 'deflate', 'any' or '' */ - public function setAcceptedCompression($compmethod) + public function setAcceptedCompression($compMethod) { - if ($compmethod == 'any') { + if ($compMethod == 'any') { $this->accepted_compression = array('gzip', 'deflate'); - } elseif ($compmethod == false) { + } elseif ($compMethod == false) { $this->accepted_compression = array(); } else { - $this->accepted_compression = array($compmethod); + $this->accepted_compression = array($compMethod); } } @@ -277,11 +277,11 @@ class Client * Take care when sending compressed requests: servers might not support them * (and automatic fallback to uncompressed requests is not yet implemented). * - * @param string $compmethod either 'gzip', 'deflate' or '' + * @param string $compMethod either 'gzip', 'deflate' or '' */ - public function setRequestCompression($compmethod) + public function setRequestCompression($compMethod) { - $this->request_compression = $compmethod; + $this->request_compression = $compMethod; } /** @@ -324,22 +324,24 @@ class Client /** * Set user-agent string that will be used by this client instance * in http headers sent to the server. + * + * @param string $agentString */ - public function SetUserAgent($agentstring) + public function SetUserAgent($agentString) { - $this->user_agent = $agentstring; + $this->user_agent = $agentString; } /** * Send an xmlrpc request. * - * @param Request|Request[]|string $msg The Request object, or an array of requests for using multicall, or the complete xml representation of a request + * @param Request|Request[]|string $req The Request object, or an array of requests for using multicall, or the complete xml representation of a request * @param integer $timeout Connection timeout, in seconds, If unspecified, a platform specific timeout will apply * @param string $method if left unspecified, the http protocol chosen during creation of the object will be used * * @return Response */ - public function send($msg, $timeout = 0, $method = '') + public function send($req, $timeout = 0, $method = '') { // if user does not specify http protocol, use native method of this client // (i.e. method set during call to constructor) @@ -347,23 +349,23 @@ class Client $method = $this->method; } - if (is_array($msg)) { + if (is_array($req)) { // $msg is an array of Requests - $r = $this->multicall($msg, $timeout, $method); + $r = $this->multicall($req, $timeout, $method); return $r; - } elseif (is_string($msg)) { + } elseif (is_string($req)) { $n = new Request(''); - $n->payload = $msg; - $msg = $n; + $n->payload = $req; + $req = $n; } // where msg is a Request - $msg->debug = $this->debug; + $req->debug = $this->debug; if ($method == 'https') { $r = $this->sendPayloadHTTPS( - $msg, + $req, $this->server, $this->port, $timeout, @@ -386,7 +388,7 @@ class Client ); } elseif ($method == 'http11') { $r = $this->sendPayloadCURL( - $msg, + $req, $this->server, $this->port, $timeout, @@ -407,7 +409,7 @@ class Client ); } else { $r = $this->sendPayloadHTTP10( - $msg, + $req, $this->server, $this->port, $timeout, @@ -425,96 +427,111 @@ class Client return $r; } - private function sendPayloadHTTP10($msg, $server, $port, $timeout = 0, - $username = '', $password = '', $authtype = 1, $proxyhost = '', - $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1) + /** + * @param Request $req + * @param string $server + * @param int $port + * @param int $timeout + * @param string $username + * @param string $password + * @param int $authType + * @param string $proxyHost + * @param int $proxyPort + * @param string $proxyUsername + * @param string $proxyPassword + * @param int $proxyAuthType + * @return Response + */ + protected function sendPayloadHTTP10($req, $server, $port, $timeout = 0, + $username = '', $password = '', $authType = 1, $proxyHost = '', + $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1) { if ($port == 0) { $port = 80; } // Only create the payload if it was not created previously - if (empty($msg->payload)) { - $msg->createPayload($this->request_charset_encoding); + if (empty($req->payload)) { + $req->createPayload($this->request_charset_encoding); } - $payload = $msg->payload; + $payload = $req->payload; // Deflate request body and set appropriate request headers if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate')) { if ($this->request_compression == 'gzip') { $a = @gzencode($payload); if ($a) { $payload = $a; - $encoding_hdr = "Content-Encoding: gzip\r\n"; + $encodingHdr = "Content-Encoding: gzip\r\n"; } } else { $a = @gzcompress($payload); if ($a) { $payload = $a; - $encoding_hdr = "Content-Encoding: deflate\r\n"; + $encodingHdr = "Content-Encoding: deflate\r\n"; } } } else { - $encoding_hdr = ''; + $encodingHdr = ''; } // thanks to Grant Rauscher for this $credentials = ''; if ($username != '') { $credentials = 'Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n"; - if ($authtype != 1) { + if ($authType != 1) { error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0'); } } - $accepted_encoding = ''; + $acceptedEncoding = ''; if (is_array($this->accepted_compression) && count($this->accepted_compression)) { - $accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n"; + $acceptedEncoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n"; } - $proxy_credentials = ''; - if ($proxyhost) { - if ($proxyport == 0) { - $proxyport = 8080; + $proxyCredentials = ''; + if ($proxyHost) { + if ($proxyPort == 0) { + $proxyPort = 8080; } - $connectserver = $proxyhost; - $connectport = $proxyport; + $connectServer = $proxyHost; + $connectPort = $proxyPort; $uri = 'http://' . $server . ':' . $port . $this->path; - if ($proxyusername != '') { - if ($proxyauthtype != 1) { + if ($proxyUsername != '') { + if ($proxyAuthType != 1) { error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported with HTTP 1.0'); } - $proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername . ':' . $proxypassword) . "\r\n"; + $proxyCredentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyUsername . ':' . $proxyPassword) . "\r\n"; } } else { - $connectserver = $server; - $connectport = $port; + $connectServer = $server; + $connectPort = $port; $uri = $this->path; } // Cookie generation, as per rfc2965 (version 1 cookies) or // netscape's rules (version 0 cookies) - $cookieheader = ''; + $cookieHeader = ''; if (count($this->cookies)) { $version = ''; foreach ($this->cookies as $name => $cookie) { if ($cookie['version']) { $version = ' $Version="' . $cookie['version'] . '";'; - $cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";'; + $cookieHeader .= ' ' . $name . '="' . $cookie['value'] . '";'; if ($cookie['path']) { - $cookieheader .= ' $Path="' . $cookie['path'] . '";'; + $cookieHeader .= ' $Path="' . $cookie['path'] . '";'; } if ($cookie['domain']) { - $cookieheader .= ' $Domain="' . $cookie['domain'] . '";'; + $cookieHeader .= ' $Domain="' . $cookie['domain'] . '";'; } if ($cookie['port']) { - $cookieheader .= ' $Port="' . $cookie['port'] . '";'; + $cookieHeader .= ' $Port="' . $cookie['port'] . '";'; } } else { - $cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";"; + $cookieHeader .= ' ' . $name . '=' . $cookie['value'] . ";"; } } - $cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n"; + $cookieHeader = 'Cookie:' . $version . substr($cookieHeader, 0, -1) . "\r\n"; } // omit port if 80 @@ -524,12 +541,12 @@ class Client 'User-Agent: ' . $this->user_agent . "\r\n" . 'Host: ' . $server . $port . "\r\n" . $credentials . - $proxy_credentials . - $accepted_encoding . - $encoding_hdr . + $proxyCredentials . + $acceptedEncoding . + $encodingHdr . 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" . - $cookieheader . - 'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " . + $cookieHeader . + 'Content-Type: ' . $req->content_type . "\r\nContent-Length: " . strlen($payload) . "\r\n\r\n" . $payload; @@ -538,9 +555,9 @@ class Client } if ($timeout > 0) { - $fp = @fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout); + $fp = @fsockopen($connectServer, $connectPort, $this->errno, $this->errstr, $timeout); } else { - $fp = @fsockopen($connectserver, $connectport, $this->errno, $this->errstr); + $fp = @fsockopen($connectServer, $connectPort, $this->errno, $this->errstr); } if ($fp) { if ($timeout > 0 && function_exists('stream_set_timeout')) { @@ -572,47 +589,87 @@ class Client $ipd .= fread($fp, 32768); } while (!feof($fp)); fclose($fp); - $r = $msg->parseResponse($ipd, false, $this->return_type); + $r = $req->parseResponse($ipd, false, $this->return_type); return $r; } - private function sendPayloadHTTPS($msg, $server, $port, $timeout = 0, $username = '', - $password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '', - $proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1, - $keepalive = false, $key = '', $keypass = '', $sslversion = 0) + /** + * @param Request $req + * @param string $server + * @param int $port + * @param int $timeout + * @param string $username + * @param string $password + * @param int $authType + * @param string $cert + * @param string $certPass + * @param string $caCert + * @param string $caCertDir + * @param string $proxyHost + * @param int $proxyPort + * @param string $proxyUsername + * @param string $proxyPassword + * @param int $proxyAuthType + * @param bool $keepAlive + * @param string $key + * @param string $keyPass + * @param int $sslVersion + * @return Response + */ + protected function sendPayloadHTTPS($req, $server, $port, $timeout = 0, $username = '', + $password = '', $authType = 1, $cert = '', $certPass = '', $caCert = '', $caCertDir = '', + $proxyHost = '', $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, + $keepAlive = false, $key = '', $keyPass = '', $sslVersion = 0) { - $r = $this->sendPayloadCURL($msg, $server, $port, $timeout, $username, - $password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport, - $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass, $sslversion); - - return $r; + return $this->sendPayloadCURL($req, $server, $port, $timeout, $username, + $password, $authType, $cert, $certPass, $caCert, $caCertDir, $proxyHost, $proxyPort, + $proxyUsername, $proxyPassword, $proxyAuthType, 'https', $keepAlive, $key, $keyPass, $sslVersion); } /** * Contributed by Justin Miller * Requires curl to be built into PHP * NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers! + * + * @param Request $msg + * @param string $server + * @param int $port + * @param int $timeout + * @param string $username + * @param string $password + * @param int $authType + * @param string $cert + * @param string $certPass + * @param string $caCert + * @param string $caCertDir + * @param string $proxyHost + * @param int $proxyPort + * @param string $proxyUsername + * @param string $proxyPassword + * @param int $proxyAuthType + * @param string $method + * @param bool $keepAlive + * @param string $key + * @param string $keyPass + * @param int $sslVersion + * @return Response */ - private function sendPayloadCURL($msg, $server, $port, $timeout = 0, $username = '', - $password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '', - $proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1, $method = 'https', - $keepalive = false, $key = '', $keypass = '', $sslversion = 0) + protected function sendPayloadCURL($msg, $server, $port, $timeout = 0, $username = '', + $password = '', $authType = 1, $cert = '', $certPass = '', $caCert = '', $caCertDir = '', + $proxyHost = '', $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1, $method = 'https', + $keepAlive = false, $key = '', $keyPass = '', $sslVersion = 0) { if (!function_exists('curl_init')) { $this->errstr = 'CURL unavailable on this install'; - $r = new Response(0, PhpXmlRpc::$xmlrpcerr['no_curl'], PhpXmlRpc::$xmlrpcstr['no_curl']); - - return $r; + return new Response(0, PhpXmlRpc::$xmlrpcerr['no_curl'], PhpXmlRpc::$xmlrpcstr['no_curl']); } if ($method == 'https') { if (($info = curl_version()) && ((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))) ) { $this->errstr = 'SSL unavailable on this install'; - $r = new Response(0, PhpXmlRpc::$xmlrpcerr['no_ssl'], PhpXmlRpc::$xmlrpcstr['no_ssl']); - - return $r; + return new Response(0, PhpXmlRpc::$xmlrpcerr['no_ssl'], PhpXmlRpc::$xmlrpcstr['no_ssl']); } } @@ -636,17 +693,17 @@ class Client $a = @gzencode($payload); if ($a) { $payload = $a; - $encoding_hdr = 'Content-Encoding: gzip'; + $encodingHdr = 'Content-Encoding: gzip'; } } else { $a = @gzcompress($payload); if ($a) { $payload = $a; - $encoding_hdr = 'Content-Encoding: deflate'; + $encodingHdr = 'Content-Encoding: deflate'; } } } else { - $encoding_hdr = ''; + $encodingHdr = ''; } if ($this->debug > 1) { @@ -655,9 +712,9 @@ class Client flush(); } - if (!$keepalive || !$this->xmlrpc_curl_handle) { + if (!$keepAlive || !$this->xmlrpc_curl_handle) { $curl = curl_init($method . '://' . $server . ':' . $port . $this->path); - if ($keepalive) { + if ($keepAlive) { $this->xmlrpc_curl_handle = $curl; } } else { @@ -694,12 +751,12 @@ class Client // extra headers $headers = array('Content-Type: ' . $msg->content_type, 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings)); // if no keepalive is wanted, let the server know it in advance - if (!$keepalive) { + if (!$keepAlive) { $headers[] = 'Connection: close'; } // request compression header - if ($encoding_hdr) { - $headers[] = $encoding_hdr; + if ($encodingHdr) { + $headers[] = $encodingHdr; } curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); @@ -711,8 +768,8 @@ class Client if ($username && $password) { curl_setopt($curl, CURLOPT_USERPWD, $username . ':' . $password); if (defined('CURLOPT_HTTPAUTH')) { - curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype); - } elseif ($authtype != 1) { + curl_setopt($curl, CURLOPT_HTTPAUTH, $authType); + } elseif ($authType != 1) { error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install'); } } @@ -723,44 +780,43 @@ class Client curl_setopt($curl, CURLOPT_SSLCERT, $cert); } // set cert password - if ($certpass) { - curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass); + if ($certPass) { + curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certPass); } // whether to verify remote host's cert curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer); // set ca certificates file/dir - if ($cacert) { - curl_setopt($curl, CURLOPT_CAINFO, $cacert); + if ($caCert) { + curl_setopt($curl, CURLOPT_CAINFO, $caCert); } - if ($cacertdir) { - curl_setopt($curl, CURLOPT_CAPATH, $cacertdir); + if ($caCertDir) { + curl_setopt($curl, CURLOPT_CAPATH, $caCertDir); } // set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?) if ($key) { curl_setopt($curl, CURLOPT_SSLKEY, $key); } // set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?) - if ($keypass) { - curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass); + if ($keyPass) { + curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keyPass); } // whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost); // allow usage of different SSL versions - curl_setopt($curl, CURLOPT_SSLVERSION, $sslversion); + curl_setopt($curl, CURLOPT_SSLVERSION, $sslVersion); } // proxy info - if ($proxyhost) { - if ($proxyport == 0) { - $proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080 + if ($proxyHost) { + if ($proxyPort == 0) { + $proxyPort = 8080; // NB: even for HTTPS, local connection is on port 8080 } - curl_setopt($curl, CURLOPT_PROXY, $proxyhost . ':' . $proxyport); - //curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport); - if ($proxyusername) { - curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername . ':' . $proxypassword); + curl_setopt($curl, CURLOPT_PROXY, $proxyHost . ':' . $proxyPort); + if ($proxyUsername) { + curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyUsername . ':' . $proxyPassword); if (defined('CURLOPT_PROXYAUTH')) { - curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype); - } elseif ($proxyauthtype != 1) { + curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyAuthType); + } elseif ($proxyAuthType != 1) { error_log('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install'); } } @@ -770,11 +826,11 @@ class Client // the following code does not honour 'expires', 'path' and 'domain' cookie attributes // set to client obj the the user... if (count($this->cookies)) { - $cookieheader = ''; + $cookieHeader = ''; foreach ($this->cookies as $name => $cookie) { - $cookieheader .= $name . '=' . $cookie['value'] . '; '; + $cookieHeader .= $name . '=' . $cookie['value'] . '; '; } - curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2)); + curl_setopt($curl, CURLOPT_COOKIE, substr($cookieHeader, 0, -2)); } foreach ($this->extracurlopts as $opt => $val) { @@ -801,16 +857,16 @@ class Client $this->errstr = 'no response'; $resp = new Response(0, PhpXmlRpc::$xmlrpcerr['curl_fail'], PhpXmlRpc::$xmlrpcstr['curl_fail'] . ': ' . curl_error($curl)); curl_close($curl); - if ($keepalive) { + if ($keepAlive) { $this->xmlrpc_curl_handle = null; } } else { - if (!$keepalive) { + if (!$keepAlive) { curl_close($curl); } $resp = $msg->parseResponse($result, true, $this->return_type); // if we got back a 302, we can not reuse the curl handle for later calls - if ($resp->faultCode() == PhpXmlRpc::$xmlrpcerr['http_error'] && $keepalive) { + if ($resp->faultCode() == PhpXmlRpc::$xmlrpcerr['http_error'] && $keepAlive) { curl_close($curl); $this->xmlrpc_curl_handle = null; } @@ -834,20 +890,20 @@ class Client * NB: trying to shoehorn extra functionality into existing syntax has resulted * in pretty much convoluted code... * - * @param Request[] $msgs an array of Request objects + * @param Request[] $reqs an array of Request objects * @param integer $timeout connection timeout (in seconds) * @param string $method the http protocol variant to be used * @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be attempted * * @return array */ - public function multicall($msgs, $timeout = 0, $method = '', $fallback = true) + public function multicall($reqs, $timeout = 0, $method = '', $fallback = true) { if ($method == '') { $method = $this->method; } if (!$this->no_multicall) { - $results = $this->_try_multicall($msgs, $timeout, $method); + $results = $this->_try_multicall($reqs, $timeout, $method); if (is_array($results)) { // System.multicall succeeded return $results; @@ -875,14 +931,14 @@ class Client if ($fallback) { // system.multicall is (probably) unsupported by server: // emulate multicall via multiple requests - foreach ($msgs as $msg) { - $results[] = $this->send($msg, $timeout, $method); + foreach ($reqs as $req) { + $results[] = $this->send($req, $timeout, $method); } } else { // user does NOT want to fallback on many single calls: // since we should always return an array of responses, // return an array with the same error repeated n times - foreach ($msgs as $msg) { + foreach ($reqs as $req) { $results[] = $result; } } @@ -891,29 +947,34 @@ class Client } /** - * Attempt to boxcar $msgs via system.multicall. + * Attempt to boxcar $reqs via system.multicall. * Returns either an array of xmlrpc reponses, an xmlrpc error response * or false (when received response does not respect valid multicall syntax). + * + * @param Request[] $reqs + * @param int $timeout + * @param string $method + * @return array|bool|mixed|Response */ - private function _try_multicall($msgs, $timeout, $method) + private function _try_multicall($reqs, $timeout, $method) { // Construct multicall request $calls = array(); - foreach ($msgs as $msg) { - $call['methodName'] = new Value($msg->method(), 'string'); - $numParams = $msg->getNumParams(); + foreach ($reqs as $req) { + $call['methodName'] = new Value($req->method(), 'string'); + $numParams = $req->getNumParams(); $params = array(); for ($i = 0; $i < $numParams; $i++) { - $params[$i] = $msg->getParam($i); + $params[$i] = $req->getParam($i); } $call['params'] = new Value($params, 'array'); $calls[] = new Value($call, 'struct'); } - $multicall = new Request('system.multicall'); - $multicall->addParam(new Value($calls, 'array')); + $multiCall = new Request('system.multicall'); + $multiCall->addParam(new Value($calls, 'array')); // Attempt RPC call - $result = $this->send($multicall, $timeout, $method); + $result = $this->send($multiCall, $timeout, $method); if ($result->faultCode() != 0) { // call to system.multicall failed @@ -932,7 +993,7 @@ class Client return false; // bad return type from system.multicall } $numRets = count($rets); - if ($numRets != count($msgs)) { + if ($numRets != count($reqs)) { return false; // wrong number of return values. } @@ -976,7 +1037,7 @@ class Client return false; // bad return type from system.multicall } $numRets = $rets->arraysize(); - if ($numRets != count($msgs)) { + if ($numRets != count($reqs)) { return false; // wrong number of return values. } diff --git a/src/Encoder.php b/src/Encoder.php index 8c63958..f723889 100644 --- a/src/Encoder.php +++ b/src/Encoder.php @@ -23,39 +23,39 @@ class Encoder * * @author Dan Libby (dan@libby.com) * - * @param Value|Request $xmlrpc_val + * @param Value|Request $xmlrpcVal * @param array $options if 'decode_php_objs' is set in the options array, xmlrpc structs can be decoded into php objects; if 'dates_as_objects' is set xmlrpc datetimes are decoded as php DateTime objects (standard is * * @return mixed */ - public function decode($xmlrpc_val, $options = array()) + public function decode($xmlrpcVal, $options = array()) { - switch ($xmlrpc_val->kindOf()) { + switch ($xmlrpcVal->kindOf()) { case 'scalar': if (in_array('extension_api', $options)) { - reset($xmlrpc_val->me); - list($typ, $val) = each($xmlrpc_val->me); + reset($xmlrpcVal->me); + list($typ, $val) = each($xmlrpcVal->me); switch ($typ) { case 'dateTime.iso8601': - $xmlrpc_val->scalar = $val; - $xmlrpc_val->type = 'datetime'; - $xmlrpc_val->timestamp = \PhpXmlRpc\Helper\Date::iso8601_decode($val); + $xmlrpcVal->scalar = $val; + $xmlrpcVal->type = 'datetime'; + $xmlrpcVal->timestamp = \PhpXmlRpc\Helper\Date::iso8601_decode($val); - return $xmlrpc_val; + return $xmlrpcVal; case 'base64': - $xmlrpc_val->scalar = $val; - $xmlrpc_val->type = $typ; + $xmlrpcVal->scalar = $val; + $xmlrpcVal->type = $typ; - return $xmlrpc_val; + return $xmlrpcVal; default: - return $xmlrpc_val->scalarval(); + return $xmlrpcVal->scalarval(); } } - if (in_array('dates_as_objects', $options) && $xmlrpc_val->scalartyp() == 'dateTime.iso8601') { + if (in_array('dates_as_objects', $options) && $xmlrpcVal->scalartyp() == 'dateTime.iso8601') { // we return a Datetime object instead of a string // since now the constructor of xmlrpc value accepts safely strings, ints and datetimes, // we cater to all 3 cases here - $out = $xmlrpc_val->scalarval(); + $out = $xmlrpcVal->scalarval(); if (is_string($out)) { $out = strtotime($out); } @@ -69,43 +69,43 @@ class Encoder } } - return $xmlrpc_val->scalarval(); + return $xmlrpcVal->scalarval(); case 'array': - $size = $xmlrpc_val->arraysize(); + $size = $xmlrpcVal->arraysize(); $arr = array(); for ($i = 0; $i < $size; $i++) { - $arr[] = $this->decode($xmlrpc_val->arraymem($i), $options); + $arr[] = $this->decode($xmlrpcVal->arraymem($i), $options); } return $arr; case 'struct': - $xmlrpc_val->structreset(); + $xmlrpcVal->structreset(); // If user said so, try to rebuild php objects for specific struct vals. /// @todo should we raise a warning for class not found? // shall we check for proper subclass of xmlrpc value instead of // presence of _php_class to detect what we can do? - if (in_array('decode_php_objs', $options) && $xmlrpc_val->_php_class != '' - && class_exists($xmlrpc_val->_php_class) + if (in_array('decode_php_objs', $options) && $xmlrpcVal->_php_class != '' + && class_exists($xmlrpcVal->_php_class) ) { - $obj = @new $xmlrpc_val->_php_class(); - while (list($key, $value) = $xmlrpc_val->structeach()) { + $obj = @new $xmlrpcVal->_php_class(); + while (list($key, $value) = $xmlrpcVal->structeach()) { $obj->$key = $this->decode($value, $options); } return $obj; } else { $arr = array(); - while (list($key, $value) = $xmlrpc_val->structeach()) { + while (list($key, $value) = $xmlrpcVal->structeach()) { $arr[$key] = $this->decode($value, $options); } return $arr; } case 'msg': - $paramcount = $xmlrpc_val->getNumParams(); + $paramCount = $xmlrpcVal->getNumParams(); $arr = array(); - for ($i = 0; $i < $paramcount; $i++) { - $arr[] = $this->decode($xmlrpc_val->getParam($i)); + for ($i = 0; $i < $paramCount; $i++) { + $arr[] = $this->decode($xmlrpcVal->getParam($i)); } return $arr; @@ -130,39 +130,39 @@ class Encoder * * @return \PhpXmlrpc\Value */ - public function encode($php_val, $options = array()) + public function encode($phpVal, $options = array()) { - $type = gettype($php_val); + $type = gettype($phpVal); switch ($type) { case 'string': - if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val)) { - $xmlrpc_val = new Value($php_val, Value::$xmlrpcDateTime); + if (in_array('auto_dates', $options) && preg_match('/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $phpVal)) { + $xmlrpcVal = new Value($phpVal, Value::$xmlrpcDateTime); } else { - $xmlrpc_val = new Value($php_val, Value::$xmlrpcString); + $xmlrpcVal = new Value($phpVal, Value::$xmlrpcString); } break; case 'integer': - $xmlrpc_val = new Value($php_val, Value::$xmlrpcInt); + $xmlrpcVal = new Value($phpVal, Value::$xmlrpcInt); break; case 'double': - $xmlrpc_val = new Value($php_val, Value::$xmlrpcDouble); + $xmlrpcVal = new Value($phpVal, Value::$xmlrpcDouble); break; // // Add support for encoding/decoding of booleans, since they are supported in PHP case 'boolean': - $xmlrpc_val = new Value($php_val, Value::$xmlrpcBoolean); + $xmlrpcVal = new Value($phpVal, Value::$xmlrpcBoolean); break; // case 'array': // PHP arrays can be encoded to either xmlrpc structs or arrays, // depending on wheter they are hashes or plain 0..n integer indexed // A shorter one-liner would be - // $tmp = array_diff(array_keys($php_val), range(0, count($php_val)-1)); + // $tmp = array_diff(array_keys($phpVal), range(0, count($phpVal)-1)); // but execution time skyrockets! $j = 0; $arr = array(); $ko = false; - foreach ($php_val as $key => $val) { + foreach ($phpVal as $key => $val) { $arr[$key] = $this->encode($val, $options); if (!$ko && $key !== $j) { $ko = true; @@ -170,67 +170,67 @@ class Encoder $j++; } if ($ko) { - $xmlrpc_val = new Value($arr, Value::$xmlrpcStruct); + $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct); } else { - $xmlrpc_val = new Value($arr, Value::$xmlrpcArray); + $xmlrpcVal = new Value($arr, Value::$xmlrpcArray); } break; case 'object': - if (is_a($php_val, 'PhpXmlRpc\Value')) { - $xmlrpc_val = $php_val; - } elseif (is_a($php_val, 'DateTime')) { - $xmlrpc_val = new Value($php_val->format('Ymd\TH:i:s'), Value::$xmlrpcStruct); + if (is_a($phpVal, 'PhpXmlRpc\Value')) { + $xmlrpcVal = $phpVal; + } elseif (is_a($phpVal, 'DateTime')) { + $xmlrpcVal = new Value($phpVal->format('Ymd\TH:i:s'), Value::$xmlrpcStruct); } else { $arr = array(); - reset($php_val); - while (list($k, $v) = each($php_val)) { + reset($phpVal); + while (list($k, $v) = each($phpVal)) { $arr[$k] = $this->encode($v, $options); } - $xmlrpc_val = new Value($arr, Value::$xmlrpcStruct); + $xmlrpcVal = new Value($arr, Value::$xmlrpcStruct); if (in_array('encode_php_objs', $options)) { // let's save original class name into xmlrpc value: // might be useful later on... - $xmlrpc_val->_php_class = get_class($php_val); + $xmlrpcVal->_php_class = get_class($phpVal); } } break; case 'NULL': if (in_array('extension_api', $options)) { - $xmlrpc_val = new Value('', Value::$xmlrpcString); + $xmlrpcVal = new Value('', Value::$xmlrpcString); } elseif (in_array('null_extension', $options)) { - $xmlrpc_val = new Value('', Value::$xmlrpcNull); + $xmlrpcVal = new Value('', Value::$xmlrpcNull); } else { - $xmlrpc_val = new Value(); + $xmlrpcVal = new Value(); } break; case 'resource': if (in_array('extension_api', $options)) { - $xmlrpc_val = new Value((int)$php_val, Value::$xmlrpcInt); + $xmlrpcVal = new Value((int)$phpVal, Value::$xmlrpcInt); } else { - $xmlrpc_val = new Value(); + $xmlrpcVal = new Value(); } // catch "user function", "unknown type" default: // giancarlo pinerolo // it has to return // an empty object in case, not a boolean. - $xmlrpc_val = new Value(); + $xmlrpcVal = new Value(); break; } - return $xmlrpc_val; + return $xmlrpcVal; } /** * Convert the xml representation of a method response, method request or single * xmlrpc value into the appropriate object (a.k.a. deserialize). * - * @param string $xml_val + * @param string $xmlVal * @param array $options * * @return mixed false on error, or an instance of either Value, Request or Response */ - public function decode_xml($xml_val, $options = array()) + public function decode_xml($xmlVal, $options = array()) { /// @todo 'guestimate' encoding @@ -250,7 +250,7 @@ class Encoder xml_set_element_handler($parser, 'xmlrpc_se_any', 'xmlrpc_ee'); xml_set_character_data_handler($parser, 'xmlrpc_cd'); xml_set_default_handler($parser, 'xmlrpc_dh'); - if (!xml_parse($parser, $xml_val, 1)) { + if (!xml_parse($parser, $xmlVal, 1)) { $errstr = sprintf('XML error: %s at line %d, column %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser), xml_get_current_column_number($parser)); @@ -300,14 +300,14 @@ class Encoder * we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of unconforming (legacy?) clients/servers, * which will be most probably using UTF-8 anyway... * - * @param string $httpheader the http Content-type header - * @param string $xmlchunk xml content buffer - * @param string $encoding_prefs comma separated list of character encodings to be used as default (when mb extension is enabled) + * @param string $httpHeader the http Content-type header + * @param string $xmlChunk xml content buffer + * @param string $encodingPrefs comma separated list of character encodings to be used as default (when mb extension is enabled) * @return string * * @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!! */ - public static function guess_encoding($httpheader = '', $xmlchunk = '', $encoding_prefs = null) + public static function guess_encoding($httpHeader = '', $xmlChunk = '', $encodingPrefs = null) { // discussion: see http://www.yale.edu/pclt/encoding/ // 1 - test if encoding is specified in HTTP HEADERS @@ -325,7 +325,7 @@ class Encoder /// @todo this test will pass if ANY header has charset specification, not only Content-Type. Fix it? $matches = array(); - if (preg_match('/;\s*charset\s*=([^;]+)/i', $httpheader, $matches)) { + if (preg_match('/;\s*charset\s*=([^;]+)/i', $httpHeader, $matches)) { return strtoupper(trim($matches[1], " \t\"")); } @@ -336,11 +336,11 @@ class Encoder // in the xml declaration, and verify if they match. /// @todo implement check as described above? /// @todo implement check for first bytes of string even without a BOM? (It sure looks harder than for cases WITH a BOM) - if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk)) { + if (preg_match('/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlChunk)) { return 'UCS-4'; - } elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk)) { + } elseif (preg_match('/^(\xFE\xFF|\xFF\xFE)/', $xmlChunk)) { return 'UTF-16'; - } elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk)) { + } elseif (preg_match('/^(\xEF\xBB\xBF)/', $xmlChunk)) { return 'UTF-8'; } @@ -350,17 +350,17 @@ class Encoder // EQ: SPACE?=SPACE? === [ \x9\xD\xA]*=[ \x9\xD\xA]* if (preg_match('/^<\?xml\s+version\s*=\s*' . "((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))" . '\s+encoding\s*=\s*' . "((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/", - $xmlchunk, $matches)) { + $xmlChunk, $matches)) { return strtoupper(substr($matches[2], 1, -1)); } // 4 - if mbstring is available, let it do the guesswork // NB: we favour finding an encoding that is compatible with what we can process if (extension_loaded('mbstring')) { - if ($encoding_prefs) { - $enc = mb_detect_encoding($xmlchunk, $encoding_prefs); + if ($encodingPrefs) { + $enc = mb_detect_encoding($xmlChunk, $encodingPrefs); } else { - $enc = mb_detect_encoding($xmlchunk); + $enc = mb_detect_encoding($xmlChunk); } // NB: mb_detect likes to call it ascii, xml parser likes to call it US_ASCII... // IANA also likes better US-ASCII, so go with it diff --git a/src/Request.php b/src/Request.php index 4009a13..12cbf68 100644 --- a/src/Request.php +++ b/src/Request.php @@ -29,10 +29,10 @@ class Request } } - public function xml_header($charset_encoding = '') + public function xml_header($charsetEncoding = '') { - if ($charset_encoding != '') { - return "\n\n"; + if ($charsetEncoding != '') { + return "\n\n"; } else { return "\n\n"; } @@ -43,18 +43,18 @@ class Request return ''; } - public function createPayload($charset_encoding = '') + public function createPayload($charsetEncoding = '') { - if ($charset_encoding != '') { - $this->content_type = 'text/xml; charset=' . $charset_encoding; + if ($charsetEncoding != '') { + $this->content_type = 'text/xml; charset=' . $charsetEncoding; } else { $this->content_type = 'text/xml'; } - $this->payload = $this->xml_header($charset_encoding); + $this->payload = $this->xml_header($charsetEncoding); $this->payload .= '' . $this->methodname . "\n"; $this->payload .= "\n"; foreach ($this->params as $p) { - $this->payload .= "\n" . $p->serialize($charset_encoding) . + $this->payload .= "\n" . $p->serialize($charsetEncoding) . "\n"; } $this->payload .= "\n"; @@ -80,13 +80,13 @@ class Request /** * Returns xml representation of the message. XML prologue included. * - * @param string $charset_encoding + * @param string $charsetEncoding * * @return string the xml representation of the message, xml prologue included */ - public function serialize($charset_encoding = '') + public function serialize($charsetEncoding = '') { - $this->createPayload($charset_encoding); + $this->createPayload($charsetEncoding); return $this->payload; } @@ -160,12 +160,12 @@ class Request * Parse the xmlrpc response contained in the string $data and return a Response object. * * @param string $data the xmlrpc response, eventually including http headers - * @param bool $headers_processed when true prevents parsing HTTP headers for interpretation of content-encoding and consequent decoding - * @param string $return_type decides return type, i.e. content of response->value(). Either 'xmlrpcvals', 'xml' or 'phpvals' + * @param bool $headersProcessed when true prevents parsing HTTP headers for interpretation of content-encoding and consequent decoding + * @param string $returnType decides return type, i.e. content of response->value(). Either 'xmlrpcvals', 'xml' or 'phpvals' * * @return Response */ - public function parseResponse($data = '', $headers_processed = false, $return_type = 'xmlrpcvals') + public function parseResponse($data = '', $headersProcessed = false, $returnType = 'xmlrpcvals') { if ($this->debug) { // by maHo, replaced htmlspecialchars with htmlentities @@ -183,7 +183,7 @@ class Request if (substr($data, 0, 4) == 'HTTP') { $httpParser = new Http(); try { - $this->httpResponse = $httpParser->parseResponseHeaders($data, $headers_processed, $this->debug); + $this->httpResponse = $httpParser->parseResponseHeaders($data, $headersProcessed, $this->debug); } catch(\Exception $e) { $r = new Response(0, $e->getCode(), $e->getMessage()); // failed processing of HTTP response headers @@ -217,7 +217,7 @@ class Request } // if user wants back raw xml, give it to him - if ($return_type == 'xml') { + if ($returnType == 'xml') { $r = new Response($data, 0, '', 'xml'); $r->hdrs = $this->httpResponse['headers']; $r->_cookies = $this->httpResponse['cookies']; @@ -256,7 +256,7 @@ class Request $xmlRpcParser = new XMLParser(); xml_set_object($parser, $xmlRpcParser); - if ($return_type == 'phpvals') { + if ($returnType == 'phpvals') { xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee_fast'); } else { xml_set_element_handler($parser, 'xmlrpc_se', 'xmlrpc_ee'); @@ -269,17 +269,17 @@ class Request if (!xml_parse($parser, $data, count($data))) { // thanks to Peter Kocks if ((xml_get_current_line_number($parser)) == 1) { - $errstr = 'XML error at line 1, check URL'; + $errStr = 'XML error at line 1, check URL'; } else { - $errstr = sprintf('XML error: %s at line %d, column %d', + $errStr = sprintf('XML error: %s at line %d, column %d', xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser), xml_get_current_column_number($parser)); } - error_log($errstr); - $r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_return'], PhpXmlRpc::$xmlrpcstr['invalid_return'] . ' (' . $errstr . ')'); + error_log($errStr); + $r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_return'], PhpXmlRpc::$xmlrpcstr['invalid_return'] . ' (' . $errStr . ')'); xml_parser_free($parser); if ($this->debug) { - print $errstr; + print $errStr; } $r->hdrs = $this->httpResponse['headers']; $r->_cookies = $this->httpResponse['cookies']; @@ -299,7 +299,7 @@ class Request } // third error check: parsing of the response has somehow gone boink. // NB: shall we omit this check, since we trust the parsing code? - elseif ($return_type == 'xmlrpcvals' && !is_object($xmlRpcParser->_xh['value'])) { + elseif ($returnType == 'xmlrpcvals' && !is_object($xmlRpcParser->_xh['value'])) { // something odd has happened // and it's time to generate a client side error // indicating something odd went on @@ -318,24 +318,24 @@ class Request if ($xmlRpcParser->_xh['isf']) { /// @todo we should test here if server sent an int and a string, /// and/or coerce them into such... - if ($return_type == 'xmlrpcvals') { - $errno_v = $v->structmem('faultCode'); - $errstr_v = $v->structmem('faultString'); - $errno = $errno_v->scalarval(); - $errstr = $errstr_v->scalarval(); + if ($returnType == 'xmlrpcvals') { + $errNo_v = $v->structmem('faultCode'); + $errStr_v = $v->structmem('faultString'); + $errNo = $errNo_v->scalarval(); + $errStr = $errStr_v->scalarval(); } else { - $errno = $v['faultCode']; - $errstr = $v['faultString']; + $errNo = $v['faultCode']; + $errStr = $v['faultString']; } - if ($errno == 0) { + if ($errNo == 0) { // FAULT returned, errno needs to reflect that - $errno = -1; + $errNo = -1; } - $r = new Response(0, $errno, $errstr); + $r = new Response(0, $errNo, $errStr); } else { - $r = new Response($v, 0, '', $return_type); + $r = new Response($v, 0, '', $returnType); } } @@ -350,6 +350,7 @@ class Request * Echoes a debug message, taking care of escaping it when not in console mode * * @param string $message + * @param bool $encodeEntities when false, escapes using htmlspecialchars instead of htmlentities */ protected function debugMessage($message, $encodeEntities = true) { diff --git a/src/Server.php b/src/Server.php index ccf6c8c..ec9ebb4 100644 --- a/src/Server.php +++ b/src/Server.php @@ -71,10 +71,10 @@ class Server public static $_xmlrpcs_prev_ehandler = ''; /** - * @param array $dispmap the dispatch map with definition of exposed services + * @param array $dispatchMap the dispatch map with definition of exposed services * @param boolean $servicenow set to false to prevent the server from running upon construction */ - public function __construct($dispMap = null, $serviceNow = true) + public function __construct($dispatchMap = null, $serviceNow = true) { // if ZLIB is enabled, let the server by default accept compressed requests, // and compress responses sent to clients that support them @@ -95,8 +95,8 @@ class Server * instead, you can use the class add_to_map() function * to add functions manually (borrowed from SOAPX4) */ - if ($dispMap) { - $this->dmap = $dispMap; + if ($dispatchMap) { + $this->dmap = $dispatchMap; if ($serviceNow) { $this->service(); } @@ -106,7 +106,7 @@ class Server /** * Set debug level of server. * - * @param integer $in debug lvl: determines info added to xmlrpc responses (as xml comments) + * @param integer $level debug lvl: determines info added to xmlrpc responses (as xml comments) * 0 = no debug info, * 1 = msgs set from user with debugmsg(), * 2 = add complete xmlrpc request (headers and body), @@ -117,9 +117,9 @@ class Server * execution anymore, but just end up logged in the xmlrpc response) * Note that info added at level 2 and 3 will be base64 encoded */ - public function setDebug($in) + public function setDebug($level) { - $this->debug = $in; + $this->debug = $level; } /** @@ -128,27 +128,27 @@ class Server * Note that for best compatibility, the debug string should be encoded using * the PhpXmlRpc::$xmlrpc_internalencoding character set. * - * @param string $m + * @param string $msg * @access public */ - public static function xmlrpc_debugmsg($m) + public static function xmlrpc_debugmsg($msg) { - static::$_xmlrpc_debuginfo .= $m . "\n"; + static::$_xmlrpc_debuginfo .= $msg . "\n"; } - public static function error_occurred($m) + public static function error_occurred($msg) { - static::$_xmlrpcs_occurred_errors .= $m . "\n"; + static::$_xmlrpcs_occurred_errors .= $msg . "\n"; } /** * Return a string with the serialized representation of all debug info. * - * @param string $charset_encoding the target charset encoding for the serialization + * @param string $charsetEncoding the target charset encoding for the serialization * * @return string an XML comment (or two) */ - public function serializeDebug($charset_encoding = '') + public function serializeDebug($charsetEncoding = '') { // Tough encoding problem: which internal charset should we assume for debug info? // It might contain a copy of raw data received from client, ie with unknown encoding, @@ -160,7 +160,7 @@ class Server $out .= "\n"; } if (static::$_xmlrpc_debuginfo != '') { - $out .= "\n"; + $out .= "\n"; // NB: a better solution MIGHT be to use CDATA, but we need to insert it // into return payload AFTER the beginning tag //$out .= "', ']_]_>', static::$_xmlrpc_debuginfo) . "\n]]>\n"; @@ -173,16 +173,16 @@ class Server * Execute the xmlrpc request, printing the response. * * @param string $data the request body. If null, the http POST request will be examined - * @param bool $return_payload When true, return the response but do not echo it or any http header + * @param bool $returnPayload When true, return the response but do not echo it or any http header * * @return Response the response object (usually not used by caller...) */ - public function service($data = null, $return_payload = false) + public function service($data = null, $returnPayload = false) { if ($data === null) { $data = file_get_contents('php://input'); } - $raw_data = $data; + $rawData = $data; // reset internal debug info $this->debug_info = ''; @@ -192,32 +192,32 @@ class Server $this->debugmsg("+++GOT+++\n" . $data . "\n+++END+++"); } - $r = $this->parseRequestHeaders($data, $req_charset, $resp_charset, $resp_encoding); + $r = $this->parseRequestHeaders($data, $reqCharset, $respCharset, $respEncoding); if (!$r) { - $r = $this->parseRequest($data, $req_charset); + $r = $this->parseRequest($data, $reqCharset); } // save full body of request into response, for more debugging usages - $r->raw_data = $raw_data; + $r->raw_data = $rawData; if ($this->debug > 2 && static::$_xmlrpcs_occurred_errors) { $this->debugmsg("+++PROCESSING ERRORS AND WARNINGS+++\n" . static::$_xmlrpcs_occurred_errors . "+++END+++"); } - $payload = $this->xml_header($resp_charset); + $payload = $this->xml_header($respCharset); if ($this->debug > 0) { - $payload = $payload . $this->serializeDebug($resp_charset); + $payload = $payload . $this->serializeDebug($respCharset); } // G. Giunta 2006-01-27: do not create response serialization if it has // already happened. Helps building json magic if (empty($r->payload)) { - $r->serialize($resp_charset); + $r->serialize($respCharset); } $payload = $payload . $r->payload; - if ($return_payload) { + if ($returnPayload) { return $payload; } @@ -232,15 +232,15 @@ class Server // http compression of output: only // if we can do it, and we want to do it, and client asked us to, // and php ini settings do not force it already - $php_no_self_compress = !ini_get('zlib.output_compression') && (ini_get('output_handler') != 'ob_gzhandler'); - if ($this->compress_response && function_exists('gzencode') && $resp_encoding != '' - && $php_no_self_compress + $phpNoSelfCompress = !ini_get('zlib.output_compression') && (ini_get('output_handler') != 'ob_gzhandler'); + if ($this->compress_response && function_exists('gzencode') && $respEncoding != '' + && $phpNoSelfCompress ) { - if (strpos($resp_encoding, 'gzip') !== false) { + if (strpos($respEncoding, 'gzip') !== false) { $payload = gzencode($payload); header("Content-Encoding: gzip"); header("Vary: Accept-Encoding"); - } elseif (strpos($resp_encoding, 'deflate') !== false) { + } elseif (strpos($respEncoding, 'deflate') !== false) { $payload = gzcompress($payload); header("Content-Encoding: deflate"); header("Vary: Accept-Encoding"); @@ -249,7 +249,7 @@ class Server // do not output content-length header if php is compressing output for us: // it will mess up measurements - if ($php_no_self_compress) { + if ($phpNoSelfCompress) { header('Content-Length: ' . (int)strlen($payload)); } } else { @@ -265,23 +265,23 @@ class Server /** * Add a method to the dispatch map. * - * @param string $methodname the name with which the method will be made available + * @param string $methodName the name with which the method will be made available * @param string $function the php function that will get invoked * @param array $sig the array of valid method signatures * @param string $doc method documentation - * @param array $sigdoc the array of valid method signatures docs (one string per param, one for return type) + * @param array $sigDoc the array of valid method signatures docs (one string per param, one for return type) */ - public function add_to_map($methodname, $function, $sig = null, $doc = false, $sigdoc = false) + public function add_to_map($methodName, $function, $sig = null, $doc = false, $sigDoc = false) { - $this->dmap[$methodname] = array( + $this->dmap[$methodName] = array( 'function' => $function, 'docstring' => $doc, ); if ($sig) { - $this->dmap[$methodname]['signature'] = $sig; + $this->dmap[$methodName]['signature'] = $sig; } - if ($sigdoc) { - $this->dmap[$methodname]['signature_docs'] = $sigdoc; + if ($sigDoc) { + $this->dmap[$methodName]['signature_docs'] = $sigDoc; } } @@ -342,7 +342,7 @@ class Server * * @return mixed null on success or a Response */ - protected function parseRequestHeaders(&$data, &$req_encoding, &$resp_encoding, &$resp_compression) + protected function parseRequestHeaders(&$data, &$reqEncoding, &$respEncoding, &$resp_compression) { // check if $_SERVER is populated: it might have been disabled via ini file // (this is true even when in CLI mode) @@ -397,7 +397,7 @@ class Server // check if client specified accepted charsets, and if we know how to fulfill // the request if ($this->response_charset_encoding == 'auto') { - $resp_encoding = ''; + $respEncoding = ''; if (isset($_SERVER['HTTP_ACCEPT_CHARSET'])) { // here we should check if we can match the client-requested encoding // with the encodings we know we can generate. @@ -408,17 +408,17 @@ class Server foreach ($known_charsets as $charset) { foreach ($client_accepted_charsets as $accepted) { if (strpos($accepted, $charset) === 0) { - $resp_encoding = $charset; + $respEncoding = $charset; break; } } - if ($resp_encoding) { + if ($respEncoding) { break; } } } } else { - $resp_encoding = $this->response_charset_encoding; + $respEncoding = $this->response_charset_encoding; } if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { @@ -429,7 +429,7 @@ class Server // 'guestimate' request encoding /// @todo check if mbstring is enabled and automagic input conversion is on: it might mingle with this check??? - $req_encoding = Encoder::guess_encoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '', + $reqEncoding = Encoder::guess_encoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '', $data); return; @@ -440,11 +440,11 @@ class Server * php function registered with the server. * * @param string $data the xml request - * @param string $req_encoding (optional) the charset encoding of the xml request + * @param string $reqEncoding (optional) the charset encoding of the xml request * * @return Response */ - public function parseRequest($data, $req_encoding = '') + public function parseRequest($data, $reqEncoding = '') { // 2005/05/07 commented and moved into caller function code //if($data=='') @@ -457,19 +457,19 @@ class Server //$data = xmlrpc_html_entity_xlate($data); // decompose incoming XML into request structure - if ($req_encoding != '') { - if (!in_array($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) { + if ($reqEncoding != '') { + if (!in_array($reqEncoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) { // the following code might be better for mb_string enabled installs, but // makes the lib about 200% slower... - //if (!is_valid_charset($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) + //if (!is_valid_charset($reqEncoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) - error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding); - $req_encoding = PhpXmlRpc::$xmlrpc_defencoding; + error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding); + $reqEncoding = PhpXmlRpc::$xmlrpc_defencoding; } /// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue, // the encoding is not UTF8 and there are non-ascii chars in the text... /// @todo use an empty string for php 5 ??? - $parser = xml_parser_create($req_encoding); + $parser = xml_parser_create($reqEncoding); } else { $parser = xml_parser_create(); } @@ -544,11 +544,11 @@ class Server * * @param mixed $m either a Request obj or a method name * @param array $params array with method parameters as php types (if m is method name only) - * @param array $paramtypes array with xmlrpc types of method parameters (if m is method name only) + * @param array $paramTypes array with xmlrpc types of method parameters (if m is method name only) * * @return Response */ - protected function execute($m, $params = null, $paramtypes = null) + protected function execute($m, $params = null, $paramTypes = null) { if (is_object($m)) { $methName = $m->method(); @@ -569,9 +569,9 @@ class Server if (isset($dmap[$methName]['signature'])) { $sig = $dmap[$methName]['signature']; if (is_object($m)) { - list($ok, $errstr) = $this->verifySignature($m, $sig); + list($ok, $errStr) = $this->verifySignature($m, $sig); } else { - list($ok, $errstr) = $this->verifySignature($paramtypes, $sig); + list($ok, $errStr) = $this->verifySignature($paramTypes, $sig); } if (!$ok) { // Didn't match. @@ -690,10 +690,10 @@ class Server $this->debug_info .= $string . "\n"; } - protected function xml_header($charset_encoding = '') + protected function xml_header($charsetEncoding = '') { - if ($charset_encoding != '') { - return "\n"; + if ($charsetEncoding != '') { + return "\n"; } else { return "\n"; } @@ -978,33 +978,33 @@ class Server * * NB: in fact a user defined error handler can only handle WARNING, NOTICE and USER_* errors. */ - public static function _xmlrpcs_errorHandler($errcode, $errstring, $filename = null, $lineno = null, $context = null) + public static function _xmlrpcs_errorHandler($errCode, $errString, $filename = null, $lineNo = null, $context = null) { // obey the @ protocol if (error_reporting() == 0) { return; } - //if($errcode != E_NOTICE && $errcode != E_WARNING && $errcode != E_USER_NOTICE && $errcode != E_USER_WARNING) - if ($errcode != E_STRICT) { - \PhpXmlRpc\Server::error_occurred($errstring); + //if($errCode != E_NOTICE && $errCode != E_WARNING && $errCode != E_USER_NOTICE && $errCode != E_USER_WARNING) + if ($errCode != E_STRICT) { + \PhpXmlRpc\Server::error_occurred($errString); } // Try to avoid as much as possible disruption to the previous error handling // mechanism in place if ($GLOBALS['_xmlrpcs_prev_ehandler'] == '') { // The previous error handler was the default: all we should do is log error // to the default error log (if level high enough) - if (ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errcode)) { - error_log($errstring); + if (ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errCode)) { + error_log($errString); } } else { // Pass control on to previous error handler, trying to avoid loops... if ($GLOBALS['_xmlrpcs_prev_ehandler'] != array('\PhpXmlRpc\Server', '_xmlrpcs_errorHandler')) { if (is_array($GLOBALS['_xmlrpcs_prev_ehandler'])) { // the following works both with static class methods and plain object methods as error handler - call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler'], array($errcode, $errstring, $filename, $lineno, $context)); + call_user_func_array($GLOBALS['_xmlrpcs_prev_ehandler'], array($errCode, $errString, $filename, $lineNo, $context)); } else { - $GLOBALS['_xmlrpcs_prev_ehandler']($errcode, $errstring, $filename, $lineno, $context); + $GLOBALS['_xmlrpcs_prev_ehandler']($errCode, $errString, $filename, $lineno, $context); } } } diff --git a/src/Value.php b/src/Value.php index 1ea6b9e..1e5f1bf 100644 --- a/src/Value.php +++ b/src/Value.php @@ -105,12 +105,12 @@ class Value */ public function addScalar($val, $type = 'string') { - $typeof = null; + $typeOf = null; if (isset(static::$xmlrpcTypes[$type])) { - $typeof = static::$xmlrpcTypes[$type]; + $typeOf = static::$xmlrpcTypes[$type]; } - if ($typeof !== 1) { + if ($typeOf !== 1) { error_log("XML-RPC: " . __METHOD__ . ": not a scalar type ($type)"); return 0; @@ -144,7 +144,7 @@ class Value default: // a scalar, so set the value and remember we're scalar $this->me[$type] = $val; - $this->mytype = $typeof; + $this->mytype = $typeOf; return 1; } @@ -153,22 +153,22 @@ class Value /** * Add an array of xmlrpc values objects to an xmlrpc value. * - * @param Value[] $vals + * @param Value[] $values * * @return int 1 or 0 on failure * - * @todo add some checking for $vals to be an array of xmlrpc values? + * @todo add some checking for $values to be an array of xmlrpc values? */ - public function addArray($vals) + public function addArray($values) { if ($this->mytype == 0) { $this->mytype = static::$xmlrpcTypes['array']; - $this->me['array'] = $vals; + $this->me['array'] = $values; return 1; } elseif ($this->mytype == 2) { // we're adding to an array here - $this->me['array'] = array_merge($this->me['array'], $vals); + $this->me['array'] = array_merge($this->me['array'], $values); return 1; } else { @@ -181,22 +181,22 @@ class Value /** * Add an array of named xmlrpc value objects to an xmlrpc value. * - * @param Value[] $vals + * @param Value[] $values * * @return int 1 or 0 on failure * - * @todo add some checking for $vals to be an array? + * @todo add some checking for $values to be an array? */ - public function addStruct($vals) + public function addStruct($values) { if ($this->mytype == 0) { $this->mytype = static::$xmlrpcTypes['struct']; - $this->me['struct'] = $vals; + $this->me['struct'] = $values; return 1; } elseif ($this->mytype == 3) { // we're adding to a struct here - $this->me['struct'] = array_merge($this->me['struct'], $vals); + $this->me['struct'] = array_merge($this->me['struct'], $values); return 1; } else { @@ -322,11 +322,11 @@ class Value /** * Returns xml representation of the value. XML prologue not included. * - * @param string $charset_encoding the charset to be used for serialization. if null, US-ASCII is assumed + * @param string $charsetEncoding the charset to be used for serialization. if null, US-ASCII is assumed * * @return string */ - public function serialize($charset_encoding = '') + public function serialize($charsetEncoding = '') { // add check? slower, but helps to avoid recursion in serializing broken xmlrpc values... //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval'))) @@ -334,7 +334,7 @@ class Value reset($this->me); list($typ, $val) = each($this->me); - return '' . $this->serializedata($typ, $val, $charset_encoding) . "\n"; + return '' . $this->serializedata($typ, $val, $charsetEncoding) . "\n"; //} } @@ -342,26 +342,26 @@ class Value * Checks whether a struct member with a given name is present. * Works only on xmlrpc values of type struct. * - * @param string $m the name of the struct member to be looked up + * @param string $key the name of the struct member to be looked up * * @return boolean */ - public function structmemexists($m) + public function structmemexists($key) { - return array_key_exists($m, $this->me['struct']); + return array_key_exists($key, $this->me['struct']); } /** * Returns the value of a given struct member (an xmlrpc value object in itself). * Will raise a php warning if struct member of given name does not exist. * - * @param string $m the name of the struct member to be looked up + * @param string $key the name of the struct member to be looked up * * @return Value */ - public function structmem($m) + public function structmem($key) { - return $this->me['struct'][$m]; + return $this->me['struct'][$key]; } /** @@ -415,13 +415,13 @@ class Value /** * Returns the m-th member of an xmlrpc value of struct type. * - * @param integer $m the index of the value to be retrieved (zero based) + * @param integer $key the index of the value to be retrieved (zero based) * * @return Value */ - public function arraymem($m) + public function arraymem($key) { - return $this->me['array'][$m]; + return $this->me['array'][$key]; } /** diff --git a/src/Wrapper.php b/src/Wrapper.php index c5d6c47..be3cdb8 100644 --- a/src/Wrapper.php +++ b/src/Wrapper.php @@ -9,7 +9,7 @@ namespace PhpXmlRpc; /** * PHP-XMLRPC "wrapper" class. - * Generate stubs to transparently access xmlrpc methods as php functions and viceversa. + * Generate stubs to transparently access xmlrpc methods as php functions and vice-versa. * Note: this class implements the PROXY pattern, but it is not named so to avoid confusion with http proxies. * * @todo separate introspection from code generation for func-2-method wrapping @@ -26,13 +26,13 @@ class Wrapper * for php class names returns 'struct', since php objects can be serialized as xmlrpc structs * for php arrays always return array, even though arrays sometimes serialize as json structs. * - * @param string $phptype + * @param string $phpType * * @return string */ - public function php_2_xmlrpc_type($phptype) + public function php_2_xmlrpc_type($phpType) { - switch (strtolower($phptype)) { + switch (strtolower($phpType)) { case 'string': return Value::$xmlrpcString; case 'integer': @@ -49,11 +49,11 @@ class Wrapper return Value::$xmlrpcStruct; case Value::$xmlrpcBase64: case Value::$xmlrpcStruct: - return strtolower($phptype); + return strtolower($phpType); case 'resource': return ''; default: - if (class_exists($phptype)) { + if (class_exists($phpType)) { return Value::$xmlrpcStruct; } else { // unknown: might be any 'extended' xmlrpc type @@ -65,13 +65,13 @@ class Wrapper /** * Given a string defining a phpxmlrpc type return corresponding php type. * - * @param string $xmlrpctype + * @param string $xmlrpcType * * @return string */ - public function xmlrpc_2_php_type($xmlrpctype) + public function xmlrpc_2_php_type($xmlrpcType) { - switch (strtolower($xmlrpctype)) { + switch (strtolower($xmlrpcType)) { case 'base64': case 'datetime.iso8601': case 'string': @@ -90,7 +90,7 @@ class Wrapper case 'null': default: // unknown: might be any xmlrpc type - return strtolower($xmlrpctype); + return strtolower($xmlrpcType); } } @@ -123,9 +123,9 @@ class Wrapper * php functions (ie. functions not expecting a single Request obj as parameter) * is by making use of the functions_parameters_type class member. * - * @param string $funcname the name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') and array('class', 'methodname') are ok too - * @param string $newfuncname (optional) name for function to be created - * @param array $extra_options (optional) array of options for conversion. valid values include: + * @param string $funcName the name of the PHP user function to be exposed as xmlrpc method; array($obj, 'methodname') and array('class', 'methodname') are ok too + * @param string $newFuncName (optional) name for function to be created + * @param array $extraOptions (optional) array of options for conversion. valid values include: * bool return_source when true, php code w. function definition will be returned, not evaluated * bool encode_php_objs let php objects be sent to server using the 'improved' xmlrpc notation, so server can deserialize them as php objects * bool decode_php_objs --- WARNING !!! possible security hazard. only use it with trusted servers --- @@ -140,98 +140,97 @@ class Wrapper * @todo add some trigger_errors / error_log when returning false? * @todo what to do when the PHP function returns NULL? we are currently returning an empty string value... * @todo add an option to suppress php warnings in invocation of user function, similar to server debug level 3? - * @todo if $newfuncname is empty, we could use create_user_func instead of eval, as it is possibly faster + * @todo if $newFuncName is empty, we could use create_user_func instead of eval, as it is possibly faster * @todo add a verbatim_object_copy parameter to allow avoiding the same obj instance? */ - public function wrap_php_function($funcname, $newfuncname = '', $extra_options = array()) + public function wrap_php_function($funcName, $newFuncName = '', $extraOptions = array()) { - $buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true; - $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc'; + $buildIt = isset($extraOptions['return_source']) ? !($extraOptions['return_source']) : true; + $prefix = isset($extraOptions['prefix']) ? $extraOptions['prefix'] : 'xmlrpc'; $namespace = '\\PhpXmlRpc\\'; - $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false; - $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false; - $catch_warnings = isset($extra_options['suppress_warnings']) && $extra_options['suppress_warnings'] ? '@' : ''; + $encodePhpObjects = isset($extraOptions['encode_php_objs']) ? (bool)$extraOptions['encode_php_objs'] : false; + $decodePhpObjects = isset($extraOptions['decode_php_objs']) ? (bool)$extraOptions['decode_php_objs'] : false; + $catchWarnings = isset($extraOptions['suppress_warnings']) && $extraOptions['suppress_warnings'] ? '@' : ''; - $exists = false; - if (is_string($funcname) && strpos($funcname, '::') !== false) { - $funcname = explode('::', $funcname); + if (is_string($funcName) && strpos($funcName, '::') !== false) { + $funcName = explode('::', $funcName); } - if (is_array($funcname)) { - if (count($funcname) < 2 || (!is_string($funcname[0]) && !is_object($funcname[0]))) { + if (is_array($funcName)) { + if (count($funcName) < 2 || (!is_string($funcName[0]) && !is_object($funcName[0]))) { error_log('XML-RPC: syntax for function to be wrapped is wrong'); return false; } - if (is_string($funcname[0])) { - $plainfuncname = implode('::', $funcname); - } elseif (is_object($funcname[0])) { - $plainfuncname = get_class($funcname[0]) . '->' . $funcname[1]; + if (is_string($funcName[0])) { + $plainFuncName = implode('::', $funcName); + } elseif (is_object($funcName[0])) { + $plainFuncName = get_class($funcName[0]) . '->' . $funcName[1]; } - $exists = method_exists($funcname[0], $funcname[1]); + $exists = method_exists($funcName[0], $funcName[1]); } else { - $plainfuncname = $funcname; - $exists = function_exists($funcname); + $plainFuncName = $funcName; + $exists = function_exists($funcName); } if (!$exists) { - error_log('XML-RPC: function to be wrapped is not defined: ' . $plainfuncname); + error_log('XML-RPC: function to be wrapped is not defined: ' . $plainFuncName); return false; } else { // determine name of new php function - if ($newfuncname == '') { - if (is_array($funcname)) { - if (is_string($funcname[0])) { - $xmlrpcfuncname = "{$prefix}_" . implode('_', $funcname); + if ($newFuncName == '') { + if (is_array($funcName)) { + if (is_string($funcName[0])) { + $xmlrpcFuncName = "{$prefix}_" . implode('_', $funcName); } else { - $xmlrpcfuncname = "{$prefix}_" . get_class($funcname[0]) . '_' . $funcname[1]; + $xmlrpcFuncName = "{$prefix}_" . get_class($funcName[0]) . '_' . $funcName[1]; } } else { - $xmlrpcfuncname = "{$prefix}_$funcname"; + $xmlrpcFuncName = "{$prefix}_$funcName"; } } else { - $xmlrpcfuncname = $newfuncname; + $xmlrpcFuncName = $newFuncName; } - while ($buildit && function_exists($xmlrpcfuncname)) { - $xmlrpcfuncname .= 'x'; + while ($buildIt && function_exists($xmlrpcFuncName)) { + $xmlrpcFuncName .= 'x'; } // start to introspect PHP code - if (is_array($funcname)) { - $func = new \ReflectionMethod($funcname[0], $funcname[1]); + if (is_array($funcName)) { + $func = new \ReflectionMethod($funcName[0], $funcName[1]); if ($func->isPrivate()) { - error_log('XML-RPC: method to be wrapped is private: ' . $plainfuncname); + error_log('XML-RPC: method to be wrapped is private: ' . $plainFuncName); return false; } if ($func->isProtected()) { - error_log('XML-RPC: method to be wrapped is protected: ' . $plainfuncname); + error_log('XML-RPC: method to be wrapped is protected: ' . $plainFuncName); return false; } if ($func->isConstructor()) { - error_log('XML-RPC: method to be wrapped is the constructor: ' . $plainfuncname); + error_log('XML-RPC: method to be wrapped is the constructor: ' . $plainFuncName); return false; } if ($func->isDestructor()) { - error_log('XML-RPC: method to be wrapped is the destructor: ' . $plainfuncname); + error_log('XML-RPC: method to be wrapped is the destructor: ' . $plainFuncName); return false; } if ($func->isAbstract()) { - error_log('XML-RPC: method to be wrapped is abstract: ' . $plainfuncname); + error_log('XML-RPC: method to be wrapped is abstract: ' . $plainFuncName); return false; } /// @todo add more checks for static vs. nonstatic? } else { - $func = new \ReflectionFunction($funcname); + $func = new \ReflectionFunction($funcName); } if ($func->isInternal()) { // Note: from PHP 5.1.0 onward, we will possibly be able to use invokeargs // instead of getparameters to fully reflect internal php functions ? - error_log('XML-RPC: function to be wrapped is internal: ' . $plainfuncname); + error_log('XML-RPC: function to be wrapped is internal: ' . $plainFuncName); return false; } @@ -287,20 +286,20 @@ class Wrapper // execute introspection of actual function prototype $params = array(); $i = 0; - foreach ($func->getParameters() as $paramobj) { + foreach ($func->getParameters() as $paramObj) { $params[$i] = array(); - $params[$i]['name'] = '$' . $paramobj->getName(); - $params[$i]['isoptional'] = $paramobj->isOptional(); + $params[$i]['name'] = '$' . $paramObj->getName(); + $params[$i]['isoptional'] = $paramObj->isOptional(); $i++; } // start building of PHP code to be eval'd - $innercode = "\$encoder = new {$namespace}Encoder();\n"; + $innerCode = "\$encoder = new {$namespace}Encoder();\n"; $i = 0; - $parsvariations = array(); + $parsVariations = array(); $pars = array(); - $pnum = count($params); + $pNum = count($params); foreach ($params as $param) { if (isset($paramDocs[$i]['name']) && $paramDocs[$i]['name'] && strtolower($paramDocs[$i]['name']) != strtolower($param['name'])) { // param name from phpdoc info does not match param definition! @@ -309,107 +308,107 @@ class Wrapper if ($param['isoptional']) { // this particular parameter is optional. save as valid previous list of parameters - $innercode .= "if (\$paramcount > $i) {\n"; - $parsvariations[] = $pars; + $innerCode .= "if (\$paramcount > $i) {\n"; + $parsVariations[] = $pars; } - $innercode .= "\$p$i = \$msg->getParam($i);\n"; - if ($decode_php_objects) { - $innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = \$encoder->decode(\$p$i, array('decode_php_objs'));\n"; + $innerCode .= "\$p$i = \$msg->getParam($i);\n"; + if ($decodePhpObjects) { + $innerCode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = \$encoder->decode(\$p$i, array('decode_php_objs'));\n"; } else { - $innercode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = \$encoder->decode(\$p$i);\n"; + $innerCode .= "if (\$p{$i}->kindOf() == 'scalar') \$p$i = \$p{$i}->scalarval(); else \$p$i = \$encoder->decode(\$p$i);\n"; } $pars[] = "\$p$i"; $i++; if ($param['isoptional']) { - $innercode .= "}\n"; + $innerCode .= "}\n"; } - if ($i == $pnum) { + if ($i == $pNum) { // last allowed parameters combination - $parsvariations[] = $pars; + $parsVariations[] = $pars; } } $sigs = array(); - $psigs = array(); - if (count($parsvariations) == 0) { + $pSigs = array(); + if (count($parsVariations) == 0) { // only known good synopsis = no parameters - $parsvariations[] = array(); - $minpars = 0; + $parsVariations[] = array(); + $minPars = 0; } else { - $minpars = count($parsvariations[0]); + $minPars = count($parsVariations[0]); } - if ($minpars) { + if ($minPars) { // add to code the check for min params number // NB: this check needs to be done BEFORE decoding param values - $innercode = "\$paramcount = \$msg->getNumParams();\n" . - "if (\$paramcount < $minpars) return new {$namespace}Response(0, " . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . ", '" . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . "');\n" . $innercode; + $innerCode = "\$paramcount = \$msg->getNumParams();\n" . + "if (\$paramcount < $minPars) return new {$namespace}Response(0, " . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . ", '" . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . "');\n" . $innerCode; } else { - $innercode = "\$paramcount = \$msg->getNumParams();\n" . $innercode; + $innerCode = "\$paramcount = \$msg->getNumParams();\n" . $innerCode; } - $innercode .= "\$np = false;\n"; + $innerCode .= "\$np = false;\n"; // since there are no closures in php, if we are given an object instance, // we store a pointer to it in a global var... - if (is_array($funcname) && is_object($funcname[0])) { - $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcfuncname] = &$funcname[0]; - $innercode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcfuncname'];\n"; - $realfuncname = '$obj->' . $funcname[1]; + if (is_array($funcName) && is_object($funcName[0])) { + $GLOBALS['xmlrpcWPFObjHolder'][$xmlrpcFuncName] = &$funcName[0]; + $innerCode .= "\$obj =& \$GLOBALS['xmlrpcWPFObjHolder']['$xmlrpcFuncName'];\n"; + $realFuncName = '$obj->' . $funcName[1]; } else { - $realfuncname = $plainfuncname; + $realFuncName = $plainFuncName; } - foreach ($parsvariations as $pars) { - $innercode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catch_warnings}$realfuncname(" . implode(',', $pars) . "); else\n"; + foreach ($parsVariations as $pars) { + $innerCode .= "if (\$paramcount == " . count($pars) . ") \$retval = {$catchWarnings}$realFuncName(" . implode(',', $pars) . "); else\n"; // build a 'generic' signature (only use an appropriate return type) $sig = array($returns); - $psig = array($returnsDocs); + $pSig = array($returnsDocs); for ($i = 0; $i < count($pars); $i++) { if (isset($paramDocs[$i]['type'])) { $sig[] = $this->php_2_xmlrpc_type($paramDocs[$i]['type']); } else { $sig[] = Value::$xmlrpcValue; } - $psig[] = isset($paramDocs[$i]['doc']) ? $paramDocs[$i]['doc'] : ''; + $pSig[] = isset($paramDocs[$i]['doc']) ? $paramDocs[$i]['doc'] : ''; } $sigs[] = $sig; - $psigs[] = $psig; + $pSigs[] = $pSig; } - $innercode .= "\$np = true;\n"; - $innercode .= "if (\$np) return new {$namespace}Response(0, " . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . ", '" . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . "'); else {\n"; - //$innercode .= "if (\$_xmlrpcs_error_occurred) return new Response(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n"; - $innercode .= "if (is_a(\$retval, '{$namespace}Response')) return \$retval; else\n"; + $innerCode .= "\$np = true;\n"; + $innerCode .= "if (\$np) return new {$namespace}Response(0, " . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . ", '" . PhpXmlRpc::$xmlrpcerr['incorrect_params'] . "'); else {\n"; + //$innerCode .= "if (\$_xmlrpcs_error_occurred) return new Response(0, $GLOBALS['xmlrpcerr']user, \$_xmlrpcs_error_occurred); else\n"; + $innerCode .= "if (is_a(\$retval, '{$namespace}Response')) return \$retval; else\n"; if ($returns == Value::$xmlrpcDateTime || $returns == Value::$xmlrpcBase64) { - $innercode .= "return new {$namespace}Response(new {$namespace}Value(\$retval, '$returns'));"; + $innerCode .= "return new {$namespace}Response(new {$namespace}Value(\$retval, '$returns'));"; } else { - if ($encode_php_objects) { - $innercode .= "return new {$namespace}Response(\$encoder->encode(\$retval, array('encode_php_objs')));\n"; + if ($encodePhpObjects) { + $innerCode .= "return new {$namespace}Response(\$encoder->encode(\$retval, array('encode_php_objs')));\n"; } else { - $innercode .= "return new {$namespace}Response(\$encoder->encode(\$retval));\n"; + $innerCode .= "return new {$namespace}Response(\$encoder->encode(\$retval));\n"; } } // shall we exclude functions returning by ref? // if($func->returnsReference()) // return false; - $code = "function $xmlrpcfuncname(\$msg) {\n" . $innercode . "}\n}"; + $code = "function $xmlrpcFuncName(\$msg) {\n" . $innerCode . "}\n}"; //print_r($code); - if ($buildit) { + if ($buildIt) { $allOK = 0; eval($code . '$allOK=1;'); // alternative - //$xmlrpcfuncname = create_function('$m', $innercode); + //$xmlrpcFuncName = create_function('$m', $innerCode); if (!$allOK) { - error_log('XML-RPC: could not create function ' . $xmlrpcfuncname . ' to wrap php function ' . $plainfuncname); + error_log('XML-RPC: could not create function ' . $xmlrpcFuncName . ' to wrap php function ' . $plainFuncName); return false; } } - /// @todo examine if $paramDocs matches $parsvariations and build array for + /// @todo examine if $paramDocs matches $parsVariations and build array for /// usage as method signature, plus put together a nice string for docs - $ret = array('function' => $xmlrpcfuncname, 'signature' => $sigs, 'docstring' => $desc, 'signature_docs' => $psigs, 'source' => $code); + $ret = array('function' => $xmlrpcFuncName, 'signature' => $sigs, 'docstring' => $desc, 'signature_docs' => $pSigs, 'source' => $code); return $ret; } @@ -421,7 +420,7 @@ class Wrapper * object and called from remote clients (as well as their corresponding signature info). * * @param mixed $classname the name of the class whose methods are to be exposed as xmlrpc methods, or an object instance of that class - * @param array $extra_options see the docs for wrap_php_method for more options + * @param array $extraOptions see the docs for wrap_php_method for more options * string method_type 'static', 'nonstatic', 'all' and 'auto' (default); the latter will switch between static and non-static depending on wheter $classname is a class name or object instance * * @return array or false on failure @@ -429,10 +428,10 @@ class Wrapper * @todo get_class_methods will return both static and non-static methods. * we have to differentiate the action, depending on wheter we recived a class name or object */ - public function wrap_php_class($classname, $extra_options = array()) + public function wrap_php_class($classname, $extraOptions = array()) { - $methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : ''; - $methodtype = isset($extra_options['method_type']) ? $extra_options['method_type'] : 'auto'; + $methodfilter = isset($extraOptions['method_filter']) ? $extraOptions['method_filter'] : ''; + $methodtype = isset($extraOptions['method_type']) ? $extraOptions['method_type'] : 'auto'; $result = array(); $mlist = get_class_methods($classname); @@ -444,7 +443,7 @@ class Wrapper if (($func->isStatic && ($methodtype == 'all' || $methodtype == 'static' || ($methodtype == 'auto' && is_string($classname)))) || (!$func->isStatic && ($methodtype == 'all' || $methodtype == 'nonstatic' || ($methodtype == 'auto' && is_object($classname)))) ) { - $methodwrap = $this->wrap_php_function(array($classname, $mname), '', $extra_options); + $methodwrap = $this->wrap_php_function(array($classname, $mname), '', $extraOptions); if ($methodwrap) { $result[$methodwrap['function']] = $methodwrap['function']; } @@ -480,8 +479,8 @@ class Wrapper * for debugging purposes. * * @param Client $client an xmlrpc client set up correctly to communicate with target server - * @param string $methodname the xmlrpc method to be mapped to a php function - * @param array $extra_options array of options that specify conversion details. valid options include + * @param string $methodName the xmlrpc method to be mapped to a php function + * @param array $extraOptions array of options that specify conversion details. valid options include * integer signum the index of the method signature to use in mapping (if method exposes many sigs) * integer timeout timeout (in secs) to be used when executing function/calling remote method * string protocol 'http' (default), 'http11' or 'https' @@ -494,49 +493,49 @@ class Wrapper * * @return string the name of the generated php function (or false) - OR AN ARRAY... */ - public function wrap_xmlrpc_method($client, $methodname, $extra_options = 0, $timeout = 0, $protocol = '', $newfuncname = '') + public function wrap_xmlrpc_method($client, $methodName, $extraOptions = 0, $timeout = 0, $protocol = '', $newFuncName = '') { // mind numbing: let caller use sane calling convention (as per javadoc, 3 params), // OR the 2.0 calling convention (no options) - we really love backward compat, don't we? - if (!is_array($extra_options)) { - $signum = $extra_options; - $extra_options = array(); + if (!is_array($extraOptions)) { + $signum = $extraOptions; + $extraOptions = array(); } else { - $signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0; - $timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0; - $protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : ''; - $newfuncname = isset($extra_options['new_function_name']) ? $extra_options['new_function_name'] : ''; + $signum = isset($extraOptions['signum']) ? (int)$extraOptions['signum'] : 0; + $timeout = isset($extraOptions['timeout']) ? (int)$extraOptions['timeout'] : 0; + $protocol = isset($extraOptions['protocol']) ? $extraOptions['protocol'] : ''; + $newFuncName = isset($extraOptions['new_function_name']) ? $extraOptions['new_function_name'] : ''; } - //$encode_php_objects = in_array('encode_php_objects', $extra_options); - //$verbatim_client_copy = in_array('simple_client_copy', $extra_options) ? 1 : - // in_array('build_class_code', $extra_options) ? 2 : 0; + //$encodePhpObjects = in_array('encode_php_objects', $extraOptions); + //$verbatimClientCopy = in_array('simple_client_copy', $extraOptions) ? 1 : + // in_array('build_class_code', $extraOptions) ? 2 : 0; - $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false; - $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false; + $encodePhpObjects = isset($extraOptions['encode_php_objs']) ? (bool)$extraOptions['encode_php_objs'] : false; + $decodePhpObjects = isset($extraOptions['decode_php_objs']) ? (bool)$extraOptions['decode_php_objs'] : false; // it seems like the meaning of 'simple_client_copy' here is swapped wrt client_copy_mode later on... - $simple_client_copy = isset($extra_options['simple_client_copy']) ? (int)($extra_options['simple_client_copy']) : 0; - $buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true; - $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc'; + $simple_client_copy = isset($extraOptions['simple_client_copy']) ? (int)($extraOptions['simple_client_copy']) : 0; + $buildIt = isset($extraOptions['return_source']) ? !($extraOptions['return_source']) : true; + $prefix = isset($extraOptions['prefix']) ? $extraOptions['prefix'] : 'xmlrpc'; $namespace = '\\PhpXmlRpc\\'; - if (isset($extra_options['return_on_fault'])) { + if (isset($extraOptions['return_on_fault'])) { $decode_fault = true; - $fault_response = $extra_options['return_on_fault']; + $fault_response = $extraOptions['return_on_fault']; } else { $decode_fault = false; $fault_response = ''; } - $debug = isset($extra_options['debug']) ? ($extra_options['debug']) : 0; + $debug = isset($extraOptions['debug']) ? ($extraOptions['debug']) : 0; $msgclass = $namespace . 'Request'; $valclass = $namespace . 'Value'; $decoderClass = $namespace . 'Encoder'; $msg = new $msgclass('system.methodSignature'); - $msg->addparam(new $valclass($methodname)); + $msg->addparam(new $valclass($methodName)); $client->setDebug($debug); $response = $client->send($msg, $timeout, $protocol); if ($response->faultCode()) { - error_log('XML-RPC: could not retrieve method signature from remote server for method ' . $methodname); + error_log('XML-RPC: could not retrieve method signature from remote server for method ' . $methodName); return false; } else { @@ -546,30 +545,30 @@ class Wrapper $msig = $decoder->decode($msig); } if (!is_array($msig) || count($msig) <= $signum) { - error_log('XML-RPC: could not retrieve method signature nr.' . $signum . ' from remote server for method ' . $methodname); + error_log('XML-RPC: could not retrieve method signature nr.' . $signum . ' from remote server for method ' . $methodName); return false; } else { // pick a suitable name for the new function, avoiding collisions - if ($newfuncname != '') { - $xmlrpcfuncname = $newfuncname; + if ($newFuncName != '') { + $xmlrpcFuncName = $newFuncName; } else { // take care to insure that methodname is translated to valid // php function name - $xmlrpcfuncname = $prefix . '_' . preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'), - array('_', ''), $methodname); + $xmlrpcFuncName = $prefix . '_' . preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'), + array('_', ''), $methodName); } - while ($buildit && function_exists($xmlrpcfuncname)) { - $xmlrpcfuncname .= 'x'; + while ($buildIt && function_exists($xmlrpcFuncName)) { + $xmlrpcFuncName .= 'x'; } $msig = $msig[$signum]; $mdesc = ''; // if in 'offline' mode, get method description too. // in online mode, favour speed of operation - if (!$buildit) { + if (!$buildIt) { $msg = new $msgclass('system.methodHelp'); - $msg->addparam(new $valclass($methodname)); + $msg->addparam(new $valclass($methodName)); $response = $client->send($msg, $timeout, $protocol); if (!$response->faultCode()) { $mdesc = $response->value(); @@ -579,25 +578,25 @@ class Wrapper } } - $results = $this->build_remote_method_wrapper_code($client, $methodname, - $xmlrpcfuncname, $msig, $mdesc, $timeout, $protocol, $simple_client_copy, - $prefix, $decode_php_objects, $encode_php_objects, $decode_fault, + $results = $this->build_remote_method_wrapper_code($client, $methodName, + $xmlrpcFuncName, $msig, $mdesc, $timeout, $protocol, $simple_client_copy, + $prefix, $decodePhpObjects, $encodePhpObjects, $decode_fault, $fault_response, $namespace); //print_r($code); - if ($buildit) { + if ($buildIt) { $allOK = 0; eval($results['source'] . '$allOK=1;'); // alternative - //$xmlrpcfuncname = create_function('$m', $innercode); + //$xmlrpcFuncName = create_function('$m', $innerCode); if ($allOK) { - return $xmlrpcfuncname; + return $xmlrpcFuncName; } else { - error_log('XML-RPC: could not create function ' . $xmlrpcfuncname . ' to wrap remote method ' . $methodname); + error_log('XML-RPC: could not create function ' . $xmlrpcFuncName . ' to wrap remote method ' . $methodName); return false; } } else { - $results['function'] = $xmlrpcfuncname; + $results['function'] = $xmlrpcFuncName; return $results; } @@ -611,22 +610,22 @@ class Wrapper * For more details see wrap_xmlrpc_method. * * @param Client $client the client obj all set to query the desired server - * @param array $extra_options list of options for wrapped code + * @param array $extraOptions list of options for wrapped code * * @return mixed false on error, the name of the created class if all ok or an array with code, class name and comments (if the appropriatevoption is set in extra_options) */ - public function wrap_xmlrpc_server($client, $extra_options = array()) + public function wrap_xmlrpc_server($client, $extraOptions = array()) { - $methodfilter = isset($extra_options['method_filter']) ? $extra_options['method_filter'] : ''; - //$signum = isset($extra_options['signum']) ? (int)$extra_options['signum'] : 0; - $timeout = isset($extra_options['timeout']) ? (int)$extra_options['timeout'] : 0; - $protocol = isset($extra_options['protocol']) ? $extra_options['protocol'] : ''; - $newclassname = isset($extra_options['new_class_name']) ? $extra_options['new_class_name'] : ''; - $encode_php_objects = isset($extra_options['encode_php_objs']) ? (bool)$extra_options['encode_php_objs'] : false; - $decode_php_objects = isset($extra_options['decode_php_objs']) ? (bool)$extra_options['decode_php_objs'] : false; - $verbatim_client_copy = isset($extra_options['simple_client_copy']) ? !($extra_options['simple_client_copy']) : true; - $buildit = isset($extra_options['return_source']) ? !($extra_options['return_source']) : true; - $prefix = isset($extra_options['prefix']) ? $extra_options['prefix'] : 'xmlrpc'; + $methodfilter = isset($extraOptions['method_filter']) ? $extraOptions['method_filter'] : ''; + //$signum = isset($extraOptions['signum']) ? (int)$extraOptions['signum'] : 0; + $timeout = isset($extraOptions['timeout']) ? (int)$extraOptions['timeout'] : 0; + $protocol = isset($extraOptions['protocol']) ? $extraOptions['protocol'] : ''; + $newclassname = isset($extraOptions['new_class_name']) ? $extraOptions['new_class_name'] : ''; + $encodePhpObjects = isset($extraOptions['encode_php_objs']) ? (bool)$extraOptions['encode_php_objs'] : false; + $decodePhpObjects = isset($extraOptions['decode_php_objs']) ? (bool)$extraOptions['decode_php_objs'] : false; + $verbatimClientCopy = isset($extraOptions['simple_client_copy']) ? !($extraOptions['simple_client_copy']) : true; + $buildIt = isset($extraOptions['return_source']) ? !($extraOptions['return_source']) : true; + $prefix = isset($extraOptions['prefix']) ? $extraOptions['prefix'] : 'xmlrpc'; $namespace = '\\PhpXmlRpc\\'; $msgclass = $namespace . 'Request'; @@ -652,24 +651,24 @@ class Wrapper } else { // pick a suitable name for the new function, avoiding collisions if ($newclassname != '') { - $xmlrpcclassname = $newclassname; + $xmlrpcClassName = $newclassname; } else { - $xmlrpcclassname = $prefix . '_' . preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'), + $xmlrpcClassName = $prefix . '_' . preg_replace(array('/\./', '/[^a-zA-Z0-9_\x7f-\xff]/'), array('_', ''), $client->server) . '_client'; } - while ($buildit && class_exists($xmlrpcclassname)) { - $xmlrpcclassname .= 'x'; + while ($buildIt && class_exists($xmlrpcClassName)) { + $xmlrpcClassName .= 'x'; } /// @todo add function setdebug() to new class, to enable/disable debugging - $source = "class $xmlrpcclassname\n{\nvar \$client;\n\n"; + $source = "class $xmlrpcClassName\n{\nvar \$client;\n\n"; $source .= "function __construct()\n{\n"; - $source .= $this->build_client_wrapper_code($client, $verbatim_client_copy, $prefix, $namespace); + $source .= $this->build_client_wrapper_code($client, $verbatimClientCopy, $prefix, $namespace); $source .= "\$this->client = \$client;\n}\n\n"; $opts = array('simple_client_copy' => 2, 'return_source' => true, 'timeout' => $timeout, 'protocol' => $protocol, - 'encode_php_objs' => $encode_php_objects, 'prefix' => $prefix, - 'decode_php_objs' => $decode_php_objects, + 'encode_php_objs' => $encodePhpObjects, 'prefix' => $prefix, + 'decode_php_objs' => $decodePhpObjects, ); /// @todo build javadoc for class definition, too foreach ($mlist as $mname) { @@ -678,7 +677,7 @@ class Wrapper array('_', ''), $mname); $methodwrap = $this->wrap_xmlrpc_method($client, $mname, $opts); if ($methodwrap) { - if (!$buildit) { + if (!$buildIt) { $source .= $methodwrap['docstring']; } $source .= $methodwrap['source'] . "\n"; @@ -688,20 +687,20 @@ class Wrapper } } $source .= "}\n"; - if ($buildit) { + if ($buildIt) { $allOK = 0; eval($source . '$allOK=1;'); // alternative - //$xmlrpcfuncname = create_function('$m', $innercode); + //$xmlrpcFuncName = create_function('$m', $innerCode); if ($allOK) { - return $xmlrpcclassname; + return $xmlrpcClassName; } else { - error_log('XML-RPC: could not create class ' . $xmlrpcclassname . ' to wrap remote server ' . $client->server); + error_log('XML-RPC: could not create class ' . $xmlrpcClassName . ' to wrap remote server ' . $client->server); return false; } } else { - return array('class' => $xmlrpcclassname, 'code' => $source, 'docstring' => ''); + return array('class' => $xmlrpcClassName, 'code' => $source, 'docstring' => ''); } } } @@ -714,33 +713,33 @@ class Wrapper * valid php code is emitted. * Note: real spaghetti code follows... */ - public function build_remote_method_wrapper_code($client, $methodname, $xmlrpcfuncname, + public function build_remote_method_wrapper_code($client, $methodName, $xmlrpcFuncName, $msig, $mdesc = '', $timeout = 0, $protocol = '', $client_copy_mode = 0, $prefix = 'xmlrpc', - $decode_php_objects = false, $encode_php_objects = false, $decode_fault = false, + $decodePhpObjects = false, $encodePhpObjects = false, $decode_fault = false, $fault_response = '', $namespace = '\\PhpXmlRpc\\') { - $code = "function $xmlrpcfuncname ("; + $code = "function $xmlrpcFuncName ("; if ($client_copy_mode < 2) { // client copy mode 0 or 1 == partial / full client copy in emitted code - $innercode = $this->build_client_wrapper_code($client, $client_copy_mode, $prefix, $namespace); - $innercode .= "\$client->setDebug(\$debug);\n"; + $innerCode = $this->build_client_wrapper_code($client, $client_copy_mode, $prefix, $namespace); + $innerCode .= "\$client->setDebug(\$debug);\n"; $this_ = ''; } else { // client copy mode 2 == no client copy in emitted code - $innercode = ''; + $innerCode = ''; $this_ = 'this->'; } - $innercode .= "\$msg = new {$namespace}Request('$methodname');\n"; + $innerCode .= "\$msg = new {$namespace}Request('$methodName');\n"; if ($mdesc != '') { // take care that PHP comment is not terminated unwillingly by method description $mdesc = "/**\n* " . str_replace('*/', '* /', $mdesc) . "\n"; } else { - $mdesc = "/**\nFunction $xmlrpcfuncname\n"; + $mdesc = "/**\nFunction $xmlrpcFuncName\n"; } // param parsing - $innercode .= "\$encoder = new {$namespace}Encoder();\n"; + $innerCode .= "\$encoder = new {$namespace}Encoder();\n"; $plist = array(); $pcount = count($msig); for ($i = 1; $i < $pcount; $i++) { @@ -750,15 +749,15 @@ class Wrapper $ptype == 'string' || $ptype == 'dateTime.iso8601' || $ptype == 'base64' || $ptype == 'null' ) { // only build directly xmlrpc values when type is known and scalar - $innercode .= "\$p$i = new {$namespace}Value(\$p$i, '$ptype');\n"; + $innerCode .= "\$p$i = new {$namespace}Value(\$p$i, '$ptype');\n"; } else { - if ($encode_php_objects) { - $innercode .= "\$p$i = \$encoder->encode(\$p$i, array('encode_php_objs'));\n"; + if ($encodePhpObjects) { + $innerCode .= "\$p$i = \$encoder->encode(\$p$i, array('encode_php_objs'));\n"; } else { - $innercode .= "\$p$i = \$encoder->encode(\$p$i);\n"; + $innerCode .= "\$p$i = \$encoder->encode(\$p$i);\n"; } } - $innercode .= "\$msg->addparam(\$p$i);\n"; + $innerCode .= "\$msg->addparam(\$p$i);\n"; $mdesc .= '* @param ' . $this->xmlrpc_2_php_type($ptype) . " \$p$i\n"; } if ($client_copy_mode < 2) { @@ -768,23 +767,23 @@ class Wrapper $plist = implode(', ', $plist); $mdesc .= '* @return ' . $this->xmlrpc_2_php_type($msig[0]) . " (or an {$namespace}Response obj instance if call fails)\n*/\n"; - $innercode .= "\$res = \${$this_}client->send(\$msg, $timeout, '$protocol');\n"; + $innerCode .= "\$res = \${$this_}client->send(\$msg, $timeout, '$protocol');\n"; if ($decode_fault) { if (is_string($fault_response) && ((strpos($fault_response, '%faultCode%') !== false) || (strpos($fault_response, '%faultString%') !== false))) { - $respcode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '" . str_replace("'", "''", $fault_response) . "')"; + $respCode = "str_replace(array('%faultCode%', '%faultString%'), array(\$res->faultCode(), \$res->faultString()), '" . str_replace("'", "''", $fault_response) . "')"; } else { - $respcode = var_export($fault_response, true); + $respCode = var_export($fault_response, true); } } else { - $respcode = '$res'; + $respCode = '$res'; } - if ($decode_php_objects) { - $innercode .= "if (\$res->faultcode()) return $respcode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));"; + if ($decodePhpObjects) { + $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value(), array('decode_php_objs'));"; } else { - $innercode .= "if (\$res->faultcode()) return $respcode; else return \$encoder->decode(\$res->value());"; + $innerCode .= "if (\$res->faultcode()) return $respCode; else return \$encoder->decode(\$res->value());"; } - $code = $code . $plist . ") {\n" . $innercode . "\n}\n"; + $code = $code . $plist . ") {\n" . $innerCode . "\n}\n"; return array('source' => $code, 'docstring' => $mdesc); } @@ -793,15 +792,20 @@ class Wrapper * Given necessary info, generate php code that will rebuild a client object * Take care that no full checking of input parameters is done to ensure that * valid php code is emitted. + * @param Client $client + * @param bool $verbatimClientCopy + * @param string $prefix + * @param string $namespace + * @return string */ - protected function build_client_wrapper_code($client, $verbatim_client_copy, $prefix = 'xmlrpc', $namespace = '\\PhpXmlRpc\\' ) + protected function build_client_wrapper_code($client, $verbatimClientCopy, $prefix = 'xmlrpc', $namespace = '\\PhpXmlRpc\\' ) { $code = "\$client = new {$namespace}Client('" . str_replace("'", "\'", $client->path) . "', '" . str_replace("'", "\'", $client->server) . "', $client->port);\n"; // copy all client fields to the client that will be generated runtime // (this provides for future expansion or subclassing of client obj) - if ($verbatim_client_copy) { + if ($verbatimClientCopy) { foreach ($client as $fld => $val) { if ($fld != 'debug' && $fld != 'return_type') { $val = var_export($val, true); -- 2.43.0