WIP docs
authorgggeek <giunta.gaetano@gmail.com>
Tue, 3 Jan 2023 18:01:07 +0000 (18:01 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 3 Jan 2023 18:01:07 +0000 (18:01 +0000)
doc/manual/phpxmlrpc_manual.adoc
src/Client.php
src/Helper/Charset.php
src/Helper/Http.php
src/Helper/XMLParser.php
src/Request.php
src/Response.php
src/Server.php
src/Value.php

index c01e119..0961dea 100644 (file)
@@ -1074,9 +1074,21 @@ $val = $encoder::decodeXml($text);
 if ($val) echo 'Found a value of type ' . $val->kindOf(); else echo 'Found invalid xml';
 ----
 
-=== Logging
+=== Errors and Logging
 
-@TODO...
+Many of the classes in this library by default use the php error logging facilities to log errors in case there
+is some unexpected but non-fatal event happening, such as f.e. when an invalid xml-rpc request or response are received.
+Going straight to the log instead of triggering a php warning or error has the advantage of not breaking the xml-rpc
+output when the issue is happening within the context of an xmlrpc-server and `display_errors` is enabled.
+
+In case things are not going as you expect, please check the error log first for the presence of any messages from
+PHPXMLRPC which could be useful in troubleshooting what is going on under the hood.
+
+You can customize the way error messages are traced via the static method `setLogger` available for the classes
+`Client`, `Encoder`, `Request`, `Server` and `Value`. Keep in mind that for the moment, classes `Charset`, `HTTP` and
+`XMLParser` do not allow the same customization without hacking the `PhpXmlRpc\Logger` class. Last but not least, be
+aware that the same Logger is also responsible for echoing to screen the debug messages produced by the Client when its
+debug level has been set; this allows to customize the debugging process in the same way.
 
 === Transferring PHP objects over XML-RPC
 
@@ -1477,7 +1489,22 @@ To find out what the server is really returning to your client, you have to enab
 
 If what you need is to save the responses received from the server as xml, you have multiple options:
 
-1- use the `serialize` method on the Response object.
+1 - use the Response's `httpResponse` method
+
+[source, php]
+----
+$resp = $client->send($msg);
+if (!$resp->faultCode())
+    $data_to_be_saved = $resp->httpResponse()['raw_data'];
+----
+
+Note that, while the data saved this way is an accurate copy of what is received from the server, it might not match what
+gets parsed into the response's value, as there is some filtering involved, such as stripping of comments junk from
+the end of the message, character set conversion, etc...
+
+Note also that, in the future, this might need some debug mode to be enabled in order to work.
+
+2 - use the `serialize` method on the Response object.
 
 [source, php]
 ----
@@ -1492,7 +1519,7 @@ as "<string/>", `serialize()` will output "<string></string>"), or if the server
 which case the xml generated client side using serialize() will correspond to the error response generated
 internally by the lib).
 
-2 - set the client object to return the raw xml received instead of the decoded objects:
+3 - set the client object to return the raw xml received instead of the decoded objects:
 
 [source, php]
 ----
@@ -1508,10 +1535,6 @@ protocol will be checked. This means that xml-rpc responses sent by the server t
 response on the client (e.g. malformed xml, responses that have faultCode set, etc...) now will not be flagged as
 invalid, and you might end up saving not valid xml but random junk...
 
-3 - use the Response's `httpResponse` method
-
-@TODO...
-
 === Can I use the MS Windows character set?
 
 If the data your application is using comes from a Microsoft application, there are some chances that the character set
index 6ecdfd3..e1ada81 100644 (file)
@@ -705,6 +705,7 @@ class Client
         if ($username != '') {
             $credentials = 'Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
             if ($authType != 1) {
+                /// @todo make this a proper error, ie. return a failure
                 $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0');
             }
         }
@@ -725,6 +726,7 @@ class Client
             $uri = 'http://' . $server . ':' . $port . $this->path;
             if ($proxyUsername != '') {
                 if ($proxyAuthType != 1) {
+                    /// @todo make this a proper error, ie. return a failure
                     $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported with HTTP 1.0');
                 }
                 $proxyCredentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyUsername . ':' . $proxyPassword) . "\r\n";
@@ -1093,6 +1095,7 @@ class Client
             if (defined('CURLOPT_HTTPAUTH')) {
                 curl_setopt($curl, CURLOPT_HTTPAUTH, $authType);
             } elseif ($authType != 1) {
+                /// @todo make this a proper error, ie. return a failure
                 $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install');
             }
         }
@@ -1142,6 +1145,7 @@ class Client
                 if (defined('CURLOPT_PROXYAUTH')) {
                     curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyAuthType);
                 } elseif ($proxyAuthType != 1) {
+                    /// @todo make this a proper error, ie. return a failure
                     $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
                 }
             }
index 07951d9..c04fe6b 100644 (file)
@@ -272,6 +272,7 @@ class Charset
 
             default:
                 $escapedData = '';
+                /// @todo allow usage of a custom Logger via the DIC(ish) pattern we use in other classes
                 Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ": Converting from $srcEncoding to $destEncoding: not supported...");
         }
 
index 4b74f39..e3f4e80 100644 (file)
@@ -5,6 +5,7 @@ namespace PhpXmlRpc\Helper;
 use PhpXmlRpc\Exception\HttpException;
 use PhpXmlRpc\PhpXmlRpc;
 
+/// @todo allow usage of a custom Logger via the DIC(ish) pattern we use in other classes
 class Http
 {
     /**
index 6ccfb34..f1678b4 100644 (file)
@@ -14,6 +14,7 @@ use PhpXmlRpc\Value;
  *       - add parseRequest, parseResponse, parseValue methods
  * @todo if iconv() or mb_string() are available, we could allow to convert the received xml to a custom charset encoding
  *       while parsing, which is faster than doing it later by going over the rebuilt data structure
+ * @todo allow usage of a custom Logger via the DIC(ish) pattern we use in other classes
  */
 class XMLParser
 {
index 39273cf..0031320 100644 (file)
@@ -65,6 +65,7 @@ class Request
         return self::$charsetEncoder;
     }
 
+    /// @todo this should be a static method
     public function setCharsetEncoder($charsetEncoder)
     {
         self::$charsetEncoder = $charsetEncoder;
@@ -300,7 +301,7 @@ class Request
             }
         }
 
-        // if user wants back raw xml, give it to her
+        // if the user wants back raw xml, give it to her
         if ($returnType == 'xml') {
             return new Response($data, 0, '', 'xml', $this->httpResponse);
         }
index 8a3c45e..afde3ba 100644 (file)
@@ -38,6 +38,7 @@ class Response
         return self::$charsetEncoder;
     }
 
+    /// @todo this should be a static method
     public function setCharsetEncoder($charsetEncoder)
     {
         self::$charsetEncoder = $charsetEncoder;
index 9c43489..a483b38 100644 (file)
@@ -133,6 +133,7 @@ class Server
         return self::$charsetEncoder;
     }
 
+    /// @todo this should be a static method
     public function setCharsetEncoder($charsetEncoder)
     {
         self::$charsetEncoder = $charsetEncoder;
index d76e3b6..d23f766 100644 (file)
@@ -72,6 +72,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
         return self::$charsetEncoder;
     }
 
+    /// @todo this should be a static method
     public function setCharsetEncoder($charsetEncoder)
     {
         self::$charsetEncoder = $charsetEncoder;