ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Whoops\Handler\JsonResponseHandler Class Reference

Catches an exception and converts it to a JSON response. More...

+ Inheritance diagram for Whoops\Handler\JsonResponseHandler:
+ Collaboration diagram for Whoops\Handler\JsonResponseHandler:

Public Member Functions

 addTraceToOutput ($returnFrames=null)
 
 onlyForAjaxRequests ($onlyForAjaxRequests=null)
 
 handle ()
 
- Public Member Functions inherited from Whoops\Handler\Handler
 setRun (Run $run)
 
 setInspector (Inspector $inspector)
 
 setException (Exception $exception)
 

Private Member Functions

 isAjaxRequest ()
 Check, if possible, that this execution was triggered by an AJAX request. More...
 

Private Attributes

 $returnFrames = false
 
 $onlyForAjaxRequests = false
 

Additional Inherited Members

- Data Fields inherited from Whoops\Handler\Handler
const DONE = 0x10
 Return constants that can be returned from Handler::handle to message the handler walker. More...
 
const LAST_HANDLER = 0x20
 
const QUIT = 0x30
 
- Protected Member Functions inherited from Whoops\Handler\Handler
 getRun ()
 
 getInspector ()
 
 getException ()
 

Detailed Description

Catches an exception and converts it to a JSON response.

Additionally can also return exception frames for consumption by an API.

Definition at line 16 of file JsonResponseHandler.php.

Member Function Documentation

◆ addTraceToOutput()

Whoops\Handler\JsonResponseHandler::addTraceToOutput (   $returnFrames = null)
Parameters
bool | null$returnFrames
Returns
bool|$this

Definition at line 32 of file JsonResponseHandler.php.

References Whoops\Handler\JsonResponseHandler\$returnFrames.

Referenced by Whoops\Handler\JsonResponseHandler\handle().

33  {
34  if (func_num_args() == 0) {
35  return $this->returnFrames;
36  }
37 
38  $this->returnFrames = (bool) $returnFrames;
39  return $this;
40  }
+ Here is the caller graph for this function:

◆ handle()

Whoops\Handler\JsonResponseHandler::handle ( )
Returns
int

Implements Whoops\Handler\HandlerInterface.

Definition at line 70 of file JsonResponseHandler.php.

References Whoops\Handler\JsonResponseHandler\addTraceToOutput(), Whoops\Util\Misc\canSendHeaders(), Whoops\Handler\Handler\DONE, Whoops\Handler\Handler\getInspector(), Whoops\Handler\JsonResponseHandler\isAjaxRequest(), Whoops\Handler\JsonResponseHandler\onlyForAjaxRequests(), and Whoops\Handler\Handler\QUIT.

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  }
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
Whoops - php errors for cool kids.
static canSendHeaders()
Can we at this point in time send HTTP headers?
Definition: Misc.php:21
onlyForAjaxRequests($onlyForAjaxRequests=null)
+ Here is the call graph for this function:

◆ isAjaxRequest()

Whoops\Handler\JsonResponseHandler::isAjaxRequest ( )
private

Check, if possible, that this execution was triggered by an AJAX request.

Returns
bool

Definition at line 60 of file JsonResponseHandler.php.

References $_SERVER.

Referenced by Whoops\Handler\JsonResponseHandler\handle().

61  {
62  return (
63  !empty($_SERVER['HTTP_X_REQUESTED_WITH'])
64  && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
65  }
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
+ Here is the caller graph for this function:

◆ onlyForAjaxRequests()

Whoops\Handler\JsonResponseHandler::onlyForAjaxRequests (   $onlyForAjaxRequests = null)
Parameters
bool | null$onlyForAjaxRequests
Returns
null|bool

Definition at line 46 of file JsonResponseHandler.php.

References Whoops\Handler\JsonResponseHandler\$onlyForAjaxRequests.

Referenced by Whoops\Handler\JsonResponseHandler\handle().

47  {
48  if (func_num_args() == 0) {
50  }
51 
53  }
onlyForAjaxRequests($onlyForAjaxRequests=null)
+ Here is the caller graph for this function:

Field Documentation

◆ $onlyForAjaxRequests

Whoops\Handler\JsonResponseHandler::$onlyForAjaxRequests = false
private

◆ $returnFrames

Whoops\Handler\JsonResponseHandler::$returnFrames = false
private

The documentation for this class was generated from the following file: