Improve the way test suite reports error messages at DEBUG=1
[plcapi.git] / src / Client.php
index 00195af..214d970 100644 (file)
@@ -2,6 +2,8 @@
 
 namespace PhpXmlRpc;
 
+use PhpXmlRpc\Helper\Logger;
+
 class Client
 {
     /// @todo: do these need to be public?
@@ -361,7 +363,7 @@ class Client
         }
 
         // where req is a Request
-        $req->debug = $this->debug;
+        $req->setDebug($this->debug);
 
         if ($method == 'https') {
             $r = $this->sendPayloadHTTPS(
@@ -551,7 +553,7 @@ class Client
             $payload;
 
         if ($this->debug > 1) {
-            $this->debugMessage("---SENDING---\n$op\n---END---");
+            Logger::instance()->debugMessage("---SENDING---\n$op\n---END---");
         }
 
         if ($timeout > 0) {
@@ -707,9 +709,7 @@ class Client
         }
 
         if ($this->debug > 1) {
-            $this->debugMessage("---SENDING---\n$payload\n---END---");
-            // let the client see this now in case http times out...
-            flush();
+            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
@@ -848,7 +849,7 @@ class Client
                 $message .= $name . ': ' . $val . "\n";
             }
             $message .= "---END---";
-            $this->debugMessage($message);
+            Logger::instance()->debugMessage($message);
         }
 
         if (!$result) {
@@ -987,7 +988,7 @@ class Client
         if ($this->return_type == 'xml') {
             return $rets;
         } elseif ($this->return_type == 'phpvals') {
-            ///@todo test this code branch...
+            /// @todo test this code branch...
             $rets = $result->value();
             if (!is_array($rets)) {
                 return false;       // bad return type from system.multicall
@@ -1071,21 +1072,4 @@ class Client
             return $response;
         }
     }
-
-    /**
-     * Echoes a debug message, taking care of escaping it when not in console mode
-     *
-     * @param string $message
-     */
-    protected function debugMessage($message)
-    {
-        if (PHP_SAPI != 'cli') {
-            print "<PRE>\n".htmlentities($message)."\n</PRE>";
-        }
-        else {
-            print "\n$message\n";
-        }
-        // let the client see this now in case http times out...
-        flush();
-    }
 }