ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AbstractError.php
Go to the documentation of this file.
1<?php
9namespace Slim\Handlers;
10
14abstract 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}
An exception for terminatinating execution or to throw for unit testing.
Abstract Slim application error handler.
logError($message)
Wraps the error_log function so that this can be easily tested.
writeToErrorLog($throwable)
Write to the error log if displayErrorDetails is false.
__construct($displayErrorDetails=false)
Constructor.
renderThrowableAsText($throwable)
Render error as Text.
Abstract Slim application handler.
PHP_EOL
Definition: complexTest.php:7
$code
Definition: example_050.php:99
catch(Exception $e) $message
Slim Framework (https://slimframework.com)
$text
Definition: errorreport.php:18