/** * Set the error name and message (also reports to the monitor * @see JPSpan_Monitor * @param int error code * @param string name to be given to Javascript error class * @param string error message * @return void * @access public */ function setError($code, $name, $message) { $this->code = $code; $this->name = $name; $this->message = $message; require_once JPSPAN . 'Monitor.php'; $M =& JPSpan_Monitor::instance(); $M->announceError($name, $code, $message, __FILE__, __LINE__); }
/** * Serve a request * @param boolean send headers * @return boolean FALSE if failed (invalid request - see errors) * @access public */ function serve($sendHeaders = TRUE) { require_once JPSPAN . 'Monitor.php'; $M =& JPSpan_Monitor::instance(); $this->calledClass = NULL; $this->calledMethod = NULL; if ($this->resolveCall()) { $M->setRequestInfo('class', $this->calledClass); $M->setRequestInfo('method', $this->calledMethod); if (FALSE !== ($Handler =& $this->getHandler($this->calledClass))) { $args = array(); $M->setRequestInfo('args', $args); if ($Handler instanceof TPageWithCallback) { $this->getArgs($args); $response = $this->handleCallback($Handler, $args); } else { if ($this->getArgs($args)) { $M->setRequestInfo('args', $args); $response = call_user_func_array(array(&$Handler, $this->calledMethod), $args); } else { $response = call_user_func(array(&$Handler, $this->calledMethod)); } } require_once JPSPAN . 'Serializer.php'; $M->setResponseInfo('payload', $response); $M->announceSuccess(); $response = JPSpan_Serializer::serialize($response); if ($sendHeaders) { header('Content-Length: ' . strlen($response)); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . 'GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); } echo $response; return TRUE; } else { trigger_error('Invalid handle for: ' . $this->calledClass, E_USER_ERROR); return FALSE; } } return FALSE; }
/** * Custom PHP exception handler which generates Javascript exceptions * @todo i18n error messages */ function JPSpan_ExceptionHandler($exception) { $name = 'Server_Error'; $file = addSlashes($exception->getFile()); if (!JPSPAN_ERROR_MESSAGES) { $message = 'Server unable to respond'; } else { $message = strip_tags($exception->getMessage()); } $code = 2005; $error = "var e = new Error('{$message}');e.name = '{$name}';e.code = '{$code}';"; if (JPSPAN_ERROR_DEBUG) { $error .= "e.file = '{$file}';e.line = '" . $exception->getLine() . "';"; } $error .= "throw e;"; echo 'new Function("' . addSlashes($error) . '");'; if (!defined('JPSPAN')) { define('JPSPAN', dirname(__FILE__) . '/'); } require_once JPSPAN . 'Monitor.php'; $M =& JPSpan_Monitor::instance(); $M->announceError($name, $code, $message, $file, $exception->getLine()); exit; }