-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.php
More file actions
75 lines (58 loc) · 2.1 KB
/
index.php
File metadata and controls
75 lines (58 loc) · 2.1 KB
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
69
70
71
72
73
74
75
<?php
while (ob_get_level() > 0) {
ob_end_clean();
}
ini_set('output_buffering', '0');
ini_set('implicit_flush', '1');
ini_set('display_errors', '1');
error_reporting(E_ALL);
define('ERROR_LOG_FILE', __DIR__ . '/error_log');
require_once __DIR__ . '/src/Logger.php';
require_once __DIR__ . '/src/Config.php';
S3Gateway\Logger::init(ERROR_LOG_FILE);
// 立即记录一些初始化信息
S3Gateway\Logger::info("=== S3 Gateway Initializing ===");
S3Gateway\Logger::info("PHP Version: " . phpversion());
S3Gateway\Logger::info("Error log file: " . ERROR_LOG_FILE);
// 测试配置加载
try {
$appDebug = S3Gateway\Config::appDebug();
S3Gateway\Logger::info("Config loaded - APP_DEBUG: " . var_export($appDebug, true));
} catch (Exception $e) {
S3Gateway\Logger::error("Error loading config: " . $e->getMessage());
}
set_error_handler(function($errno, $errstr, $errfile, $errline) {
S3Gateway\Logger::error(sprintf("Error [%d]: %s in %s:%d", $errno, $errstr, $errfile, $errline));
return false;
});
set_exception_handler(function($e) {
S3Gateway\Logger::exception($e, 'Uncaught Exception');
http_response_code(500);
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Error><Code>InternalError</Code><Message>' . $e->getMessage() . '</Message></Error>';
});
spl_autoload_register(function ($class) {
$prefix = 'S3Gateway\\';
$baseDir = __DIR__ . '/src/';
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) {
return;
}
$relativeClass = substr($class, $len);
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
if (file_exists($file)) {
require $file;
}
});
use S3Gateway\Http\Router;
try {
$router = new Router();
$router->handle();
} catch (Throwable $e) {
S3Gateway\Logger::exception($e, 'Unhandled Throwable');
http_response_code(500);
header('Content-Type: application/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<Error><Code>InternalError</Code><Message>' . $e->getMessage() . '</Message></Error>';
}