Change platforms tested on Travis
[plcapi.git] / src / Helper / Logger.php
index cb0ab10..77e0e14 100644 (file)
@@ -1,16 +1,25 @@
 <?php
-/**
- * Created by PhpStorm.
- * User: gg
- * Date: 12/04/2015
- * Time: 12:11
- */
 
 namespace PhpXmlRpc\Helper;
 
-
 class Logger
 {
+    protected static $instance = null;
+
+    /**
+     * This class is singleton, so that later we can move to DI patterns.
+     *
+     * @return Logger
+     */
+    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
@@ -19,8 +28,13 @@ class Logger
      * @param string $message
      * @param string $encoding
      */
-    public static function debugMessage($message, $encoding=null)
+    public function debugMessage($message, $encoding=null)
     {
+        // US-ASCII is a warning for PHP and a fatal for HHVM
+        if ($encoding == 'US-ASCII') {
+            $encoding = 'UTF-8';
+        }
+
         if (PHP_SAPI != 'cli') {
             $flags = ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE;
             if ($encoding != null) {
@@ -35,4 +49,4 @@ class Logger
         // let the user see this now in case there's a time out later...
         flush();
     }
-}
\ No newline at end of file
+}