ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
JsonResponseHandler.php
Go to the documentation of this file.
1 <?php
7 namespace Whoops\Handler;
8 
10 
17 {
21  private $returnFrames = false;
22 
26  private $onlyForAjaxRequests = false;
27 
32  public function addTraceToOutput($returnFrames = null)
33  {
34  if (func_num_args() == 0) {
35  return $this->returnFrames;
36  }
37 
38  $this->returnFrames = (bool) $returnFrames;
39  return $this;
40  }
41 
46  public function onlyForAjaxRequests($onlyForAjaxRequests = null)
47  {
48  if (func_num_args() == 0) {
50  }
51 
53  }
54 
60  private function isAjaxRequest()
61  {
62  return (
63  !empty($_SERVER['HTTP_X_REQUESTED_WITH'])
64  && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
65  }
66 
70  public function handle()
71  {
72  if ($this->onlyForAjaxRequests() && !$this->isAjaxRequest()) {
73  return Handler::DONE;
74  }
75 
76  $response = array(
77  'error' => Formatter::formatExceptionAsDataArray(
78  $this->getInspector(),
79  $this->addTraceToOutput()
80  ),
81  );
82 
83  if (\Whoops\Util\Misc::canSendHeaders()) {
84  header('Content-Type: application/json');
85  }
86 
87  echo json_encode($response);
88  return Handler::QUIT;
89  }
90 }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
Whoops - php errors for cool kids.
isAjaxRequest()
Check, if possible, that this execution was triggered by an AJAX request.
const DONE
Return constants that can be returned from Handler::handle to message the handler walker...
Definition: Handler.php:22
Catches an exception and converts it to a JSON response.
Whoops - php errors for cool kids.
static canSendHeaders()
Can we at this point in time send HTTP headers?
Definition: Misc.php:21
Abstract implementation of a Handler.
Definition: Handler.php:16
onlyForAjaxRequests($onlyForAjaxRequests=null)