travis tests
[plcapi.git] / src / Server.php
index 6921b7e..3516f94 100644 (file)
@@ -2,8 +2,9 @@
 
 namespace PhpXmlRpc;
 
-use PhpXmlRpc\Helper\XMLParser;
+use PhpXmlRpc\Helper\Logger;
 use PhpXmlRpc\Helper\Charset;
+use PhpXmlRpc\Helper\XMLParser;
 
 /**
  * Allows effortless implementation of XML-RPC servers
@@ -142,10 +143,9 @@ class Server
     }
 
     /**
-     * Add a string to the debug info that can be later serialized by the server
-     * as part of the response message.
-     * Note that for best compatibility, the debug string should be encoded using
-     * the PhpXmlRpc::$xmlrpc_internalencoding character set.
+     * Add a string to the debug info that can be later serialized by the server as part of the response message.
+     * Note that for best compatibility, the debug string should be encoded using the PhpXmlRpc::$xmlrpc_internalencoding
+     * character set.
      *
      * @param string $msg
      * @access public
@@ -271,13 +271,15 @@ class Server
                 }
             }
 
-            // do not output content-length header if php is compressing output for us:
-            // it will mess up measurements
+            // Do not output content-length header if php is compressing output for us:
+            // it will mess up measurements.
+            // Note that Apache/mod_php will add (and even alter!) the Content-Length header on its own, but only for
+            // responses up to 8000 bytes
             if ($phpNoSelfCompress) {
                 header('Content-Length: ' . (int)strlen($payload));
             }
         } else {
-            error_log('XML-RPC: ' . __METHOD__ . ': http headers already sent before response is fully generated. Check for php warning or error messages');
+            Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': http headers already sent before response is fully generated. Check for php warning or error messages');
         }
 
         print $payload;
@@ -371,7 +373,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) {
-            error_log('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated');
+            Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': cannot parse request headers as $_SERVER is not populated');
         }
 
         if ($this->debug > 1) {
@@ -474,8 +476,11 @@ class Server
         // decompose incoming XML into request structure
 
         if ($reqEncoding != '') {
-            // Since parsing will fail if charset is not specified in the xml prologue,
-            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
+            // Since parsing will fail if
+            // - charset is not specified in the xml prologue,
+            // - the encoding is not UTF8 and
+            // - there are non-ascii chars in the text,
+            // we try to work round that...
             // The following code might be better for mb_string enabled installs, but
             // makes the lib about 200% slower...
             //if (!is_valid_charset($reqEncoding, array('UTF-8')))
@@ -486,7 +491,7 @@ class Server
                     if (extension_loaded('mbstring')) {
                         $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding);
                     } else {
-                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding);
+                        Logger::instance()->errorLog('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding);
                     }
                 }
             }
@@ -615,7 +620,7 @@ class Server
 
         // verify that function to be invoked is in fact callable
         if (!is_callable($func)) {
-            error_log("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler is not callable");
+            Logger::instance()->errorLog("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler is not callable");
             return new Response(
                 0,
                 PhpXmlRpc::$xmlrpcerr['server_error'],
@@ -638,7 +643,7 @@ class Server
                     $r = call_user_func($func, $req);
                 }
                 if (!is_a($r, 'PhpXmlRpc\Response')) {
-                    error_log("XML-RPC: " . __METHOD__ . ": function '$funcName' registered as method handler does not return an xmlrpc response object but a " . gettype($r));
+                    Logger::instance()->errorLog("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 {
@@ -693,7 +698,6 @@ class Server
                         }
                     }
                     throw $e;
-                    break;
                 case 1:
                     $r = new Response(0, $e->getCode(), $e->getMessage());
                     break;
@@ -909,7 +913,7 @@ class Server
         }
         if (isset($dmap[$methName])) {
             if (isset($dmap[$methName]['docstring'])) {
-                $r = new Response(new Value($dmap[$methName]['docstring']), 'string');
+                $r = new Response(new Value($dmap[$methName]['docstring'], 'string'));
             } else {
                 $r = new Response(new Value('', 'string'));
             }
@@ -1076,7 +1080,7 @@ 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)) {
-                error_log($errString);
+                Logger::instance()->errorLog($errString);
             }
         } else {
             // Pass control on to previous error handler, trying to avoid loops...