/** * Registers it self as error and exception handler. * * @static * @return void */ public static function register() { switch (APPLICATION_ENV) { case Application::ENV_PRODUCTION: case Application::ENV_STAGING: ini_set('display_errors', 0); ini_set('display_startup_errors', 0); error_reporting(0); break; case Application::ENV_TEST: case Application::ENV_DEVELOPMENT: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(~0); break; default: ini_set('display_errors', 0); ini_set('display_startup_errors', 0); error_reporting(0); } set_error_handler(function ($errno, $errstr, $errfile, $errline) { if (!($errno & error_reporting())) { return; } $options = array('type' => $errno, 'message' => $errstr, 'file' => $errfile, 'line' => $errline, 'isError' => true); Handler::handle(new Error($options)); }); set_exception_handler(function (\Exception $e) { $options = array('type' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'isException' => true, 'exception' => $e); Handler::handle(new Error($options)); }); register_shutdown_function(function () { if (!is_null($options = error_get_last())) { Handler::handle(new Error($options)); } }); }