ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Slim\Handlers\AbstractError Class Reference

Abstract Slim application error handler. More...

+ Inheritance diagram for Slim\Handlers\AbstractError:
+ Collaboration diagram for Slim\Handlers\AbstractError:

Public Member Functions

 __construct ($displayErrorDetails=false)
 Constructor. More...
 

Protected Member Functions

 writeToErrorLog ($throwable)
 Write to the error log if displayErrorDetails is false. More...
 
 renderThrowableAsText ($throwable)
 Render error as Text. More...
 
 logError ($message)
 Wraps the error_log function so that this can be easily tested. More...
 
- Protected Member Functions inherited from Slim\Handlers\AbstractHandler
 determineContentType (ServerRequestInterface $request)
 Determine which content type we know about is wanted using Accept header. More...
 

Protected Attributes

 $displayErrorDetails
 
- Protected Attributes inherited from Slim\Handlers\AbstractHandler
 $knownContentTypes
 

Detailed Description

Abstract Slim application error handler.

Definition at line 14 of file AbstractError.php.

Constructor & Destructor Documentation

◆ __construct()

Slim\Handlers\AbstractError::__construct (   $displayErrorDetails = false)

Constructor.

Parameters
bool$displayErrorDetailsSet to true to display full details

Definition at line 26 of file AbstractError.php.

References Slim\Handlers\AbstractError\$displayErrorDetails.

27  {
28  $this->displayErrorDetails = (bool) $displayErrorDetails;
29  }

Member Function Documentation

◆ logError()

Slim\Handlers\AbstractError::logError (   $message)
protected

Wraps the error_log function so that this can be easily tested.

Parameters
$message

Definition at line 95 of file AbstractError.php.

References $message, and Monolog\Handler\error_log().

Referenced by Slim\Handlers\AbstractError\writeToErrorLog().

96  {
98  }
catch(Exception $e) $message
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderThrowableAsText()

Slim\Handlers\AbstractError::renderThrowableAsText (   $throwable)
protected

Render error as Text.

Parameters
\Exception | \Throwable$throwable
Returns
string

Definition at line 63 of file AbstractError.php.

References $code, $file, $message, $text, and PHP_EOL.

Referenced by Slim\Handlers\AbstractError\writeToErrorLog().

64  {
65  $text = sprintf('Type: %s' . PHP_EOL, get_class($throwable));
66 
67  if ($code = $throwable->getCode()) {
68  $text .= sprintf('Code: %s' . PHP_EOL, $code);
69  }
70 
71  if ($message = $throwable->getMessage()) {
72  $text .= sprintf('Message: %s' . PHP_EOL, htmlentities($message));
73  }
74 
75  if ($file = $throwable->getFile()) {
76  $text .= sprintf('File: %s' . PHP_EOL, $file);
77  }
78 
79  if ($line = $throwable->getLine()) {
80  $text .= sprintf('Line: %s' . PHP_EOL, $line);
81  }
82 
83  if ($trace = $throwable->getTraceAsString()) {
84  $text .= sprintf('Trace: %s', $trace);
85  }
86 
87  return $text;
88  }
$code
Definition: example_050.php:99
catch(Exception $e) $message
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
$text
Definition: errorreport.php:18
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the caller graph for this function:

◆ writeToErrorLog()

Slim\Handlers\AbstractError::writeToErrorLog (   $throwable)
protected

Write to the error log if displayErrorDetails is false.

Parameters
\Exception | \Throwable$throwable
Returns
void

Definition at line 38 of file AbstractError.php.

References $message, Slim\Handlers\AbstractError\logError(), PHP_EOL, and Slim\Handlers\AbstractError\renderThrowableAsText().

Referenced by Slim\Handlers\Error\__invoke(), and Slim\Handlers\PhpError\__invoke().

39  {
40  if ($this->displayErrorDetails) {
41  return;
42  }
43 
44  $message = 'Slim Application Error:' . PHP_EOL;
45  $message .= $this->renderThrowableAsText($throwable);
46  while ($throwable = $throwable->getPrevious()) {
47  $message .= PHP_EOL . 'Previous error:' . PHP_EOL;
48  $message .= $this->renderThrowableAsText($throwable);
49  }
50 
51  $message .= PHP_EOL . 'View in rendered output by enabling the "displayErrorDetails" setting.' . PHP_EOL;
52 
53  $this->logError($message);
54  }
catch(Exception $e) $message
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
logError($message)
Wraps the error_log function so that this can be easily tested.
renderThrowableAsText($throwable)
Render error as Text.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $displayErrorDetails

Slim\Handlers\AbstractError::$displayErrorDetails
protected

Definition at line 19 of file AbstractError.php.

Referenced by Slim\Handlers\AbstractError\__construct().


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