-
Notifications
You must be signed in to change notification settings - Fork 8
/
Exception.php
173 lines (155 loc) · 3.83 KB
/
Exception.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
*
* @version 1.0
* @author Paul Dragoonis <dragoonis@php.net>
* @license http://opensource.org/licenses/mit-license.php MIT
* @copyright Digiflex Development
* @package Core
* @link www.ppiframework.com
*/
class PPI_Exception extends Exception {
/**
* The backtrace
*
* @var string
*/
public $_traceString = '';
/**
* The error line
*
* @var int|string
*/
public $line = '';
/**
* The error code
*
* @var int|string
*/
public $code = '';
/**
* The error message
*
* @var string
*/
public $message = '';
/**
* The error filename
*
* @var string
*/
public $file = '';
/**
* The backtrace as an array
*
* @var array
*/
public $_traceArray = array();
/**
* Any SQL queries that have been ran
*
* @var array
*/
public $_queries = array();
/**
* Singleton instance
*
* @var null
*/
private static $_instance = null;
/**
* Initialize the default registry instance.
* @return void
*/
protected static function init() {
self::setInstance(new PPI_Exception());
}
/**
* Set the default registry instance to a specified instance.
*
* @return void
*/
public static function setInstance(PPI_Exception $instance) {
self::$_instance = $instance;
}
/**
* Retrieves the default exception instance.
*/
public static function getInstance() {
if (self::$_instance === null) {
self::init();
}
return self::$_instance;
}
/**
* Initialise the PPI_Exception object and start setting up debug info such as backtraces.
*
* @param string $message
* @param null|array $sqlQueries
*/
function __construct($message = '', $sqlQueries = null) {
parent::__construct($message);
$this->_traceString = $this->getTraceAsString();
$this->_traceArray = $this->getTrace();
$this->_queries = PPI_Helper::getRegistry()->get('PPI_Model_Queries', array());
}
/**
* This function shows a 403 error
*
* @access public
* @return void
*/
function show_403($p_sMessage = "") {
$heading = "403 Forbidden";
$message = (!empty ($p_sMessage) ) ? $p_sMessage : "You are not allowed to access the requested location";
PPI_Helper::getRegistry()->set('PPI_View::httpResponseCode', 403);
require SYSTEMPATH.'errors/403.php';
}
/**
* This function shows a 404 error
*
* @access public
* @todo change this to a new function name
* @todo make this do 404 on the HTTP status line
* @param string argument name
* @return void
*/
static function show_404($p_sLocation = "", $p_bUseImage = false) {
$heading = "Page cannot be found";
$message = !empty($p_sLocation) ? $p_sLocation : "The page you requested was not found.";
PPI_Helper::getRegistry()->set('PPI_View::httpResponseCode', 404);
header('Status: 404 Not Found');
$oView = new PPI_Controller();
$oView->render('framework/404', array(
'heading' => 'Page cannot be found', 'message' => $message,
'errorPageType' => '404'
));
exit;
}
/**
* Show an error message
*
* @param string $p_sMsg
* @return void
*/
function show_error($p_sMsg) {
$oConfig = PPI_Helper::getConfig();
$heading = "PHP Error";
$baseUrl = $oConfig->system->base_url;
require SYSTEMPATH.'View/code_error.php';
echo $header.$html.$footer;
}
/**
* Same as show error but return the content as a param
*
* @param array $p_aError
* @return string The HTML contents
*/
function getErrorForEmail($p_aError = "") {
$oConfig = PPI_Helper::getConfig();
$heading = "PHP Error";
$baseUrl = $oConfig->system->base_url;
require SYSTEMPATH.'View/code_error.php';
return $html;
}
}