From 60c07d58c25a29732f178b525771f4f0e4e6621e Mon Sep 17 00:00:00 2001 From: printempw Date: Sat, 23 Jul 2016 22:52:31 +0800 Subject: [PATCH] make error handler registration more elegant --- app/Exceptions/ExceptionHandler.php | 10 ++++++++++ index.php | 8 ++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Exceptions/ExceptionHandler.php b/app/Exceptions/ExceptionHandler.php index 060ad94c..48736675 100644 --- a/app/Exceptions/ExceptionHandler.php +++ b/app/Exceptions/ExceptionHandler.php @@ -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) { diff --git a/index.php b/index.php index d508996a..18091a94 100755 --- a/index.php +++ b/index.php @@ -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); }