ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
JsonResponseHandler.php
Go to the documentation of this file.
1<?php
7namespace Whoops\Handler;
8
10
17{
21 private $returnFrames = false;
22
26 private $jsonApi = false;
27
33 public function setJsonApi($jsonApi = false)
34 {
35 $this->jsonApi = (bool) $jsonApi;
36 return $this;
37 }
38
43 public function addTraceToOutput($returnFrames = null)
44 {
45 if (func_num_args() == 0) {
47 }
48
49 $this->returnFrames = (bool) $returnFrames;
50 return $this;
51 }
52
56 public function handle()
57 {
58 if ($this->jsonApi === true) {
59 $response = [
60 'errors' => [
61 Formatter::formatExceptionAsDataArray(
62 $this->getInspector(),
63 $this->addTraceToOutput()
64 ),
65 ]
66 ];
67 } else {
68 $response = [
69 'error' => Formatter::formatExceptionAsDataArray(
70 $this->getInspector(),
71 $this->addTraceToOutput()
72 ),
73 ];
74 }
75
76 echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);
77
78 return Handler::QUIT;
79 }
80
84 public function contentType()
85 {
86 return 'application/json';
87 }
88}
An exception for terminatinating execution or to throw for unit testing.
Abstract implementation of a Handler.
Definition: Handler.php:16
const QUIT
The Handler has handled the Throwable in some way, and wishes to quit/stop execution.
Definition: Handler.php:31
Catches an exception and converts it to a JSON response.
setJsonApi($jsonApi=false)
Returns errors[[]] instead of error[] to be in compliance with the json:api spec.
Whoops - php errors for cool kids.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
Definition: bootstrap.php:27
$response