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); }
public function getHeader() { $header = array(Response::httpStatus($this->getCode())); if (isset($this->header)) { $header = array_merge($header, $this->header); } return $header; }