Update version.php to 3.3.0
[isso.git] / ExceptionHandler.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Exception Handler (ExceptionHandler.php)
24 *
25 * @package ISSO
26 */
27
28 /**
29 * Exception Handler
30 *
31 * This class will handle all exceptions that are uncaught in an application
32 *
33 * @author rsesek
34 * @copyright Copyright (c)2005 - 2009, Blue Static
35 * @package ISSO
36 *
37 */
38 class BSExceptionHandler
39 {
40 private function __construct()
41 {}
42
43 /**
44 * This is the handling dispatcher function that will examine, process
45 * and properly display exceptions
46 */
47 public static function handle(Exception $e)
48 {
49 // see if this was an application-level or framework-level exception
50 $trace = $e->getTrace();
51 $framework = false;
52 foreach ($trace as $i => $frame)
53 {
54 if (!isset($frame['file']))
55 {
56 continue;
57 }
58 if (strpos($frame['file'], ISSO) !== false || substr($frame['class'], 0, 2) == 'BS')
59 {
60 $framework = true;
61 break;
62 }
63 }
64 ?>
65 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
66 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
67 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
68 <head>
69 <title>Uncaught Exception</title>
70
71 <style type="text/css">
72 /*<![CDATA[*/
73 body
74 {
75 font-family: Helvetica, Arial, Verdana, sans-serif;
76 }
77
78 #warning
79 {
80 background-image: url('data:image/png;base64,<?php echo self::get_alert_image() ?>');
81 background-repeat: no-repeat;
82
83 margin: 75px 0px 0px 150px;
84 width: 600px;
85 }
86
87 h1
88 {
89 margin-left: 60px;
90 padding-top: 5px;
91 color: rgb(175, 0, 0);
92 }
93
94 pre
95 {
96 overflow: scroll;
97 }
98 /*]]>*/
99 </style>
100 </head>
101
102 <body>
103
104 <div id="warning">
105 <h1>Uncaught Exception</h1>
106
107 <p>
108 <em>An exception was encountered during the exection of this program. Because the program could not recover
109 from this error it terminated prematurely. Please contact a system administrator if this problem persists.</em>
110 </p>
111
112 <br/>
113
114 <p><strong>Time:</strong> <?php echo date('r') ?></p>
115
116 <p><strong>Context:</strong> <?php echo ($framework ? 'Framework' : 'Application')?></p>
117
118 <p><strong>Class:</strong> <?php echo get_class($e) . (get_parent_class($e) ? ' &lt; ' . get_parent_class($e) : '') ?></p>
119
120 <p><strong>Message:</strong> <?php echo $e->getMessage() ?></p>
121
122 <p>
123 <strong>Stack Trace:</strong><br/>
124 <pre>
125 <?php
126 $trace = $e->getTraceAsString();
127 echo (BSApp::get_debug() ? $trace : str_replace(getcwd(), '', $trace));
128 ?>
129 </pre>
130 </p>
131 </div>
132
133 </body>
134 </html>
135 <?php
136 }
137
138 /**
139 * Returns a base-64 representation of an alert sign
140 *
141 * @return string
142 */
143 protected static function get_alert_image()
144 {
145 return 'iVBORw0KGgoAAAANSUhEUgAAADcAAAA3CAYAAACo29JGAAAABGdBTUEAANbY1E9YMgAAABl0RVh0U2' .
146 '9mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAOlSURBVHja7Jq9jtNAEMediAcwb2CuQIgGIx6A' .
147 '8ATHFVDQXNwc5SUdXZIOqoQSmoSGhoJQc1JyPehSIXQSIjxBwhOE2dM/0t4y+2F77Tgnj7Ry7Djr/X' .
148 'k+dmY3jc1mE9xUadRwNVz1pFnWgz42Gi1qK2rjG6U5AmrTQYZaUHvyYrNZ77XmoCl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