/** * Exception Handler Callback * Rethrows uncatched Exceptions in our presentation style. * * @see http://php.net/manual/de/function.set-exception-handler.php * * @param $exception PHP Exception Objects are valid (Type Hint). */ public function handle(\Exception $exception) { if ($exception->getCode() > 0) { self::fetchExceptionTemplates($exception->getCode()); } echo YellowScreenOfDeath::renderException($exception->getMessage(), $exception->getTraceAsString(), $exception->getCode(), $exception->getFile(), $exception->getLine(), $exception->getTrace()); // we use our own exception handler here, so PHP returns exit code 0. // the execution will stop anyway, but let's return the correct code. \Koch\Tools\ApplicationQuit::quit(255); }
public function render($exception) { YellowScreenOfDeath::renderException($this->exception->getMessage(), $this->exception->getTraceAsString(), $this->exception->getCode(), $this->exception->getFile(), $this->exception->getLine(), $this->exception->getTrace()); }
/** * Koch Framework - Error callback. * * This is basically a switch statement, defining the actions taken, * in case of serveral PHP error states. * * @link http://www.usegroup.de/software/phptutorial/debugging.html * @link http://www.php.net/manual/de/function.set-error-handler.php * @link http://www.php.net/manual/de/errorfunc.constants.php * * @param int $errnum contains the error as integer. * @param string $errstr contains the error string. * @param string $errfile contains the filename with occuring error. * @param string $errline contains the line of error. * @param string $errcontext (optional) array with variables from error context. */ public static function handleError($errnum, $errstr, $errfile, $errline, $errcontext = null) { // return, if the error is suppressed, due to (@)silencing-operator if (error_reporting() === 0) { return; } /* * Assemble the error informations */ /* * Definition of PHP error types, with names for all the php error codes. * @link http://php.net/manual/de/errorfunc.constants.php */ $errorTypes = [1 => 'E_ERROR', 2 => 'E_WARNING', 4 => 'E_PARSE', 8 => 'E_NOTICE', 16 => 'E_CORE_ERROR', 32 => 'E_CORE_WARNING', 64 => 'E_COMPILE_ERROR', 128 => 'E_COMPILE_WARNING', 256 => 'E_USER_ERROR', 512 => 'E_USER_WARNING', 1024 => 'E_USER_NOTICE', 2048 => 'E_STRICT', 4096 => 'E_RECOVERABLE_ERROR', 8191 => 'E_ALL 8191', 8192 => 'E_DEPRECATED', 16384 => 'E_USER_DEPRECATED', 30719 => 'E_ALL 30719 PHP5.3.x', 32767 => 'E_ALL 32767 PHP6']; // get the errorname from the array via $errornumber $errorname = isset($errorTypes[$errnum]) ? $errorTypes[$errnum] : ''; // Handling the ErrorType via Switch switch ($errorname) { // This one is handled by register_shutdown_function + catchFatalErrorsShutdownHandler case 'E_ERROR': $errorname .= ' [PHP Fatal Error]'; break; // What are the errortypes that can be handled by a user-defined errorhandler? // What are the errortypes that can be handled by a user-defined errorhandler? case 'E_WARNING': $errorname .= ' [PHP Warning]'; break; case 'E_NOTICE': $errorname .= ' [PHP Notice]'; break; case 'E_USER_ERROR': $errorname .= ' [Koch Framework Internal Error]'; break; case 'E_USER_WARNING': $errorname .= ' [Koch Framework Internal Error]'; break; case 'E_USER_NOTICE': $errorname .= ' [Koch Framework Internal Error]'; break; case 'E_ALL': case 'E_STRICT': $errorname .= ' [PHP Strict]'; break; case 'E_RECOVERABLE_ERROR': $errorname .= ' [php not-unstable]'; break; // when it's not in there, its an unknown errorcode // when it's not in there, its an unknown errorcode default: $errorname .= ' Unknown Errorcode [' . $errnum . ']: '; } // make the errorstring more useful by linking it to the php manual $pattern = "/<a href='(.*)'>(.*)<\\/a>/"; $replacement = '<a href="http://php.net/$1" target="_blank">?</a>'; $errstr = preg_replace($pattern, $replacement, $errstr); // if DEBUG is set, display the error if (defined('DEBUG') and DEBUG === 1) { /* * SMARTY ERRORS are thrown by trigger_error() - so they bubble up as E_USER_ERROR. * * In order to handle smarty errors with an seperated error display, * we need to detect, if an E_USER_ERROR is either incoming from * SMARTY or from a template_c file (extension tpl.php). */ if (true === (bool) mb_strpos(mb_strtolower($errfile), 'smarty') or true === (bool) mb_strpos(mb_strtolower($errfile), 'tpl.php')) { // render the smarty template error echo SmartyTemplateError::render($errnum, $errorname, $errstr, $errfile, $errline, $errcontext); } else { // render normal error display, with all pieces of information, except backtraces echo YellowScreenOfDeath::renderError($errnum, $errorname, $errstr, $errfile, $errline, $errcontext); } } // Skip PHP internal error handler return true; }