implement Psr/Log interfaces
authorgggeek <giunta.gaetano@gmail.com>
Tue, 24 Jan 2023 14:13:31 +0000 (14:13 +0000)
committergggeek <giunta.gaetano@gmail.com>
Tue, 24 Jan 2023 14:13:31 +0000 (14:13 +0000)
13 files changed:
NEWS.md
demo/client/loggerinjection.php
src/Client.php
src/Encoder.php
src/Helper/Charset.php
src/Helper/Http.php
src/Helper/Logger.php
src/Helper/XMLParser.php
src/Request.php
src/Server.php
src/Value.php
src/Wrapper.php
tests/04LoggerTest.php

diff --git a/NEWS.md b/NEWS.md
index 6e0f5a8..1014ba9 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -78,6 +78,8 @@
 * new: methods `Wrapper::holdObject()` and `Wrapper::getheldObject()`, allowing flexibility in storing object instances
   for code-generation scenarios involving `Wrapper::wrapPhpClass` and `Wrapper::wrapPhpFunction`
 
+* improved: the `Logger` class now sports methods adhering to Psr\Log\LoggerInterface
+
 * improved: made sure all debug output goes through the logger at response parsing time (there was one printf call left)
 
 * improved: all the Client's `setSomething()` methods now return the client object, allowing for usage of fluent style
     changed: it now returns a Response for the cases in which it previously returned false, and an array of Response
     objects for the cases in which it previously returned a string
   - if you subclassed the `Client` class, take care of new static variables `$requestClass` and `$responseClass`
+  - if you replaced the Logger class, take care that you will have to implement methods `error` and `debug`
   - traits have been introduced for all classes dealing with Logger, XMLParser and CharsetEncoder; method `setCharsetEncoder`
     is now static
 
index 9d2133c..b5f89a2 100644 (file)
@@ -20,13 +20,13 @@ class MyLogger
     protected $errorBuffer = '';
 
     // logger API
-    public function debugMessage($message, $encoding = null)
+    public function debug($message, $context = array())
     {
         $this->debugBuffer .= $message . "\n";
     }
 
     // logger API
-    public function errorLog($message)
+    public function error($message, $context = array())
     {
         $this->errorBuffer .= $message . "\n";
     }
index 571b56d..150f9e2 100644 (file)
@@ -866,7 +866,7 @@ class Client
             $credentials = 'Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
             if ($authType != 1) {
                 /// @todo make this a proper error, i.e. return a failure
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported with HTTP 1.0');
             }
         }
 
@@ -888,7 +888,7 @@ class Client
             if ($proxyUsername != '') {
                 if ($proxyAuthType != 1) {
                     /// @todo make this a proper error, i.e. return a failure
-                    $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported with HTTP 1.0');
+                    $this->getLogger()->error('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";
             }
@@ -944,7 +944,7 @@ class Client
             $payload;
 
         if ($this->debug > 1) {
-            $this->getLogger()->debugMessage("---SENDING---\n$op\n---END---");
+            $this->getLogger()->debug("---SENDING---\n$op\n---END---");
         }
 
         $contextOptions = array();
@@ -1094,7 +1094,7 @@ class Client
                 $message .= $name . ': ' . $val . "\n";
             }
             $message .= '---END---';
-            $this->getLogger()->debugMessage($message);
+            $this->getLogger()->debug($message);
         }
 
         if (!$result) {
@@ -1171,7 +1171,7 @@ class Client
                     // http, https
                     $protocol = $method;
                     if (strpos($protocol, ':') !== false) {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": warning - attempted hacking attempt?. The curl protocol requested for the call is: '$protocol'");
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": warning - attempted hacking attempt?. The curl protocol requested for the call is: '$protocol'");
                         return false;
                     }
                 }
@@ -1247,7 +1247,7 @@ class Client
                     curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE);
                 } else {
                     /// @todo make this a proper error, i.e. return a failure
-                    $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. HTTP2 is not supported by the current PHP/curl install');
+                    $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': warning. HTTP2 is not supported by the current PHP/curl install');
                 }
                 break;
             case 'h2':
@@ -1261,7 +1261,7 @@ class Client
                 curl_setopt($curl, CURLOPT_HTTPAUTH, $authType);
             } elseif ($authType != 1) {
                 /// @todo make this a proper error, i.e. return a failure
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth is supported by the current PHP/curl install');
             }
         }
 
@@ -1311,7 +1311,7 @@ class Client
                     curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyAuthType);
                 } elseif ($proxyAuthType != 1) {
                     /// @todo make this a proper error, i.e. return a failure
-                    $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
+                    $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
                 }
             }
         }
@@ -1331,7 +1331,7 @@ class Client
         }
 
         if ($this->debug > 1) {
-            $this->getLogger()->debugMessage("---SENDING---\n$payload\n---END---");
+            $this->getLogger()->debug("---SENDING---\n$payload\n---END---");
         }
 
         return $curl;
index bcb3971..2d59338 100644 (file)
@@ -310,7 +310,7 @@ class Encoder
                     if ($valEncoding == 'ISO-8859-1') {
                         $xmlVal = utf8_encode($xmlVal);
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding);
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of xml text: ' . $valEncoding);
                     }
                 }
             }
@@ -335,7 +335,7 @@ class Encoder
         if ($xmlRpcParser->_xh['isf'] > 1) {
             // test that $xmlrpc->_xh['value'] is an obj, too???
 
-            $this->getLogger()->errorLog($xmlRpcParser->_xh['isf_reason']);
+            $this->getLogger()->error($xmlRpcParser->_xh['isf_reason']);
 
             return false;
         }
index 0bced4f..d25ee3e 100644 (file)
@@ -301,7 +301,7 @@ class Charset
                     }
                     if ($data === false) {
                         $escapedData = '';
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": Converting from $srcEncoding to $destEncoding via mbstring: failed...");
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": Converting from $srcEncoding to $destEncoding via mbstring: failed...");
                     } else {
                         if ($srcEncoding === 'UTF-8') {
                             $escapedData = $data;
@@ -311,7 +311,7 @@ class Charset
                     }
                 } else {
                     $escapedData = '';
-                    $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": Converting from $srcEncoding to $destEncoding: not supported...");
+                    $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": Converting from $srcEncoding to $destEncoding: not supported...");
                 }
         }
 
index 0e30556..a10c64f 100644 (file)
@@ -98,7 +98,7 @@ class Http
                 // this filters out all http headers from proxy. maybe we could take them into account, too?
                 $data = substr($data, $bd);
             } else {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': HTTPS via proxy error, tunnel connection possibly failed');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': HTTPS via proxy error, tunnel connection possibly failed');
                 throw new HttpException(PhpXmlRpc::$xmlrpcstr['http_error'] . ' (HTTPS via proxy error, tunnel connection possibly failed)', PhpXmlRpc::$xmlrpcerr['http_error']);
             }
         }
@@ -133,7 +133,7 @@ class Http
 
         if ($httpResponse['status_code'] !== '200') {
             $errstr = substr($data, 0, strpos($data, "\n") - 1);
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': HTTP error, got response: ' . $errstr);
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': HTTP error, got response: ' . $errstr);
             throw new HttpException(PhpXmlRpc::$xmlrpcstr['http_error'] . ' (' . $errstr . ')', PhpXmlRpc::$xmlrpcerr['http_error'], null, $httpResponse['status_code']);
         }
 
@@ -218,7 +218,7 @@ class Http
             foreach ($httpResponse['cookies'] as $header => $value) {
                 $msg .= "COOKIE: $header={$value['value']}\n";
             }
-            $this->getLogger()->debugMessage($msg);
+            $this->getLogger()->debug($msg);
         }
 
         // if CURL was used for the call, http headers have been processed, and dechunking + reinflating have been carried out
@@ -227,7 +227,7 @@ class Http
             // Decode chunked encoding sent by http 1.1 servers
             if (isset($httpResponse['headers']['transfer-encoding']) && $httpResponse['headers']['transfer-encoding'] == 'chunked') {
                 if (!$data = static::decodeChunked($data)) {
-                    $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to rebuild the chunked data received from server');
+                    $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to rebuild the chunked data received from server');
                     throw new HttpException(PhpXmlRpc::$xmlrpcstr['dechunk_fail'], PhpXmlRpc::$xmlrpcerr['dechunk_fail'], null, $httpResponse['status_code']);
                 }
             }
@@ -242,19 +242,19 @@ class Http
                         if ($httpResponse['headers']['content-encoding'] == 'deflate' && $degzdata = @gzuncompress($data)) {
                             $data = $degzdata;
                             if ($debug) {
-                                $this->getLogger()->debugMessage("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
+                                $this->getLogger()->debug("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
                             }
                         } elseif ($httpResponse['headers']['content-encoding'] == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {
                             $data = $degzdata;
                             if ($debug) {
-                                $this->getLogger()->debugMessage("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
+                                $this->getLogger()->debug("---INFLATED RESPONSE---[" . strlen($data) . " chars]---\n$data\n---END---");
                             }
                         } else {
-                            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to decode the deflated data received from server');
+                            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': errors occurred when trying to decode the deflated data received from server');
                             throw new HttpException(PhpXmlRpc::$xmlrpcstr['decompress_fail'], PhpXmlRpc::$xmlrpcerr['decompress_fail'], null, $httpResponse['status_code']);
                         }
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': the server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': the server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
                         throw new HttpException(PhpXmlRpc::$xmlrpcstr['cannot_decompress'], PhpXmlRpc::$xmlrpcerr['cannot_decompress'], null, $httpResponse['status_code']);
                     }
                 }
index 1f452c4..a4056e5 100644 (file)
@@ -11,7 +11,7 @@ class Logger
     protected static $instance = null;
 
     /**
-     * This class can be used as singleton, so that later we can move to DI patterns.
+     * This class can be used as singleton, so that later we can move to DI patterns (ish...)
      *
      * @return Logger
      */
@@ -24,14 +24,48 @@ class Logger
         return self::$instance;
     }
 
+    // *** Implement the same interface as PSR/LOG, for the sake of interoperability ***
+
+    /**
+     * NB: unlike other "traditional" loggers, this one echoes to screen the debug messages instead of logging them.
+     *
+     * @param string $message
+     * @param array $context known key: 'encoding'
+     * @return void
+     */
+    public function debug($message, $context = array())
+    {
+        if (isset($context['encoding'])) {
+            $this->debugMessage($message, $context['encoding']);
+        } else {
+            $this->debugMessage($message);
+        }
+    }
+
+    /**
+     * Triggers the writing of a message to php's error log
+     *
+     * @param string $message
+     * @param array $context
+     * @return void
+     */
+    public function error($message, $context = array())
+    {
+        $this->errorLog($message);
+    }
+
+    // BC interface
+
     /**
      * 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
      *     of 100% accuracy, which kind of defeats the purpose of debugging
      *
      * @param string $message
-     * @param string $encoding
+     * @param string $encoding deprecated
      * @return void
+     *
+     * @internal left in purely for BC
      */
     public function debugMessage($message, $encoding = null)
     {
@@ -64,8 +98,11 @@ class Logger
 
     /**
      * Writes a message to the error log.
+     *
      * @param string $message
      * @return void
+     *
+     * @internal left in purely for BC
      */
     public function errorLog($message)
     {
index 019d003..314aa8c 100644 (file)
@@ -180,7 +180,7 @@ class XMLParser
                         if (function_exists('mb_convert_encoding')) {
                             $this->current_parsing_options['target_charset'] = $val;
                         } else {
-                            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": 'target_charset' option is unsupported without mbstring");
+                            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": 'target_charset' option is unsupported without mbstring");
                         }
                         break;
 
@@ -191,7 +191,7 @@ class XMLParser
                             //$this->_xh['isf'] = 4;
                             //$this->_xh['isf_reason'] = "Callback passed as 'methodname_callback' is not callable";
                             //return;
-                            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": Callback passed as 'methodname_callback' is not callable");
+                            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": Callback passed as 'methodname_callback' is not callable");
                         }
                         break;
 
@@ -202,7 +202,7 @@ class XMLParser
                         break;
 
                     default:
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ": unsupported option: $key");
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ": unsupported option: $key");
                 }
                 unset($mergedOptions[$key]);
             }
@@ -578,7 +578,7 @@ class XMLParser
                             $this->_xh['isf_reason'] = 'Invalid data received in BOOLEAN value: ' . $this->truncateForLog($this->_xh['ac']);
                             return;
                         } else {
-                            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid data received in BOOLEAN value: ' .
+                            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': invalid data received in BOOLEAN value: ' .
                                 $this->truncateForLog($this->_xh['ac']));
                         }
                     }
@@ -603,7 +603,7 @@ class XMLParser
                         $this->_xh['isf_reason'] = 'Non numeric data received in INT value: ' . $this->truncateForLog($this->_xh['ac']);
                         return;
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': non numeric data received in INT: ' .
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': non numeric data received in INT: ' .
                             $this->truncateForLog($this->_xh['ac']));
                     }
                     /// @todo: find a better way of reporting an error value than this! Use NaN?
@@ -624,7 +624,7 @@ class XMLParser
                             $this->truncateForLog($this->_xh['ac']);
                         return;
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': non numeric data received in DOUBLE value: ' .
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': non numeric data received in DOUBLE value: ' .
                             $this->truncateForLog($this->_xh['ac']));
                     }
 
@@ -644,7 +644,7 @@ class XMLParser
                         $this->_xh['isf_reason'] = 'Invalid data received in DATETIME value: ' . $this->truncateForLog($this->_xh['ac']);
                         return;
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid data received in DATETIME value: ' .
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': invalid data received in DATETIME value: ' .
                             $this->truncateForLog($this->_xh['ac']));
                     }
                 }
@@ -653,7 +653,7 @@ class XMLParser
                         $this->_xh['value'] = new \DateTime($this->_xh['ac']);
                     } catch(\Exception $e) {
                         // q: what to do? we can not guarantee that a valid date can be created. Return null or throw?
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': ' . $e->getMessage());
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': ' . $e->getMessage());
                         $this->_xh['value'] = null;
                     }
                 } else {
@@ -675,7 +675,7 @@ class XMLParser
                     $v = base64_decode($this->_xh['ac']);
                     if ($v === '' && $this->_xh['ac'] !== '') {
                         // only the empty string should decode to the empty string
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid data received in BASE64 value: ' .
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': invalid data received in BASE64 value: ' .
                             $this->truncateForLog($this->_xh['ac']));
                     }
                 }
@@ -696,7 +696,7 @@ class XMLParser
                             $this->_xh['isf_reason'] = 'Missing NAME inside STRUCT in received xml';
                             return;
                         } else {
-                            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': missing NAME inside STRUCT in received xml');
+                            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': missing NAME inside STRUCT in received xml');
                         }
                         $this->_xh['valuestack'][$vscount - 1]['name'] = '';
                     }
@@ -707,7 +707,7 @@ class XMLParser
                         $this->_xh['isf_reason'] = 'Missing VALUE inside STRUCT in received xml';
                         return;
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': missing VALUE inside STRUCT in received xml');
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': missing VALUE inside STRUCT in received xml');
                     }
                 }
                 break;
@@ -738,7 +738,7 @@ class XMLParser
                         $this->_xh['isf_reason'] = 'Missing VALUE inside PARAM in received xml';
                         return;
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': missing VALUE inside PARAM in received xml');
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': missing VALUE inside PARAM in received xml');
                     }
                 }
                 break;
@@ -750,7 +750,7 @@ class XMLParser
                         $this->_xh['isf_reason'] = 'Invalid data received in METHODNAME: '. $this->truncateForLog($this->_xh['ac']);
                         return;
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid data received in METHODNAME: '.
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': invalid data received in METHODNAME: '.
                             $this->truncateForLog($this->_xh['ac']));
                     }
                 }
index a715991..7760be5 100644 (file)
@@ -207,14 +207,14 @@ class Request
     public function parseResponse($data = '', $headersProcessed = false, $returnType = XMLParser::RETURN_XMLRPCVALS)
     {
         if ($this->debug > 0) {
-            $this->getLogger()->debugMessage("---GOT---\n$data\n---END---");
+            $this->getLogger()->debug("---GOT---\n$data\n---END---");
         }
 
         $httpResponse = array('raw_data' => $data, 'headers' => array(), 'cookies' => array());
         $this->httpResponse = $httpResponse;
 
         if ($data == '') {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': no response received from server.');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': no response received from server.');
             return new Response(0, PhpXmlRpc::$xmlrpcerr['no_data'], PhpXmlRpc::$xmlrpcstr['no_data']);
         }
 
@@ -262,8 +262,8 @@ class Request
                 $start += strlen('<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
                 $end = strpos($data, '-->', $start);
                 $comments = substr($data, $start, $end - $start);
-                $this->getLogger()->debugMessage("---SERVER DEBUG INFO (DECODED) ---\n\t" .
-                    str_replace("\n", "\n\t", base64_decode($comments)) . "\n---END---", $respEncoding);
+                $this->getLogger()->debug("---SERVER DEBUG INFO (DECODED) ---\n\t" .
+                    str_replace("\n", "\n\t", base64_decode($comments)) . "\n---END---", array('encoding' => $respEncoding));
             }
         }
 
@@ -285,7 +285,7 @@ class Request
                     if ($respEncoding == 'ISO-8859-1') {
                         $data = utf8_encode($data);
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': unsupported charset encoding of received response: ' . $respEncoding);
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': unsupported charset encoding of received response: ' . $respEncoding);
                     }
                 }
             }
@@ -316,7 +316,7 @@ class Request
             );
 
             if ($this->debug > 0) {
-                $this->getLogger()->debugMessage($xmlRpcParser->_xh['isf_reason']);
+                $this->getLogger()->debug($xmlRpcParser->_xh['isf_reason']);
             }
         }
         // second error check: xml well-formed but not xml-rpc compliant
@@ -328,7 +328,7 @@ class Request
 
             /// @todo echo something for the user? check if this was already done by the parser...
             //if ($this->debug > 0) {
-            //    $this->getLogger()->debugMessage($xmlRpcParser->_xh['isf_reason']);
+            //    $this->getLogger()->debug($xmlRpcParser->_xh['isf_reason']);
             //}
         }
         // third error check: parsing of the response has somehow gone boink.
@@ -342,7 +342,7 @@ class Request
             /// @todo echo something for the user?
         } else {
             if ($this->debug > 1) {
-                $this->getLogger()->debugMessage(
+                $this->getLogger()->debug(
                     "---PARSED---\n".var_export($xmlRpcParser->_xh['value'], true)."\n---END---"
                 );
             }
index 76ccd54..632c395 100644 (file)
@@ -324,7 +324,7 @@ class Server
                 header('Content-Length: ' . (int)strlen($payload));
             }
         } else {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': http headers already sent before response is fully generated. Check for php warning or error messages');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': http headers already sent before response is fully generated. Check for php warning or error messages');
         }
 
         print $payload;
@@ -427,7 +427,7 @@ class Server
         // check if $_SERVER is populated: it might have been disabled via ini file
         // (this is true even when in CLI mode)
         if (count($_SERVER) == 0) {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated');
         }
 
         if ($this->debug > 1) {
@@ -548,7 +548,7 @@ class Server
                     if ($reqEncoding == 'ISO-8859-1') {
                         $data = utf8_encode($data);
                     } else {
-                        $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': unsupported charset encoding of received request: ' . $reqEncoding);
+                        $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': unsupported charset encoding of received request: ' . $reqEncoding);
                     }
                 }
             }
@@ -685,7 +685,7 @@ class Server
 
         // verify that function to be invoked is in fact callable
         if (!is_callable($func)) {
-            $this->getLogger()->errorLog("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler is not callable");
+            $this->getLogger()->error("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler is not callable");
             return new Response(
                 0,
                 PhpXmlRpc::$xmlrpcerr['server_error'],
@@ -709,7 +709,7 @@ class Server
                     $r = call_user_func($func, $req);
                 }
                 if (!is_a($r, 'PhpXmlRpc\Response')) {
-                    $this->getLogger()->errorLog("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler does not return an xmlrpc response object but a " . gettype($r));
+                    $this->getLogger()->error("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler does not return an xmlrpc response object but a " . gettype($r));
                     if (is_a($r, 'PhpXmlRpc\Value')) {
                         $r = new Response($r);
                     } else {
@@ -1285,10 +1285,11 @@ class Server
             // The previous error handler was the default: all we should do is log error
             // to the default error log (if level high enough)
             if (ini_get('log_errors') && (intval(ini_get('error_reporting')) & $errCode)) {
+                // sadly we can't use the functionality of LoggerAware, because this is a static method
                 if (self::$logger === null) {
                     self::$logger = Logger::instance();
                 }
-                self::$logger->errorLog($errString);
+                self::$logger->error($errString);
             }
         } else {
             // Pass control on to previous error handler, trying to avoid loops...
index f0203e0..a12c98f 100644 (file)
@@ -93,7 +93,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
                     $this->me['struct'] = $val;
                     break;
                 default:
-                    $this->getLogger()->errorLog("XML-RPC: " . __METHOD__ . ": not a known type ($type)");
+                    $this->getLogger()->error("XML-RPC: " . __METHOD__ . ": not a known type ($type)");
             }
         }
     }
@@ -117,7 +117,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
         }
 
         if ($typeOf !== 1) {
-            $this->getLogger()->errorLog("XML-RPC: " . __METHOD__ . ": not a scalar type ($type)");
+            $this->getLogger()->error("XML-RPC: " . __METHOD__ . ": not a scalar type ($type)");
             return 0;
         }
 
@@ -134,10 +134,10 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
 
         switch ($this->mytype) {
             case 1:
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': scalar xmlrpc value can have only one value');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': scalar xmlrpc value can have only one value');
                 return 0;
             case 3:
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': cannot add anonymous scalar to struct xmlrpc value');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': cannot add anonymous scalar to struct xmlrpc value');
                 return 0;
             case 2:
                 // we're adding a scalar value to an array here
@@ -179,7 +179,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
 
             return 1;
         } else {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': already initialized as a [' . $this->kindOf() . ']');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': already initialized as a [' . $this->kindOf() . ']');
             return 0;
         }
     }
@@ -209,7 +209,7 @@ class Value implements \Countable, \IteratorAggregate, \ArrayAccess
 
             return 1;
         } else {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': already initialized as a [' . $this->kindOf() . ']');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': already initialized as a [' . $this->kindOf() . ']');
             return 0;
         }
     }
index 8beb5b3..bf613c5 100644 (file)
@@ -174,7 +174,7 @@ class Wrapper
         }
         if (is_array($callable)) {
             if (count($callable) < 2 || (!is_string($callable[0]) && !is_object($callable[0]))) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': syntax for function to be wrapped is wrong');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': syntax for function to be wrapped is wrong');
                 return false;
             }
             if (is_string($callable[0])) {
@@ -186,7 +186,7 @@ class Wrapper
         } else if ($callable instanceof \Closure) {
             // we do not support creating code which wraps closures, as php does not allow to serialize them
             if (!$buildIt) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': a closure can not be wrapped in generated source code');
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': a closure can not be wrapped in generated source code');
                 return false;
             }
 
@@ -198,7 +198,7 @@ class Wrapper
         }
 
         if (!$exists) {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': function to be wrapped is not defined: ' . $plainFuncName);
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': function to be wrapped is not defined: ' . $plainFuncName);
             return false;
         }
 
@@ -242,23 +242,23 @@ class Wrapper
         if (is_array($callable)) {
             $func = new \ReflectionMethod($callable[0], $callable[1]);
             if ($func->isPrivate()) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is private: ' . $plainFuncName);
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': method to be wrapped is private: ' . $plainFuncName);
                 return false;
             }
             if ($func->isProtected()) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is protected: ' . $plainFuncName);
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': method to be wrapped is protected: ' . $plainFuncName);
                 return false;
             }
             if ($func->isConstructor()) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the constructor: ' . $plainFuncName);
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the constructor: ' . $plainFuncName);
                 return false;
             }
             if ($func->isDestructor()) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the destructor: ' . $plainFuncName);
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': method to be wrapped is the destructor: ' . $plainFuncName);
                 return false;
             }
             if ($func->isAbstract()) {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': method to be wrapped is abstract: ' . $plainFuncName);
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': method to be wrapped is abstract: ' . $plainFuncName);
                 return false;
             }
             /// @todo add more checks for static vs. nonstatic?
@@ -268,7 +268,7 @@ class Wrapper
         if ($func->isInternal()) {
             /// @todo from PHP 5.1.0 onward, we should be able to use invokeargs instead of getparameters to fully
             ///       reflect internal php functions
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': function to be wrapped is internal: ' . $plainFuncName);
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': function to be wrapped is internal: ' . $plainFuncName);
             return false;
         }
 
@@ -775,7 +775,7 @@ class Wrapper
         $client->setDebug($debug);
         $response = $client->send($req, $timeout, $protocol);
         if ($response->faultCode()) {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature from remote server for method ' . $methodName);
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature from remote server for method ' . $methodName);
             return false;
         }
 
@@ -787,7 +787,7 @@ class Wrapper
         }
 
         if (!is_array($mSig) || count($mSig) <= $sigNum) {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature nr.' . $sigNum . ' from remote server for method ' . $methodName);
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': could not retrieve method signature nr.' . $sigNum . ' from remote server for method ' . $methodName);
             return false;
         }
 
@@ -1091,7 +1091,7 @@ class Wrapper
         $req = new $reqClass('system.listMethods');
         $response = $client->send($req, $timeout, $protocol);
         if ($response->faultCode()) {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve method list from remote server');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': could not retrieve method list from remote server');
 
             return false;
         }
@@ -1102,7 +1102,7 @@ class Wrapper
             $mList = $decoder->decode($mList);
         }
         if (!is_array($mList) || !count($mList)) {
-            $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not retrieve meaningful method list from remote server');
+            $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': could not retrieve meaningful method list from remote server');
 
             return false;
         }
@@ -1152,7 +1152,7 @@ class Wrapper
                     }
 
                 } else {
-                    $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': will not create class method to wrap remote method ' . $mName);
+                    $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': will not create class method to wrap remote method ' . $mName);
                 }
             }
         }
@@ -1163,7 +1163,7 @@ class Wrapper
             if ($allOK) {
                 return $xmlrpcClassName;
             } else {
-                $this->getLogger()->errorLog('XML-RPC: ' . __METHOD__ . ': could not create class ' . $xmlrpcClassName . ' to wrap remote server ' . $client->server);
+                $this->getLogger()->error('XML-RPC: ' . __METHOD__ . ': could not create class ' . $xmlrpcClassName . ' to wrap remote server ' . $client->server);
                 return false;
             }
         } else {
index b857997..12c10f1 100644 (file)
@@ -67,12 +67,12 @@ class LoggerTest extends PhpXmlRpc_PolyfillTestCase
 
     // logger API
 
-    public function debugMessage($message, $encoding = null)
+    public function debug($message, $context = array())
     {
         $this->debugBuffer .= $message;
     }
 
-    public function errorLog($message)
+    public function error($message, $context = array())
     {
         $this->errorBuffer .= $message;
     }