$payload;
if ($this->debug > 1) {
- Logger::debugMessage("---SENDING---\n$op\n---END---");
+ Logger::instance()->debugMessage("---SENDING---\n$op\n---END---");
}
if ($timeout > 0) {
}
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) {
$message .= $name . ': ' . $val . "\n";
}
$message .= "---END---";
- Logger::debugMessage($message);
+ Logger::instance()->debugMessage($message);
}
if (!$result) {
namespace PhpXmlRpc\Helper;
use PhpXmlRpc\PhpXmlRpc;
-use PhpXmlRpc\Helper\Logger;
class Http
{
/**
- * Decode a string that is encoded w/ "chunked" transfer encoding
- * as defined in rfc2068 par. 19.4.6
- * code shamelessly stolen from nusoap library by Dietrich Ayala.
+ * Decode a string that is encoded with "chunked" transfer encoding as defined in rfc2068 par. 19.4.6
+ * Code shamelessly stolen from nusoap library by Dietrich Ayala.
*
* @param string $buffer the string to be decoded
*
foreach ($httpResponse['cookies'] as $header => $value) {
$msg .= "COOKIE: $header={$value['value']}\n";
}
- Logger::debugMessage($msg);
+ Logger::instance()->debugMessage($msg);
}
// if CURL was used for the call, http headers have been processed,
if ($httpResponse['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
$data = $degzdata;
if ($debug) {
- Logger::debugMessage("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
+ Logger::instance()->debugMessage("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
}
} elseif ($httpResponse['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {
$data = $degzdata;
if ($debug) {
- Logger::debugMessage("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
+ Logger::instance()->debugMessage("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
}
} else {
error_log('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to decode the deflated data received from server');
class Logger
{
+ protected static $instance = null;
+
+ /**
+ * This class is singleton, so that later we can move to DI patterns.
+ *
+ * @return Charset
+ */
+ public static function instance()
+ {
+ if (self::$instance === null) {
+ self::$instance = new self();
+ }
+
+ return self::$instance;
+ }
+
/**
* Echoes a debug message, taking care of escaping it when not in console mode.
* NB: if the encoding of the message is not known or wrong, and we are working in web mode, there is no guarantee
* @param string $message
* @param string $encoding
*/
- public static function debugMessage($message, $encoding=null)
+ public function debugMessage($message, $encoding=null)
{
if (PHP_SAPI != 'cli') {
$flags = ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE;
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());
$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);
}
}
PhpXmlRpc::$xmlrpcstr['invalid_return']);
} else {
if ($this->debug) {
- Logger::debugMessage(
+ Logger::instance()->debugMessage(
"---PARSED---\n".var_export($xmlRpcParser->_xh['value'], true)."\n---END---"
);
}