X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2FClient.php;h=4e03d3e9d7bbf25f06d04ddf342e24f40292f7cd;hb=b337d292eb5b5656d27a2fc9ab6796be300c59a3;hp=fe4eb5d2183c7162ebe3f503500bedbb0cd0afa2;hpb=affe41f5f2420693ea08b1b9496b6fc5dd786e20;p=plcapi.git diff --git a/src/Client.php b/src/Client.php index fe4eb5d..4e03d3e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,6 +13,8 @@ class Client const USE_CURL_ALWAYS = 1; const USE_CURL_AUTO = 2; + protected static $logger; + /// @todo: do these need to be public? public $method = 'http'; public $server; @@ -88,10 +90,11 @@ class Client /** * The charset encoding that will be used for serializing request sent by the client. - * It defaults to NULL, which means using US-ASCII and encoding all characters outside of the ASCII range using - * their xml character entity representation (this has the benefit that line end characters will not be mangled in - * the transfer, a CR-LF will be preserved as well as a singe LF). - * Valid values are 'US-ASCII', 'UTF-8' and 'ISO-8859-1' + * It defaults to NULL, which means using US-ASCII and encoding all characters outside of the ASCII printable range + * using their xml character entity representation (this has the benefit that line end characters will not be mangled + * in the transfer, a CR-LF will be preserved as well as a singe LF). + * Valid values are 'US-ASCII', 'UTF-8' and 'ISO-8859-1'. + * For the fastest mode of operation, set your both your app internal encoding as well as this to UTF-8. */ public $request_charset_encoding = ''; @@ -115,6 +118,19 @@ class Client */ public $user_agent; + public function getLogger() + { + if (self::$logger === null) { + self::$logger = Logger::instance(); + } + return self::$logger; + } + + public static function setLogger($logger) + { + self::$logger = $logger; + } + /** * @param string $path either the PATH part of the xmlrpc server URL, or complete server URL (in which case you * should use and empty string for all other parameters) @@ -670,7 +686,7 @@ class Client if ($username != '') { $credentials = 'Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n"; if ($authType != 1) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0'); } } @@ -690,7 +706,7 @@ class Client $uri = 'http://' . $server . ':' . $port . $this->path; if ($proxyUsername != '') { if ($proxyAuthType != 1) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported with HTTP 1.0'); + $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"; } @@ -746,7 +762,7 @@ class Client $payload; if ($this->debug > 1) { - Logger::instance()->debugMessage("---SENDING---\n$op\n---END---"); + $this->getLogger()->debugMessage("---SENDING---\n$op\n---END---"); } $contextOptions = array(); @@ -900,7 +916,7 @@ class Client } if ($this->debug > 1) { - Logger::instance()->debugMessage("---SENDING---\n$payload\n---END---"); + $this->getLogger()->debugMessage("---SENDING---\n$payload\n---END---"); } if (!$keepAlive || !$this->xmlrpc_curl_handle) { @@ -976,7 +992,7 @@ class Client if (defined('CURLOPT_HTTPAUTH')) { curl_setopt($curl, CURLOPT_HTTPAUTH, $authType); } elseif ($authType != 1) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install'); } } @@ -1024,7 +1040,7 @@ class Client if (defined('CURLOPT_PROXYAUTH')) { curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyAuthType); } elseif ($proxyAuthType != 1) { - Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install'); + $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install'); } } } @@ -1054,7 +1070,7 @@ class Client $message .= $name . ': ' . $val . "\n"; } $message .= '---END---'; - Logger::instance()->debugMessage($message); + $this->getLogger()->debugMessage($message); } if (!$result) {