| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
if (!defined('ROOT_PATH')) { |
| 24 |
define('ROOT_PATH', __DIR__ . (__DIR__ === DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR)); |
| 25 |
} |
| 26 |
|
| 27 |
$vc = require_once(ROOT_PATH . 'config' . DIRECTORY_SEPARATOR . 'vendor_config.php'); |
| 28 |
if (!is_array($vc) || !isset($vc['autoload_file'], $vc['config_file'], $vc['version_suffix'])) { |
| 29 |
echo 'Error: Incorrect vendor config file'; |
| 30 |
exit; |
| 31 |
} |
| 32 |
|
| 33 |
if (defined('PHP_UNIT_TEST')) { |
| 34 |
ob_start(); |
| 35 |
} |
| 36 |
|
| 37 |
define('APP_VERSION', '3.0-pre' . strval($vc['version_suffix'])); |
| 38 |
define('CONFIG_FILE', strval($vc['config_file'])); |
| 39 |
|
| 40 |
$va = strval($vc['autoload_file']); |
| 41 |
if (is_readable($va)) { |
| 42 |
require_once($va); |
| 43 |
} |
| 44 |
|
| 45 |
spl_autoload_register(function ($class) { |
| 46 |
$prefix = 'Liuch\\DmarcSrg\\'; |
| 47 |
$prefix_len = 15; |
| 48 |
$base_dir = ROOT_PATH . 'classes' . DIRECTORY_SEPARATOR; |
| 49 |
|
| 50 |
if (strncmp($prefix, $class, $prefix_len) === 0) { |
| 51 |
$relative_class = substr($class, $prefix_len); |
| 52 |
$file = $base_dir . str_replace('\\', DIRECTORY_SEPARATOR, $relative_class) . '.php'; |
| 53 |
if (file_exists($file)) { |
| 54 |
require_once($file); |
| 55 |
} |
| 56 |
} |
| 57 |
}); |
| 58 |
|
| 59 |
date_default_timezone_set('GMT'); |
| 60 |
|
| 61 |
$core = new Liuch\DmarcSrg\Core([ |
| 62 |
'auth' => [ 'Liuch\DmarcSrg\Auth' ], |
| 63 |
'admin' => [ 'Liuch\DmarcSrg\Admin' ], |
| 64 |
'ehandler' => [ 'Liuch\DmarcSrg\ErrorHandler' ], |
| 65 |
'config' => [ 'Liuch\DmarcSrg\Config', [ CONFIG_FILE ] ], |
| 66 |
'status' => [ 'Liuch\DmarcSrg\Status' ], |
| 67 |
'session' => [ 'Liuch\DmarcSrg\Session' ], |
| 68 |
'database' => [ 'Liuch\DmarcSrg\Database\DatabaseController' ], |
| 69 |
'template' => ROOT_PATH . 'template.html' |
| 70 |
]); |
| 71 |
$core->errorHandler()->setLogger(new Liuch\DmarcSrg\Log\PhpSystemLogger()); |
| 72 |
|
| 73 |
set_exception_handler(function ($e) { |
| 74 |
Liuch\DmarcSrg\Core::instance()->errorHandler()->handleException($e); |
| 75 |
}); |
| 76 |
|
| 77 |
set_error_handler(function (int $severity, string $message, string $file, int $line) { |
| 78 |
if (error_reporting() === 0) { |
| 79 |
return false; |
| 80 |
} |
| 81 |
throw new \ErrorException($message, -1, $severity, $file, $line); |
| 82 |
}); |
| 83 |
|
| 84 |
unset($vc, $va); |