示例#1
0
文件: core.php 项目: yeaha/lysine
function __on_exception($exception, $terminate = true)
{
    $code = $exception instanceof HTTP\Error ? $exception->getCode() : 500;
    if (PHP_SAPI == 'cli') {
        if (!$terminate) {
            return array($code, array());
        }
        echo $exception;
        die(1);
    }
    $header = $exception instanceof HTTP\Error ? $exception->getHeader() : array(Response::httpStatus(500));
    if (DEBUG) {
        $message = strip_tags($exception->getMessage());
        if (strpos($message, "\n") !== false) {
            $lines = explode("\n", $message);
            $message = $lines[0];
        }
        $header[] = 'X-Exception-Message: ' . $message;
        $header[] = 'X-Exception-Code: ' . $exception->getCode();
        foreach (explode("\n", $exception->getTraceAsString()) as $index => $line) {
            $header[] = sprintf('X-Exception-Trace-%d: %s', $index, $line);
        }
    }
    if ($terminate && !headers_sent()) {
        foreach ($header as $h) {
            header($h);
        }
    }
    return array($code, $header);
}
示例#2
0
文件: http.php 项目: yeaha/lysine
 public function getHeader()
 {
     $header = array(Response::httpStatus($this->getCode()));
     if (isset($this->header)) {
         $header = array_merge($header, $this->header);
     }
     return $header;
 }