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
|
|
|
* Render an exception into an HTTP response. |
53
|
|
|
* |
54
|
|
|
* @param \Illuminate\Http\Request $request |
55
|
|
|
* @param \Exception $e |
56
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
57
|
|
|
*/ |
58
|
8 |
|
public function render($request, Exception $e) |
59
|
|
|
{ |
60
|
8 |
|
$response = $this->exceptionHandler->render($request, $e); |
61
|
|
|
|
62
|
8 |
|
if ($this->shouldRenderException($response) === true) { |
63
|
7 |
|
return $response; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
$response->setContent( |
67
|
1 |
|
$this->debuggerManager->exceptionHandler($e) |
68
|
|
|
); |
69
|
|
|
|
70
|
1 |
|
return $response; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Render an exception to the console. |
75
|
|
|
* |
76
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
77
|
|
|
* @param \Exception $e |
78
|
|
|
*/ |
79
|
1 |
|
public function renderForConsole($output, Exception $e) |
80
|
|
|
{ |
81
|
1 |
|
$this->exceptionHandler->renderForConsole($output, $e); |
82
|
1 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* shouldRenderException. |
86
|
|
|
* |
87
|
|
|
* @param \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response $response |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
8 |
|
protected function shouldRenderException($response) |
91
|
|
|
{ |
92
|
8 |
|
if ($response instanceof RedirectResponse) { |
|
|
|
|
93
|
2 |
|
return true; |
94
|
|
|
} |
95
|
|
|
|
96
|
6 |
|
if ($response instanceof JsonResponse) { |
|
|
|
|
97
|
2 |
|
return true; |
98
|
|
|
} |
99
|
|
|
|
100
|
4 |
|
if ($response->getContent() instanceof View) { |
|
|
|
|
101
|
2 |
|
return true; |
102
|
|
|
} |
103
|
|
|
|
104
|
2 |
|
if ($response instanceof Response && $response->getOriginalContent() instanceof View) { |
|
|
|
|
105
|
1 |
|
return true; |
106
|
|
|
} |
107
|
|
|
|
108
|
1 |
|
return false; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.