1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Recca0120\LaravelTracy\Exceptions; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Illuminate\Http\Response; |
7
|
|
|
use Illuminate\Contracts\View\View; |
8
|
|
|
use Recca0120\LaravelTracy\DebuggerManager; |
9
|
|
|
use Illuminate\Contracts\Debug\ExceptionHandler; |
10
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
11
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
12
|
|
|
|
13
|
|
|
class Handler implements ExceptionHandler |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* app exception handler. |
17
|
|
|
* |
18
|
|
|
* @var \Illuminate\Contracts\Debug\ExceptionHandler |
19
|
|
|
*/ |
20
|
|
|
protected $exceptionHandler; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* $debuggerManager. |
24
|
|
|
* |
25
|
|
|
* @var \Recca0120\LaravelTracy\DebuggerManager |
26
|
|
|
*/ |
27
|
|
|
protected $debuggerManager; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* __construct. |
31
|
|
|
* |
32
|
|
|
* @param \Illuminate\Contracts\Debug\ExceptionHandler $exceptionHandler |
33
|
|
|
* @param \Recca0120\LaravelTracy\DebuggerManager $debuggerManager |
34
|
|
|
*/ |
35
|
11 |
|
public function __construct(ExceptionHandler $exceptionHandler, DebuggerManager $debuggerManager) |
36
|
|
|
{ |
37
|
11 |
|
$this->exceptionHandler = $exceptionHandler; |
38
|
11 |
|
$this->debuggerManager = $debuggerManager; |
39
|
11 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Report or log an exception. |
43
|
|
|
* |
44
|
|
|
* @param \Exception $e |
45
|
|
|
*/ |
46
|
1 |
|
public function report(Exception $e) |
47
|
|
|
{ |
48
|
1 |
|
$this->exceptionHandler->report($e); |
49
|
1 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Determine if the exception should be reported. |
53
|
|
|
* |
54
|
|
|
* @param \Exception $e |
55
|
|
|
* @return bool |
56
|
|
|
*/ |
57
|
|
|
public function shouldReport(Exception $e) |
58
|
8 |
|
{ |
59
|
|
|
return $this->exceptionHandler->shouldReport($e); |
60
|
8 |
|
} |
61
|
|
|
|
62
|
8 |
|
/** |
63
|
1 |
|
* Render an exception into an HTTP response. |
64
|
1 |
|
* |
65
|
1 |
|
* @param \Illuminate\Http\Request $request |
66
|
|
|
* @param \Exception $e |
67
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
68
|
|
|
*/ |
69
|
8 |
|
public function render($request, Exception $e) |
70
|
|
|
{ |
71
|
|
|
$response = $this->exceptionHandler->render($request, $e); |
72
|
|
|
|
73
|
|
|
if ($this->shouldRenderException($response) === true) { |
74
|
|
|
$_SERVER = $request->server(); |
75
|
|
|
$response->setContent( |
76
|
|
|
$this->debuggerManager->exceptionHandler($e) |
77
|
|
|
); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
1 |
|
return $response; |
81
|
1 |
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Render an exception to the console. |
85
|
|
|
* |
86
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
87
|
|
|
* @param \Exception $e |
88
|
|
|
*/ |
89
|
8 |
|
public function renderForConsole($output, Exception $e) |
90
|
|
|
{ |
91
|
8 |
|
$this->exceptionHandler->renderForConsole($output, $e); |
92
|
2 |
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
6 |
|
* shouldRenderException. |
96
|
2 |
|
* |
97
|
|
|
* @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response |
98
|
|
|
* @return bool |
99
|
4 |
|
*/ |
100
|
2 |
|
protected function shouldRenderException($response) |
101
|
|
|
{ |
102
|
|
|
if ($response instanceof RedirectResponse) { |
|
|
|
|
103
|
2 |
|
return false; |
104
|
1 |
|
} |
105
|
|
|
|
106
|
|
|
if ($response instanceof JsonResponse) { |
|
|
|
|
107
|
1 |
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($response->getContent() instanceof View) { |
|
|
|
|
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($response instanceof Response && $response->getOriginalContent() instanceof View) { |
|
|
|
|
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
return true; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.