Smutty
MVC Framework
View Code: Smutty_Exception
Browse: All · Classes · Plugins
1
<?
2
3
define( 'ERR_ALL', 1 );
4
define( 'ERR_STANDARD', 2 );
5
6
/**
7
* this class handles all exceptions and warnings
8
* generated by smutty.
9
*
10
*/
11
12
class Smutty_Exception extends Smutty_Object {
13
14
// warnings that have been generated
15
private $warnings;
16
17
// are templates enabled?
18
private $useTemplates;
19
20
// error types to show
21
private $errorTypes;
22
23
// singleton
24
private static $instance = null;
25
26
/**
27
* constructor
28
*
29
* @return nothing
30
*
31
*/
32
34
$this->warnings = array();
35
$this->useTemplates = false;
36
$this->errorTypes = ERR_STANDARD;
37
}
38
39
/**
40
* enables the use of smarty templates for error
41
* reporting purposes
42
*
43
* @return nothing
44
*
45
*/
46
48
$this->useTemplates = true;
49
}
50
51
/**
52
* returns the singleton instance for this object. this singleton
53
* can then be used to set global error reporting options.
54
*
55
* @return Smutty_Exception
56
*
57
*/
58
59
public static function &getInstance() {
60
if ( self::$instance == null )
61
self::$instance = new Smutty_Exception();
62
return self::$instance;
63
}
64
65
/**
66
* returns a boolean indicating if templates will be
67
* used when reporting an error
68
*
69
* @return boolean
70
*
71
*/
72
74
return $this->useTemplates;
75
}
76
77
/**
78
* call this to raise a fatal error
79
*
80
* @param String $message the error message
81
* @param String $wikiHelp name of wiki help page
82
* @param int $code http status code
83
* @return nothing
84
*
85
*/
86
88
$e =& Smutty_Exception::getInstance();
89
header( 'HTTP/1.1 ' . $code );
90
if ( $e->useTemplates )
91
$e->showTemplate($message,$wikiHelp);
92
else
93
$e->showStandard($message,$wikiHelp);
94
exit();
95
}
96
97
/**
98
* this method is used to indicate that something has gone wrong, but
99
* that it's not serious. just a warning. these warning messages
100
* can then be reached by the getWarnings() method
101
*
102
* @param String $message the warning message
103
* @param String $wikiHelp the wiki help page
104
* @return nothing
105
*
106
*/
107
109
$e =& Smutty_Exception::getInstance();
110
$e->addWarning( $message, $wikiHelp );
111
}
112
113
/**
114
* adds a warning message
115
*
116
* @param String $message the warning message
117
* @param String $wikiHelp the wiki help page
118
* @return nothing
119
*
120
*/
121
123
$warning = new stdclass();
124
$warning->message = $message;
125
$warning->wikiHelp = $wikiHelp;
126
$this->warnings[] = $warning;
127
}
128
129
/**
130
* returns an array of warning messages that have been generated
131
*
132
* @return array
133
*
134
*/
135
137
return $this->warnings;
138
}
139
140
/**
141
* handles an error from php.
142
*
143
* @param int $errno severity
144
* @param String $errstr description
145
* @param String $errfile the files full path
146
* @param int $errline the line
147
* @param int $errcon the contect
148
* @return nothing
149
*
150
*/
151
153
$showError = true;
154
switch ( $this->errorTypes ) {
155
case ERR_ALL:
156
break;
157
case ERR_STANDARD:
158
if ( in_array($errno,array(E_NOTICE)) )
159
$showError = false;
160
break;
161
}
162
// really show the error?
163
if ( $showError )
164
Smutty_Exception::fatal(
165
"($errno) $errstr ($errfile, line $errline)",
166
'SmuttyOverview'
167
);
168
}
169
170
/**
171
* shows an error message using smarty templates
172
*
173
* @param String $message the error message
174
* @param String $wikiHelp name of wiki help page
175
* @return nothing
176
*
177
*/
178
180
$tpl = new Smutty_Template_Smutty();
181
$tpl->assign( 'stack', debug_backtrace() );
182
$tpl->assign( 'message', $message );
183
$tpl->assign( 'wikiHelp', $wikiHelp );
184
$tpl->display( 'exception.tpl' );
185
}
186
187
/**
188
* shows an error message with standard output
189
*
190
* @param String $message the error message
191
* @param String $wikiHelp name of wiki help page
192
* @return nothing
193
*
194
*/
195
197
?>
198
<html><head><title>Smutty Exception</title></head><body>
199
<h1><Smutty Exception></h1>
200
<p>Burp! An error has occurred, the following message was reported:</p>
201
<blockquote><?= htmlspecialchars($message) ?></blockquote>
202
<p>You may be able to <a href="http://smutty.pu-gh.com/wiki/<?= urlencode($wikiHelp) ?>">find help
203
on the wiki</a>! (<?= htmlspecialchars($wikiHelp) ?>)</p>
204
</body></html>
205
<?
206
}
207
208
/**
209
* sets the level of error reporting
210
*
211
* @param int $type the errors types to show
212
* @return nothing
213
*
214
*/
215
217
$e =& Smutty_Exception::getInstance();
218
$e->errorTypes = $type;
219
}
220
221
/**
222
* returns the current level of error reporting
223
*
224
* @return integer
225
*
226
*/
227
229
$e =& Smutty_Exception::getInstance();
230
return $e->errorTypes;
231
}
232
233
}
234
235
?>
The code shown here is the code that is currently running this site. If you want to view the latest SVN version of the code then go to the Subversion repository.