3 namespace PhpXmlRpc\Helper;
6 * @todo implement an interface
7 * @todo make constructor private to force users to go through `instance()` ?
11 protected static $instance = null;
14 * This class can be used as singleton, so that later we can move to DI patterns.
18 public static function instance()
20 if (self::$instance === null) {
21 self::$instance = new self();
24 return self::$instance;
28 * Echoes a debug message, taking care of escaping it when not in console mode.
29 * NB: if the encoding of the message is not known or wrong, and we are working in web mode, there is no guarantee
30 * of 100% accuracy, which kind of defeats the purpose of debugging
32 * @param string $message
33 * @param string $encoding
35 public function debugMessage($message, $encoding = null)
37 // US-ASCII is a warning for PHP and a fatal for HHVM
38 if ($encoding == 'US-ASCII') {
42 if (PHP_SAPI != 'cli') {
44 // avoid warnings on php < 5.4...
45 if (defined('ENT_HTML401')) {
46 $flags = $flags | ENT_HTML401;
48 if (defined('ENT_SUBSTITUTE')) {
49 $flags = $flags | ENT_SUBSTITUTE;
51 if ($encoding != null) {
52 print "<PRE>\n".htmlentities($message, $flags, $encoding)."\n</PRE>";
54 print "<PRE>\n".htmlentities($message, $flags)."\n</PRE>";
60 // let the user see this now in case there's a time out later...
65 * Writes a message to the error log
66 * @param string $message
68 public function errorLog($message)