-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_error.php
104 lines (89 loc) · 2.31 KB
/
class_error.php
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
Hadron Framework: Error Handling Object.
Created by Azareal.
Licensed under the terms of the GPLv3.
Copyright Azareal (c) 2013 - 2017
*/
// Hadron Framework namespace..
namespace Hadron;
// Is someone trying to access this directly?
if(!defined("HADRON_START")) die("You are not allowed to access this file directly.");
class Error
{
protected $log = [];
protected $devmode = 0;
protected $main = null;
public function __construct(Container $main)
{
$this->main = $main;
}
public function setDevMode($switch)
{
$this->devmode = $switch;
}
function query($msg, $critical = false)
{
trigger_error($msg,E_USER_ERROR);
if($critical && $this->devmode==1) {
echo "Failed to execute query: {$msg}.\n<br />Backtrace: ";
debug_print_backtrace();
exit;
} elseif($critical) {
header("HTTP/1.1 500 Internal Server Error");
die("Failed to execute query: {$msg}");
}
else $this->log[] = "Failed to execute query: {$msg}";
}
function custom($msg, $critical = false)
{
if($critical && $this->devmode==1) {
echo "{$msg}\n<br />Backtrace: ";
debug_print_backtrace();
exit;
} elseif(!$critical) {
header("HTTP/1.1 500 Internal Server Error");
die($msg);
}
else $this->log[] = $msg;
}
function raw($msg) { $this->log[] = $msg; }
function getError($type, $msg = null)
{
$plugins = $this->main->getPlugins();
// Does the page not exist?
if($type==404) return $plugins->hook("error_404", $msg);
// Not have permission to view this page?
elseif($type==403) return $plugins->hook("error_403", $msg);
// An error in the server itself?
elseif($type==500) return $plugins->hook("error_500", $msg);
return false;
}
function pop($offset = false)
{
if($offset) return $this->log[$offset];
if(count($this->log)==0) die($this->getError(500,"An unknown error was detected."));
$index = count($this->log) - 1;
$log = $this->log[$index];
unset($this->log[$index]);
return $log;
}
function output($offset = false)
{
if($offset) echo $this->log[$offset];
elseif(count($this->log)!=0) {
$log = $this->log;
foreach($log as $l) echo $l."<br />\n";
$this->log = [];
}
}
// Make sure errors are always outputted..
function __destruct()
{
if(count($this->log)!=0)
{
$log = $this->log;
foreach($log as $l) echo $l."<br />\n";
}
}
}