9 namespace PhpXmlRpc\Helper;
14 protected static $instance = null;
17 * This class is singleton, so that later we can move to DI patterns.
21 public static function instance()
23 if (self::$instance === null) {
24 self::$instance = new self();
27 return self::$instance;
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
35 * @param string $message
36 * @param string $encoding
38 public function debugMessage($message, $encoding=null)
40 // US-ASCII is a warning for PHP and a fatal for HHVM
41 if ($encoding == 'US-ASCII') {
45 if (PHP_SAPI != 'cli') {
46 $flags = ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE;
47 if ($encoding != null) {
48 print "<PRE>\n".htmlentities($message, $flags, $encoding)."\n</PRE>";
50 print "<PRE>\n".htmlentities($message, $flags)."\n</PRE>";
56 // let the user see this now in case there's a time out later...