Fix ArrayIterator interface implementation; remove usage of arraysize(), structsize...
[plcapi.git] / src / Client.php
index d71ef27..3ff4b7c 100644 (file)
@@ -341,7 +341,7 @@ class Client
      * @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
+     * @return Response|Response[]
      */
     public function send($req, $timeout = 0, $method = '')
     {
@@ -352,7 +352,7 @@ class Client
         }
 
         if (is_array($req)) {
-            // $msg is an array of Requests
+            // $req is an array of Requests
             $r = $this->multicall($req, $timeout, $method);
 
             return $r;
@@ -363,7 +363,7 @@ class Client
         }
 
         // where req is a Request
-        $req->debug = $this->debug;
+        $req->setDebug($this->debug);
 
         if ($method == 'https') {
             $r = $this->sendPayloadHTTPS(
@@ -553,7 +553,7 @@ class Client
             $payload;
 
         if ($this->debug > 1) {
-            Logger::debugMessage("---SENDING---\n$op\n---END---");
+            Logger::instance()->debugMessage("---SENDING---\n$op\n---END---");
         }
 
         if ($timeout > 0) {
@@ -634,7 +634,7 @@ class Client
      * 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 Request $req
      * @param string $server
      * @param int $port
      * @param int $timeout
@@ -657,7 +657,7 @@ class Client
      * @param int $sslVersion
      * @return Response
      */
-    protected function sendPayloadCURL($msg, $server, $port, $timeout = 0, $username = '',
+    protected function sendPayloadCURL($req, $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)
@@ -684,12 +684,12 @@ class Client
         }
 
         // 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);
         }
 
         // Deflate request body and set appropriate request headers
-        $payload = $msg->payload;
+        $payload = $req->payload;
         if (function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate')) {
             if ($this->request_compression == 'gzip') {
                 $a = @gzencode($payload);
@@ -709,7 +709,7 @@ class Client
         }
 
         if ($this->debug > 1) {
-            Logger::debugMessage("---SENDING---\n$payload\n---END---");
+            Logger::instance()->debugMessage("---SENDING---\n$payload\n---END---");
         }
 
         if (!$keepAlive || !$this->xmlrpc_curl_handle) {
@@ -722,10 +722,11 @@ class Client
         }
 
         // results into variable
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
 
-        if ($this->debug) {
-            curl_setopt($curl, CURLOPT_VERBOSE, 1);
+        if ($this->debug > 1) {
+            curl_setopt($curl, CURLOPT_VERBOSE, true);
+            /// @todo allow callers to redirect curlopt_stderr to some stream which can be buffered
         }
         curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
         // required for XMLRPC: post the data
@@ -749,7 +750,7 @@ class Client
             }
         }
         // extra headers
-        $headers = array('Content-Type: ' . $msg->content_type, 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
+        $headers = array('Content-Type: ' . $req->content_type, 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
         // if no keepalive is wanted, let the server know it in advance
         if (!$keepAlive) {
             $headers[] = 'Connection: close';
@@ -848,7 +849,7 @@ class Client
                 $message .= $name . ': ' . $val . "\n";
             }
             $message .= "---END---";
-            Logger::debugMessage($message);
+            Logger::instance()->debugMessage($message);
         }
 
         if (!$result) {
@@ -864,7 +865,7 @@ class Client
             if (!$keepAlive) {
                 curl_close($curl);
             }
-            $resp = $msg->parseResponse($result, true, $this->return_type);
+            $resp = $req->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) {
                 curl_close($curl);
@@ -1036,7 +1037,7 @@ class Client
             if ($rets->kindOf() != 'array') {
                 return false;       // bad return type from system.multicall
             }
-            $numRets = $rets->arraysize();
+            $numRets = $rets->count();
             if ($numRets != count($reqs)) {
                 return false;       // wrong number of return values.
             }
@@ -1046,7 +1047,7 @@ class Client
                 $val = $rets->arraymem($i);
                 switch ($val->kindOf()) {
                     case 'array':
-                        if ($val->arraysize() != 1) {
+                        if ($val->count() != 1) {
                             return false;       // Bad value
                         }
                         // Normal return value