/** * @param \Throwable $exception * * @return bool */ public static function exceptionHandler(\Throwable $exception) { // This error code is not included in error_reporting if (!error_reporting() || $exception->getLine() == 0) { return; } if ('cli' === PHP_SAPI || isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'curl') !== false) { $formatterClass = '\\Cawa\\Error\\Formatter\\CliFormatter'; } else { $formatterClass = '\\Cawa\\Error\\Formatter\\HtmlFormatter'; } if (AbstractApp::isInit() && AbstractApp::instance() instanceof HttpApp) { self::log($exception); self::response()->setStatus(500); if (AbstractApp::env() != AbstractApp::PROD || Ip::isAdmin()) { $formatter = new $formatterClass(); self::render($formatter, $exception); } else { self::clearAllBuffer(); echo self::router()->returnError(500); } AbstractApp::instance()->end(); } else { if (!headers_sent()) { header('HTTP/1.1 500 Internal Server Error'); } if (AbstractApp::env() != AbstractApp::PROD) { $formatter = new $formatterClass(); self::render($formatter, $exception); } else { self::clearAllBuffer(); echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . "\n" . '<html><head>' . "\n" . '<title>' . self::response()->getStatusString(500) . '</title>' . "\n" . '</head><body>' . "\n" . '<h1>' . self::response()->getStatusString(500) . '</h1>' . "\n" . '</body></html>'; } } }