Fix one phpdoc
[plcapi.git] / src / Helper / Logger.php
1 <?php
2 /**
3  * Created by PhpStorm.
4  * User: gg
5  * Date: 12/04/2015
6  * Time: 12:11
7  */
8
9 namespace PhpXmlRpc\Helper;
10
11
12 class Logger
13 {
14     protected static $instance = null;
15
16     /**
17      * This class is singleton, so that later we can move to DI patterns.
18      *
19      * @return Logger
20      */
21     public static function instance()
22     {
23         if (self::$instance === null) {
24             self::$instance = new self();
25         }
26
27         return self::$instance;
28     }
29
30     /**
31      * Echoes a debug message, taking care of escaping it when not in console mode.
32      * NB: if the encoding of the message is not known or wrong, and we are working in web mode, there is no guarantee
33      *     of 100% accuracy, which kind of defeats the purpose of debugging
34      *
35      * @param string $message
36      * @param string $encoding
37      */
38     public function debugMessage($message, $encoding=null)
39     {
40         if (PHP_SAPI != 'cli') {
41             $flags = ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE;
42             if ($encoding != null) {
43                 print "<PRE>\n".htmlentities($message, $flags, $encoding)."\n</PRE>";
44             } else {
45                 print "<PRE>\n".htmlentities($message, $flags)."\n</PRE>";
46             }
47         } else {
48             print "\n$message\n";
49         }
50
51         // let the user see this now in case there's a time out later...
52         flush();
53     }
54 }