make error handler registration more elegant

This commit is contained in:
printempw 2016-07-23 22:52:31 +08:00
parent c5ee4b9da2
commit 60c07d58c2
2 changed files with 12 additions and 6 deletions

View File

@ -4,6 +4,16 @@ namespace App\Exceptions;
class ExceptionHandler
{
public static function register()
{
if ($_SERVER['REQUEST_METHOD'] == "GET") {
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
self::handler(
new \ErrorException($errstr, $errno, $errno, $errfile, $errline)
);
});
}
}
public static function handler($e)
{

View File

@ -24,11 +24,8 @@ if ($_ENV['APP_DEBUG'] !== "false") {
$whoops->pushHandler($handler);
$whoops->register();
} else {
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
Exceptions\ExceptionHandler::handler(
new \ErrorException($errstr, $errno, $errno, $errfile, $errline)
);
});
// register custom error handler
Exceptions\ExceptionHandler::register();
}
// set aliases for App\Services
@ -42,7 +39,6 @@ foreach ($services as $facade => $class) {
*/
if (\Http::getUri() != "/" && substr(\Http::getUri(), -1) == "/")
{
die(\Http::getUri());
$url = substr(\Http::getCurrentUrl(), 0, -1);
\Http::redirect($url);
}