123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php namespace Laravel;
- class Error {
-
- public static function exception($exception, $trace = true)
- {
- static::log($exception);
- ob_get_level() and ob_end_clean();
- $message = $exception->getMessage();
-
- $file = $exception->getFile();
- if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel'.DS.'view.php'))
- {
- $message = 'Error rendering view: ['.View::$last['name'].']'.PHP_EOL.PHP_EOL.$message;
- $file = View::$last['path'];
- }
-
-
-
- if (Config::get('error.detail'))
- {
- $response_body = "<html><h2>Unhandled Exception</h2>
- <h3>Message:</h3>
- <pre>".$message."</pre>
- <h3>Location:</h3>
- <pre>".$file." on line ".$exception->getLine()."</pre>";
- if ($trace)
- {
- $response_body .= "
- <h3>Stack Trace:</h3>
- <pre>".$exception->getTraceAsString()."</pre></html>";
- }
- $response = Response::make($response_body, 500);
- }
-
-
-
- else
- {
- $response = Event::first('500', $exception);
- $response = Response::prepare($response);
- }
- $response->render();
- $response->send();
- $response->foundation->finish();
- exit(1);
- }
-
- public static function native($code, $error, $file, $line)
- {
- if (error_reporting() === 0) return;
-
-
-
- $exception = new \ErrorException($error, $code, 0, $file, $line);
- if (in_array($code, Config::get('error.ignore')))
- {
- return static::log($exception);
- }
- static::exception($exception);
- }
-
- public static function shutdown()
- {
-
-
-
- $error = error_get_last();
- if ( ! is_null($error))
- {
- extract($error, EXTR_SKIP);
- static::exception(new \ErrorException($message, $type, 0, $file, $line), false);
- }
- }
-
- public static function log($exception)
- {
- if (Config::get('error.log'))
- {
- call_user_func(Config::get('error.logger'), $exception);
- }
- }
- }
|