<?php
namespace startmvc\core;
class Exception
{
private function __construct()
{
}
public static function init() {
set_error_handler([__CLASS__, 'error'], E_ALL | E_STRICT);
set_exception_handler([__CLASS__, 'exception']);
}
public static function error($errno, $errstr, $errfile, $errline)
{
$output=['类型:'.$errno,'错误:'.$errstr,'文件:'.$errfile,'行号:'.$errline];
self::errorPage($output);
return false;
}
public static function exception(\Throwable $exception)
{
$output=['异常:'.$exception->getMessage(),'文件:'.$exception->getFile(),'行号:'.$exception->getLine(),'跟踪:'.str_replace("#", "<br>#", $exception->getTraceAsString())];
self::errorPage($output);
exit(1);
}
private static function errorPage($output)
{
if(config('debug')){
include 'tpl/error.php';
}
exit;
}
}