ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
PlainTextFallbackResponder.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PDOException;
24use Throwable;
25use DateTimeZone;
26use DateTimeImmutable;
28
47{
57 public function respond(
58 Throwable $e,
60 ?string $status_message = null
61 ): never {
62 if (\defined('DEVMODE') && DEVMODE) {
63 throw $e;
64 }
65
66 if (!headers_sent()) {
67 http_response_code($status_code);
68 header('Content-Type: text/plain; charset=UTF-8');
69 }
70
71 $session_prefix = session_id() !== '' ? session_id() : 'no-session';
72 $incident_id = $session_prefix . '_' . (new \Random\Randomizer())->getInt(1, 9999);
73 $timestamp = (new DateTimeImmutable())
74 ->setTimezone(new DateTimeZone('UTC'))
75 ->format('Y-m-d\TH:i:s\Z');
76
77 echo ($status_message ?? 'Internal Server Error') . "\n";
78 echo "Incident: $incident_id\n";
79 echo "Timestamp: $timestamp\n";
80
81 if ($e instanceof PDOException) {
82 echo "Message: A database error occurred. Please contact the system administrator with the incident id.\n";
83 } else {
84 echo "Message: {$e->getMessage()}\n";
85 }
86
87 error_log(
88 \sprintf(
89 "[%s] INCIDENT %s — Uncaught %s: %s in %s:%d\nStack trace:\n%s\n",
91 $incident_id,
92 \get_class($e),
93 $e->getMessage(),
94 $e->getFile(),
95 $e->getLine(),
96 $e->getTraceAsString()
97 ));
98
99 exit(1);
100 }
101}
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
Responder that sends a minimal plain-text error response without relying on any ILIAS service (no DIC...
respond(Throwable $e, int $status_code=StatusCode::HTTP_INTERNAL_SERVER_ERROR, ?string $status_message=null)
Send a minimal plain-text error response and terminate the process.
exit
const HTTP_INTERNAL_SERVER_ERROR
Definition: StatusCode.php:77
if(!file_exists('../ilias.ini.php'))