-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.php
50 lines (40 loc) · 1.44 KB
/
debug.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
<?php
error_reporting ( -1 );
assert_options ( ASSERT_ACTIVE, 1 );
assert_options ( ASSERT_WARNING, 0 );
assert_options ( ASSERT_BAIL, 0 );
assert_options ( ASSERT_QUIET_EVAL, 0 );
assert_options ( ASSERT_CALLBACK, 'assert_callcack' );
set_error_handler ( 'error_handler' );
set_exception_handler ( 'exception_handler' );
register_shutdown_function ( 'shutdown_handler' );
function assert_callcack ( $file, $line, $message ) {
throw new CustomizableException( $message, NULL, $file, $line );
}
function error_handler ( $errno, $error, $file, $line, $vars ) {
if ( $errno === 0 || ( $errno & error_reporting () ) === 0 ) return;
throw new CustomizableException( $error, $errno, $file, $line );
}
function exception_handler ( Exception $e ) {
// Do what ever!
echo '<pre>', print_r ( $e, TRUE ), '</pre>';
exit;
}
function shutdown_handler () {
try {
if ( NULL !== $error = error_get_last () ) throw new CustomizableException( $error[ 'message' ],
$error[ 'type' ], $error[ 'file' ], $error[ 'line' ] );
} catch ( \Exception $e ) {
exception_handler ( $e );
}
}
class CustomizableException extends \Exception {
public function __construct ( $message = NULL, $code = NULL, $file = NULL, $line = NULL ) {
if ( $code === NULL ) parent::__construct ( $message );
else
parent::__construct ( $message, $code );
if ( $file !== NULL ) $this->file = $file;
if ( $line !== NULL ) $this->line = $line;
}
}
?>