data = $data; } static function addWarning ($domain, $code, $message) { if (!isset (self::$reply->warnings)) self::$reply->warnings = []; self::$reply->warnings[] = new Message ($domain, $code, $message); } static function setError ($domain, $code, $message) { self::$reply->data = NULL; self::$reply->error = new Message ($domain, $code, $message); } static function exceptionHandler ($e) { // XXX: Exception trace //$trace = array_pop (debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS, 2)); self::setError ('PHP', 'exception', $e->getMessage ()); self::sendReply (); } static function errorHandler ($errno, $message, $file, $line, $context) { switch ($errno) { case E_ERROR: case E_PARSE: case E_CORE_ERROR: case E_USER_ERROR: case E_COMPILE_ERROR: self::setError ('PHP', $errno, "$file:$line:$message"); break; default: self::addWarning ('PHP', $errno, "$file:$line:$message"); } return TRUE; } static function sendReply () { header ('Content-Type: application/json; charset=UTF-8'); echo json_encode (self::$reply); } } ?>