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
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]
----
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]
----
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
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');
}
}
$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";
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');
}
}
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');
}
}
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...");
}
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
{
/**
* - 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
{
return self::$charsetEncoder;
}
+ /// @todo this should be a static method
public function setCharsetEncoder($charsetEncoder)
{
self::$charsetEncoder = $charsetEncoder;
}
}
- // 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);
}
return self::$charsetEncoder;
}
+ /// @todo this should be a static method
public function setCharsetEncoder($charsetEncoder)
{
self::$charsetEncoder = $charsetEncoder;
return self::$charsetEncoder;
}
+ /// @todo this should be a static method
public function setCharsetEncoder($charsetEncoder)
{
self::$charsetEncoder = $charsetEncoder;
return self::$charsetEncoder;
}
+ /// @todo this should be a static method
public function setCharsetEncoder($charsetEncoder)
{
self::$charsetEncoder = $charsetEncoder;