Exemplo n.º 1
0
 /**
  * Exception handler
  *
  * This will log the exception and output the exception properties
  * formatted as html or a 500 response depending on your application config
  *
  * @param object The uncaught exception
  */
 public static function exception($e)
 {
     static::log($e);
     if (Config::error('report')) {
         // clear output buffer
         while (ob_get_level() > 1) {
             ob_end_clean();
         }
         if (Request::cli()) {
             Cli::write(PHP_EOL . 'Uncaught Exception', 'light_red');
             Cli::write($e->getMessage() . PHP_EOL);
             Cli::write('Origin', 'light_red');
             Cli::write(substr($e->getFile(), strlen(PATH)) . ' on line ' . $e->getLine() . PHP_EOL);
             Cli::write('Trace', 'light_red');
             Cli::write($e->getTraceAsString() . PHP_EOL);
         } else {
             $html = file_get_contents(PATH . '../assets/error_document.tpl.html');
             $lines = explode("\n", htmlentities(file_get_contents($e->getFile())));
             $line = $e->getLine();
             $file = $e->getFile();
             $start_line = $line - 5 <= 0 ? 0 : $line - 5;
             $file_contents = array_slice($lines, $start_line, 1);
             $array = ['debug.message' => $e->getMessage(), 'debug.location' => "<strong>{$file}</strong> on line <strong>{$line}</strong>", 'debug.backtrace' => $e->getTraceAsString(), 'copyright.year' => date('Y')];
             foreach ($array as $find => $replace) {
                 $html = str_replace('{{' . $find . '}}', $replace, $html);
             }
             echo $html;
         }
     } else {
         // issue a 500 response
         Response::error(500, array('exception' => $e))->send();
     }
     exit(1);
 }
Exemplo n.º 2
0
    /**
     * Exception handler
     *
     * This will log the exception and output the exception properties
     * formatted as html or a 500 response depending on your application config
     *
     * @param object The uncaught exception
     */
    public static function exception($e)
    {
        static::log($e);
        if (Config::error('report')) {
            // clear output buffer
            while (ob_get_level() > 1) {
                ob_end_clean();
            }
            if (Request::cli()) {
                Cli::write(PHP_EOL . 'Uncaught Exception', 'light_red');
                Cli::write($e->getMessage() . PHP_EOL);
                Cli::write('Origin', 'light_red');
                Cli::write(substr($e->getFile(), strlen(PATH)) . ' on line ' . $e->getLine() . PHP_EOL);
                Cli::write('Trace', 'light_red');
                Cli::write($e->getTraceAsString() . PHP_EOL);
            } else {
                echo '<html>
					<head>
						<title>Uncaught Exception</title>
						<style>
							body{font-family:"Open Sans",arial,sans-serif;background:#FFF;color:#333;margin:2em}
							code{background:#D1E751;border-radius:4px;padding:2px 6px}
						</style>
					</head>
					<body>
						<h1>Uncaught Exception</h1>
						<p><code>' . $e->getMessage() . '</code></p>
						<h3>Origin</h3>
						<p><code>' . substr($e->getFile(), strlen(PATH)) . ' on line ' . $e->getLine() . '</code></p>
						<h3>Trace</h3>
						<pre>' . $e->getTraceAsString() . '</pre>
					</body>
					</html>';
            }
        } else {
            // issue a 500 response
            Response::error(500, array('exception' => $e))->send();
        }
        exit(1);
    }
Exemplo n.º 3
0
 /**
  * Get the error report response for the exception.
  *
  * @param  bool      $detailed
  * @return Resposne
  */
 private function get_response($detailed)
 {
     return $detailed ? $this->detailed_response() : Response::error('500');
 }