1: <?php namespace Laravel;
2:
3: class Error {
4:
5: 6: 7: 8: 9: 10: 11:
12: public static function exception($exception, $trace = true)
13: {
14: static::log($exception);
15:
16: ob_get_level() and ob_end_clean();
17:
18: $message = $exception->getMessage();
19:
20:
21: $file = $exception->getFile();
22:
23: if (str_contains($exception->getFile(), 'eval()') and str_contains($exception->getFile(), 'laravel'.DS.'view.php'))
24: {
25: $message = 'Error rendering view: ['.View::$last['name'].']'.PHP_EOL.PHP_EOL.$message;
26:
27: $file = View::$last['path'];
28: }
29:
30:
31:
32:
33:
34: if (Config::get('error.detail'))
35: {
36: $response_body = "<html><h2>Unhandled Exception</h2>
37: <h3>Message:</h3>
38: <pre>".$message."</pre>
39: <h3>Location:</h3>
40: <pre>".$file." on line ".$exception->getLine()."</pre>";
41:
42: if ($trace)
43: {
44: $response_body .= "
45: <h3>Stack Trace:</h3>
46: <pre>".$exception->getTraceAsString()."</pre></html>";
47: }
48:
49: $response = Response::make($response_body, 500);
50: }
51:
52:
53:
54:
55: else
56: {
57: $response = Event::first('500', array($exception));
58:
59: $response = Response::prepare($response);
60: }
61:
62: $response->render();
63: $response->send();
64: $response->foundation->finish();
65:
66: exit(1);
67: }
68:
69: 70: 71: 72: 73: 74: 75: 76: 77:
78: public static function native($code, $error, $file, $line)
79: {
80: if (error_reporting() === 0) return;
81:
82:
83:
84:
85: $exception = new \ErrorException($error, $code, 0, $file, $line);
86:
87: if (in_array($code, Config::get('error.ignore')))
88: {
89: return static::log($exception);
90: }
91:
92: static::exception($exception);
93: }
94:
95: 96: 97: 98: 99:
100: public static function shutdown()
101: {
102:
103:
104:
105: $error = error_get_last();
106:
107: if ( ! is_null($error))
108: {
109: extract($error, EXTR_SKIP);
110:
111: static::exception(new \ErrorException($message, $type, 0, $file, $line), false);
112: }
113: }
114:
115: 116: 117: 118: 119: 120:
121: public static function log($exception)
122: {
123: if (Config::get('error.log'))
124: {
125: call_user_func(Config::get('error.logger'), $exception);
126: }
127: }
128:
129: }
130: