cb0ab104fc5125a063b2e4a708aa60e6f744f5be
[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     /**
15      * Echoes a debug message, taking care of escaping it when not in console mode.
16      * NB: if the encoding of the message is not known or wrong, and we are working in web mode, there is no guarantee
17      *     of 100% accuracy, which kind of defeats the purpose of debugging
18      *
19      * @param string $message
20      * @param string $encoding
21      */
22     public static function debugMessage($message, $encoding=null)
23     {
24         if (PHP_SAPI != 'cli') {
25             $flags = ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE;
26             if ($encoding != null) {
27                 print "<PRE>\n".htmlentities($message, $flags, $encoding)."\n</PRE>";
28             } else {
29                 print "<PRE>\n".htmlentities($message, $flags)."\n</PRE>";
30             }
31         } else {
32             print "\n$message\n";
33         }
34
35         // let the user see this now in case there's a time out later...
36         flush();
37     }
38 }