3 namespace PhpXmlRpc\Helper;
7 protected static $instance = null;
10 * This class is singleton, so that later we can move to DI patterns.
14 public static function instance()
16 if (self::$instance === null) {
17 self::$instance = new self();
20 return self::$instance;
24 * Echoes a debug message, taking care of escaping it when not in console mode.
25 * NB: if the encoding of the message is not known or wrong, and we are working in web mode, there is no guarantee
26 * of 100% accuracy, which kind of defeats the purpose of debugging
28 * @param string $message
29 * @param string $encoding
31 public function debugMessage($message, $encoding = null)
33 // US-ASCII is a warning for PHP and a fatal for HHVM
34 if ($encoding == 'US-ASCII') {
38 if (PHP_SAPI != 'cli') {
40 // avoid warnings on php < 5.4...
41 if (defined('ENT_HTML401')) {
42 $flags = $flags | ENT_HTML401;
44 if (defined('ENT_SUBSTITUTE')) {
45 $flags = $flags | 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...
61 * Writes a message to the error log
63 public function errorLog($message)