3 namespace PhpXmlRpc\Helper;
6 * @todo make constructor private to force users to go through `instance()`
10 protected static $instance = null;
13 * This class is singleton, so that later we can move to DI patterns.
17 public static function instance()
19 if (self::$instance === null) {
20 self::$instance = new self();
23 return self::$instance;
27 * Echoes a debug message, taking care of escaping it when not in console mode.
28 * NB: if the encoding of the message is not known or wrong, and we are working in web mode, there is no guarantee
29 * of 100% accuracy, which kind of defeats the purpose of debugging
31 * @param string $message
32 * @param string $encoding
34 public function debugMessage($message, $encoding = null)
36 // US-ASCII is a warning for PHP and a fatal for HHVM
37 if ($encoding == 'US-ASCII') {
41 if (PHP_SAPI != 'cli') {
43 // avoid warnings on php < 5.4...
44 if (defined('ENT_HTML401')) {
45 $flags = $flags | ENT_HTML401;
47 if (defined('ENT_SUBSTITUTE')) {
48 $flags = $flags | ENT_SUBSTITUTE;
50 if ($encoding != null) {
51 print "<PRE>\n".htmlentities($message, $flags, $encoding)."\n</PRE>";
53 print "<PRE>\n".htmlentities($message, $flags)."\n</PRE>";
59 // let the user see this now in case there's a time out later...
64 * Writes a message to the error log
65 * @param string $message
67 public function errorLog($message)