|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Recca0120\LaravelTracy\Exceptions; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler; |
|
7
|
|
|
use Illuminate\Contracts\View\View; |
|
8
|
|
|
use Illuminate\Http\Response; |
|
9
|
|
|
use Recca0120\LaravelTracy\DebuggerManager; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
12
|
|
|
use Throwable; |
|
13
|
|
|
|
|
14
|
|
|
class Handler implements ExceptionHandler |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* app exception handler. |
|
18
|
|
|
* |
|
19
|
|
|
* @var \Illuminate\Contracts\Debug\ExceptionHandler |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $exceptionHandler; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* $debuggerManager. |
|
25
|
|
|
* |
|
26
|
|
|
* @var \Recca0120\LaravelTracy\DebuggerManager |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $debuggerManager; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* __construct. |
|
32
|
|
|
* |
|
33
|
|
|
* @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptionHandler |
|
34
|
|
|
* @param \Recca0120\LaravelTracy\DebuggerManager $debuggerManager |
|
35
|
|
|
*/ |
|
36
|
12 |
|
public function __construct(ExceptionHandler $exceptionHandler, DebuggerManager $debuggerManager) |
|
37
|
|
|
{ |
|
38
|
12 |
|
$this->exceptionHandler = $exceptionHandler; |
|
39
|
12 |
|
$this->debuggerManager = $debuggerManager; |
|
40
|
12 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Report or log an exception. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Throwable $e |
|
46
|
|
|
* @return void |
|
47
|
|
|
* |
|
48
|
|
|
* @throws \Exception |
|
49
|
|
|
*/ |
|
50
|
1 |
|
public function report(Throwable $e) |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->exceptionHandler->report($e); |
|
53
|
1 |
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Determine if the exception should be reported. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \Throwable $e |
|
59
|
|
|
* @return bool |
|
60
|
|
|
*/ |
|
61
|
1 |
|
public function shouldReport(Throwable $e) |
|
62
|
|
|
{ |
|
63
|
1 |
|
return $this->exceptionHandler->shouldReport($e); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Render an exception into an HTTP response. |
|
68
|
|
|
* |
|
69
|
|
|
* @param \Illuminate\Http\Request $request |
|
70
|
|
|
* @param \Throwable $e |
|
71
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
|
72
|
|
|
* |
|
73
|
|
|
* @throws \Throwable |
|
74
|
|
|
*/ |
|
75
|
8 |
|
public function render($request, Throwable $e) |
|
76
|
|
|
{ |
|
77
|
8 |
|
$response = $this->exceptionHandler->render($request, $e); |
|
78
|
|
|
|
|
79
|
8 |
|
if ($this->shouldRenderException($response) === true) { |
|
80
|
1 |
|
$_SERVER = $request->server(); |
|
81
|
1 |
|
$response->setContent( |
|
82
|
1 |
|
$this->debuggerManager->exceptionHandler($e) |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
8 |
|
return $response; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Render an exception to the console. |
|
91
|
|
|
* |
|
92
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
93
|
|
|
* @param \Throwable $e |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function renderForConsole($output, Throwable $e) |
|
97
|
|
|
{ |
|
98
|
1 |
|
$this->exceptionHandler->renderForConsole($output, $e); |
|
99
|
1 |
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* shouldRenderException. |
|
103
|
|
|
* |
|
104
|
|
|
* @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
8 |
|
protected function shouldRenderException($response) |
|
108
|
|
|
{ |
|
109
|
|
|
if ( |
|
110
|
8 |
|
$response instanceof RedirectResponse || |
|
111
|
6 |
|
$response instanceof JsonResponse || |
|
112
|
4 |
|
$response->getContent() instanceof View || |
|
113
|
8 |
|
($response instanceof Response && $response->getOriginalContent() instanceof View) |
|
114
|
|
|
) { |
|
115
|
7 |
|
return false; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
1 |
|
return true; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|