-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
66 lines (45 loc) · 1.87 KB
/
Bootstrap.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace verfriemelt\wrapped;
use ErrorException;
use verfriemelt\wrapped\_\Cli\Console;
class Bootstrap {
CONST NAMESPACE = "verfriemelt\\wrapped";
static public function registerAutoloader() {
spl_autoload_register( function ( $class ) {
if ( substr( $class, 0, strlen( self::NAMESPACE ) ) !== self::NAMESPACE ) {
return false;
}
$class = substr( $class, strlen( self::NAMESPACE ) );
$possiblePath = __DIR__ . "/" . str_replace( "\\", "/", $class ) . ".php";
if ( file_exists( $possiblePath ) ) {
return require_once $possiblePath;
}
} );
}
static public function registerExceptionHandling() {
// lazy ass exception handling
set_exception_handler( function ( $e ) {
if ( !Console::isCli() ) {
// header( "Content-type: text/plain" );
}
$trace = $e->getTraceAsString() . PHP_EOL . PHP_EOL . PHP_EOL . print_r( $e, 1 );
$trace .= PHP_EOL . PHP_EOL;
$trace .= "SERVER:";
$trace .= PHP_EOL;
$trace .= print_r( $_SERVER, 1 );
$trace .= PHP_EOL . PHP_EOL;
$trace .= "GET:";
$trace .= PHP_EOL;
$trace .= print_r( $_GET, 1 );
$trace .= PHP_EOL . PHP_EOL;
$trace .= "POST:";
$trace .= PHP_EOL;
$trace .= print_r( $_POST, 1 );
echo $trace;
die();
} );
set_error_handler( function ( $errno, $errstr, $errfile, $errline ) {
throw new ErrorException( $errstr, 0, $errno, $errfile, $errline );
} );
}
}