forked from Nihonnosanzoku/GenshinStarfiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror-handler.php
More file actions
72 lines (64 loc) · 2.61 KB
/
Copy patherror-handler.php
File metadata and controls
72 lines (64 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* GenshinStarfield - Hata ve Exception Handler
* Tüm hata ve exception'ları merkezi olarak yönetir
*/
// Error Handler
set_error_handler(function($errno, $errstr, $errfile, $errline) {
$error_types = [
E_ERROR => 'FATAL ERROR',
E_WARNING => 'WARNING',
E_PARSE => 'PARSE ERROR',
E_NOTICE => 'NOTICE',
E_CORE_ERROR => 'CORE ERROR',
E_CORE_WARNING => 'CORE WARNING',
E_COMPILE_ERROR => 'COMPILE ERROR',
E_COMPILE_WARNING => 'COMPILE WARNING',
E_USER_ERROR => 'USER ERROR',
E_USER_WARNING => 'USER WARNING',
E_USER_NOTICE => 'USER NOTICE',
];
$type = isset($error_types[$errno]) ? $error_types[$errno] : 'UNKNOWN ERROR';
// Log Error
$message = "[$type] $errstr in $errfile on line $errline";
error_log($message);
// Geliştirme ortamında detayları göster
if (defined('DEBUG') && DEBUG === true) {
echo "<div style='background: #fee; border: 1px solid #fcc; padding: 10px; margin: 10px 0;'>";
echo "<strong style='color: #c33;'>$type</strong><br>";
echo htmlspecialchars($errstr) . "<br>";
echo "<small>" . htmlspecialchars($errfile) . ":" . $errline . "</small>";
echo "</div>";
}
return true;
});
// Exception Handler
set_exception_handler(function($exception) {
// Log Exception
error_log("Exception: " . $exception->getMessage());
if (defined('DEBUG') && DEBUG === true) {
echo "<div style='background: #fee; border: 1px solid #fcc; padding: 10px; margin: 10px 0;'>";
echo "<strong style='color: #c33;'>Exception Error</strong><br>";
echo htmlspecialchars($exception->getMessage()) . "<br>";
echo "<small>" . htmlspecialchars($exception->getFile()) . ":" . $exception->getLine() . "</small>";
echo "</div>";
} else {
http_response_code(500);
include '404.php';
}
});
// Shutdown Function - Fatal Error'ları Yakala
register_shutdown_function(function() {
$error = error_get_last();
if ($error !== null) {
error_log("Fatal Error: " . $error['message']);
if (defined('DEBUG') && DEBUG === true) {
echo "<div style='background: #fee; border: 1px solid #fcc; padding: 10px; margin: 10px 0;'>";
echo "<strong style='color: #c33;'>FATAL ERROR</strong><br>";
echo htmlspecialchars($error['message']) . "<br>";
echo "<small>" . htmlspecialchars($error['file']) . ":" . $error['line'] . "</small>";
echo "</div>";
}
}
});
?>