Implement interface ArrayAccess in the Value class
[plcapi.git] / src / Request.php
index 6eb7671..5220968 100644 (file)
@@ -2,9 +2,10 @@
 
 namespace PhpXmlRpc;
 
+use PhpXmlRpc\Helper\Charset;
 use PhpXmlRpc\Helper\Http;
-use PhpXmlRpc\Helper\XMLParser;
 use PhpXmlRpc\Helper\Logger;
+use PhpXmlRpc\Helper\XMLParser;
 
 class Request
 {
@@ -52,7 +53,7 @@ class Request
             $this->content_type = 'text/xml';
         }
         $this->payload = $this->xml_header($charsetEncoding);
-        $this->payload .= '<methodName>' . $this->methodname . "</methodName>\n";
+        $this->payload .= '<methodName>' . Charset::instance()->encodeEntities($this->methodname, PhpXmlRpc::$xmlrpc_internalencoding, $charsetEncoding) . "</methodName>\n";
         $this->payload .= "<params>\n";
         foreach ($this->params as $p) {
             $this->payload .= "<param>\n" . $p->serialize($charsetEncoding) .
@@ -169,7 +170,7 @@ class Request
     public function parseResponse($data = '', $headersProcessed = false, $returnType = 'xmlrpcvals')
     {
         if ($this->debug) {
-            Logger::debugMessage("---GOT---\n$data\n---END---");
+            Logger::instance()->debugMessage("---GOT---\n$data\n---END---");
         }
 
         $this->httpResponse = array('raw_data' => $data, 'headers' => array(), 'cookies' => array());
@@ -215,7 +216,7 @@ class Request
                 $start += strlen('<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
                 $end = strpos($data, '-->', $start);
                 $comments = substr($data, $start, $end - $start);
-                Logger::debugMessage("---SERVER DEBUG INFO (DECODED) ---\n\t" .
+                Logger::instance()->debugMessage("---SERVER DEBUG INFO (DECODED) ---\n\t" .
                     str_replace("\n", "\n\t", base64_decode($comments)) . "\n---END---", $respEncoding);
             }
         }
@@ -317,8 +318,8 @@ class Request
             $r = new Response(0, PhpXmlRpc::$xmlrpcerr['invalid_return'],
                 PhpXmlRpc::$xmlrpcstr['invalid_return']);
         } else {
-            if ($this->debug) {
-                Logger::debugMessage(
+            if ($this->debug > 1) {
+                Logger::instance()->debugMessage(
                     "---PARSED---\n".var_export($xmlRpcParser->_xh['value'], true)."\n---END---"
                 );
             }
@@ -329,8 +330,10 @@ 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 ($returnType == 'xmlrpcvals') {
-                    $errNo_v = $v->structmem('faultCode');
-                    $errStr_v = $v->structmem('faultString');
+                    //$errNo_v = $v->structmem('faultCode');
+                    //$errStr_v = $v->structmem('faultString');
+                    $errNo_v = $v['faultCode'];
+                    $errStr_v = $v['faultString'];
                     $errNo = $errNo_v->scalarval();
                     $errStr = $errStr_v->scalarval();
                 } else {
@@ -355,4 +358,24 @@ class Request
 
         return $r;
     }
+
+    /**
+     * Kept the old name even if Request class was renamed, for compatibility.
+     *
+     * @return string
+     */
+    public function kindOf()
+    {
+        return 'msg';
+    }
+
+    /**
+     * Enables/disables the echoing to screen of the xmlrpc responses received.
+     *
+     * @param integer $in values 0, 1, 2 are supported
+     */
+    public function setDebug($in)
+    {
+        $this->debug = $in;
+    }
 }