ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractError.php
Go to the documentation of this file.
1 <?php
9 namespace Slim\Handlers;
10 
14 abstract class AbstractError extends AbstractHandler
15 {
20 
26  public function __construct($displayErrorDetails = false)
27  {
28  $this->displayErrorDetails = (bool) $displayErrorDetails;
29  }
30 
38  protected function writeToErrorLog($throwable)
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  }
55 
63  protected function renderThrowableAsText($throwable)
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  }
89 
95  protected function logError($message)
96  {
98  }
99 }
$code
Definition: example_050.php:99
PHP_EOL
Definition: complexTest.php:5
writeToErrorLog($throwable)
Write to the error log if displayErrorDetails is false.
catch(Exception $e) $message
$text
Definition: errorreport.php:18
Abstract Slim application error handler.
__construct($displayErrorDetails=false)
Constructor.
logError($message)
Wraps the error_log function so that this can be easily tested.
Slim Framework (https://slimframework.com)
renderThrowableAsText($throwable)
Render error as Text.
Abstract Slim application handler.