]> git.mxchange.org Git - hub.git/blob - ship-simu/application/hub/exceptions.php
Initial import
[hub.git] / ship-simu / application / hub / exceptions.php
1 <?php
2 // The hub's own exception handler
3 function hub_exception_handler ($exceptionInstance) {
4         // Is it an object and a valid instance?
5         if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
6                 // Get the regular trace
7                 $trace = $exceptionInstance->getTrace();
8
9                 // Get 3 call levels
10                 $backTrace = "";
11                 for ($idx = 0; $idx < 3; $idx++) {
12                         $traceArray = $trace[$idx];
13
14                         // Convert arguments type into human-readable
15                         $args = $traceArray['args'];
16                         $argsString = "";
17                         foreach ($args as $arg) {
18                                 $argsString .= ", ".gettype($arg);
19                         }
20                         $argsString = substr($argsString, 2);
21
22                         $backTrace .= sprintf("---------- Pos %d: ----------
23 Method : %s%s%s(%s)
24 ----- Caller: -----
25 File   : %s
26 Line   : %d\n",
27                                 ($idx + 1),
28                                 $traceArray['class'],
29                                 $traceArray['type'],
30                                 $traceArray['function'],
31                                 $argsString,
32                                 basename($traceArray['file']),
33                                 $traceArray['line']
34                         );
35                 }
36
37                 // Construct the message
38                 $message = sprintf("--------------------------------------------------------------------------------
39 Uncaught Exception : %s
40 --------------------------------------------------------------------------------
41 Message            : %s
42 Code               : %s
43 File               : %s
44 Line               : %d
45 --------------------------------------------------------------------------------
46 Backtrace:
47 --------------------------------------------------------------------------------
48 %s
49 --------------------------------------------------------------------------------\n",
50                         trim(html_entity_decode(strip_tags($exceptionInstance->__toString()))),
51                         trim(html_entity_decode(strip_tags($exceptionInstance->getMessage()))),
52                         $exceptionInstance->getHexCode(),
53                         $exceptionInstance->getFile(),
54                         $exceptionInstance->getLine(),
55                         trim($backTrace)
56                 );
57
58                 // Output the message
59                 print $message;
60         }
61 }
62
63 // Set the new handler
64 set_exception_handler('hub_exception_handler');
65
66 // [EOF]
67 ?>