These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Whoops - php errors for cool kids |
||
4 | * @author Filipe Dobreira <http://github.com/filp> |
||
5 | */ |
||
6 | |||
7 | namespace ByJG\RestServer\Whoops; |
||
8 | |||
9 | use Whoops\Exception\Formatter; |
||
10 | use Whoops\Handler\Handler; |
||
11 | use Whoops\Handler\JsonResponseHandler as OriginalJsonHandler; |
||
12 | use Whoops\Util\Misc; |
||
13 | |||
14 | /** |
||
15 | * Catches an exception and converts it to a JSON |
||
16 | * response. Additionally can also return exception |
||
17 | * frames for consumption by an API. |
||
18 | */ |
||
19 | class JsonResponseHandler extends OriginalJsonHandler |
||
20 | { |
||
21 | |||
22 | use \ByJG\RestServer\Whoops\WhoopsDebugTrait; |
||
23 | use \ByJG\RestServer\Whoops\WhoopsHeaderTrait; |
||
24 | |||
25 | /** |
||
26 | * @return int |
||
27 | */ |
||
28 | public function handle() |
||
29 | { |
||
30 | if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) { |
||
0 ignored issues
–
show
|
|||
31 | return Handler::DONE; |
||
32 | } |
||
33 | |||
34 | $response = array( |
||
35 | 'error' => Formatter::formatExceptionAsDataArray( |
||
36 | $this->getInspector(), |
||
37 | $this->addTraceToOutput() |
||
38 | ), |
||
39 | ); |
||
40 | |||
41 | $debug = $this->getDataTable(); |
||
42 | if (count($debug) > 0) { |
||
43 | $response["debug"] = $debug; |
||
44 | } |
||
45 | |||
46 | if (Misc::canSendHeaders()) { |
||
47 | header('Content-Type: application/json'); |
||
48 | } |
||
49 | |||
50 | $this->setProperHeader($this->getException()); |
||
51 | echo json_encode($response); |
||
52 | return Handler::QUIT; |
||
53 | } |
||
54 | } |
||
55 |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.