1) { $path = rtrim($path, '/'); } $method = $_SERVER['REQUEST_METHOD'] ?? 'GET'; Logger::info('request', ['method' => $method, 'path' => $path]); // 注册路由(声明式路由表) $router = new Router(); foreach ((array) require APP_ROOT . '/app/config/routes.php' as $route) { $router->add($route['method'], $route['pattern'], $route['handler'], $route['middleware'] ?? []); } $match = $router->match($path, $method); if ($match === null) { Logger::warning('route not found', ['method' => $method, 'path' => $path]); Response::html( '404' . '' . '

404

页面不存在。

', 404 ); } call_user_func($match['handler'], $match['params']); } catch (\Throwable $e) { Logger::error('uncaught exception', [ 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine(), ]); $detail = Config::get('app.debug', false) ? '
' . e($e->getMessage()) . PHP_EOL . e($e->getFile() . ':' . $e->getLine()) . '
' : '

服务器开小差了,请稍后再试。

'; Response::html( '500' . '' . '

500

' . $detail . '', 500 ); }