-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.php
68 lines (55 loc) · 2.03 KB
/
init.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
67
68
<?php
function dump_backtrace_to_stderr($bt) {
foreach ($bt as $id => $frame) {
if ($id == 0) {
file_put_contents('php://stderr', "Traceback (most recent call last):\n");
}
foreach (['type', 'class'] as $k) {
if (!isset($frame[$k])) $frame[$k] = '';
}
file_put_contents('php://stderr', sprintf(
'#%2d# %s%s%s()'."\n",
$id, $frame['class'], $frame['type'], $frame['function']
));
if (isset($frame['file'])) {
file_put_contents('php://stderr', sprintf(
' File "%s" (line %s)'."\n",
$frame['file'], $frame['line']
));
}
}
}
function dump_exception_to_stderr($e) {
file_put_contents('php://stderr', sprintf("Exception: %s\n\n", $e->getMessage()));
dump_backtrace_to_stderr($e->getTrace());
}
function debug_php_error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
file_put_contents('php://stderr', sprintf(
"PHP warning triggered: %s (\"%s\" line %d)\n\n", $errstr, $errfile, $errline
));
dump_backtrace_to_stderr(array_reverse(debug_backtrace()));
return false; // continue with the normal error handler
}
// shamelessly copied from WordPress source code :)
define('ABSPATH', dirname(__FILE__) . '/');
spl_autoload_register(function ($class_name) {
$class_name = preg_replace('/\\\\/', '/', $class_name);
if (strpos($class_name, '..') !== false) {
throw new Exception("Bad class name: $class_name");
}
$sf = ABSPATH . "vendor/$class_name.php";
if (file_exists($sf)) {
require_once($sf);
}
});
set_exception_handler('dump_exception_to_stderr');
set_error_handler('debug_php_error_handler');
require_once(ABSPATH . 'config.php');
\famzah\PNP\PNPApp::Initialize(ABSPATH . 'pnp', $config['plugins']);
#\famzah\PNP\PNPApp::getInstance()->traceEnabled = true;
$Utils = \famzah\PNP\PNPApp::getInstance()->new_object('\rrdg\lib\Utils');
$Utils->x_check_config($config); // cross-check config values
$Mapping = \famzah\PNP\PNPApp::getInstance()
->new_object('\rrdg\lib\Mapping', $config);
$Search = \famzah\PNP\PNPApp::getInstance()
->new_object('\rrdg\lib\Search', $config, $Utils, $Mapping);