]> git.mxchange.org Git - hub.git/blob - application/hub/exceptions.php
Space added
[hub.git] / application / hub / exceptions.php
1 <?php
2 /**
3  * An include file for setting up the exception handler of the hub
4  *
5  *
6  * @author              Roland Haeder <webmaster@ship-simu.org>
7  * @version             0.0
8  * @copyright   Copyright (c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
9  * @license             GNU GPL 3.0 or any newer version
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25 // The hub's own exception handler
26 function hub_exception_handler ($exceptionInstance) {
27         // Is it an object and a valid instance?
28         if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
29                 // Get the regular trace
30                 $trace = $exceptionInstance->getTrace();
31
32                 // Get 3 call levels
33                 $backTrace = "";
34                 for ($idx = 0; $idx < 3; $idx++) {
35                         // Copy array for argument analysis and init variable
36                         $traceArray = $trace[$idx];
37                         $argsString = "";
38
39                         // Convert arguments type into human-readable
40                         foreach ($traceArray['args'] as $arg) {
41                                 $argsString .= ", " . gettype($arg);
42                         } // END - foreach
43                         $argsString = substr($argsString, 2);
44
45                         $backTrace .= sprintf("---------- Pos %d: ----------
46 Method : %s%s%s(%s)
47 ----- Caller: -----
48 File   : %s
49 Line   : %d\n",
50                                 ($idx + 1),
51                                 $traceArray['class'],
52                                 $traceArray['type'],
53                                 $traceArray['function'],
54                                 $argsString,
55                                 basename($traceArray['file']),
56                                 $traceArray['line']
57                         );
58                 } // END - for
59
60                 // Construct the message
61                 $message = sprintf("--------------------------------------------------------------------------------
62 Uncaught Exception : %s
63 --------------------------------------------------------------------------------
64 Message            : %s
65 Code               : %s
66 File               : %s
67 Line               : %d
68 --------------------------------------------------------------------------------
69 Backtrace:
70 --------------------------------------------------------------------------------
71 %s
72 --------------------------------------------------------------------------------\n",
73                         trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
74                         trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
75                         $exceptionInstance->getHexCode(),
76                         $exceptionInstance->getFile(),
77                         $exceptionInstance->getLine(),
78                         trim($backTrace)
79                 );
80
81                 // Output the message
82                 print($message);
83         } else {
84                 // Invalid exception instance detected! Do *only* throw exceptions that
85                 // extends our own exception 'FrameworkException' to get such nice
86                 // outputs like above.
87                 print("exceptionInstance is invalid! Please inform the core developer team.\n");
88         }
89 }
90
91 // Set the new handler
92 set_exception_handler('hub_exception_handler');
93
94 // [EOF]
95 ?>