From 0a7c5f06c609e96455ce2a60580255c2f2f2846f Mon Sep 17 00:00:00 2001 From: sunxyw <31698606+sunxyw@users.noreply.github.com> Date: Fri, 29 Apr 2022 12:23:06 +0800 Subject: [PATCH] refactor RouteManager static file routing (#105) --- src/ZM/Utils/Manager/RouteManager.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/ZM/Utils/Manager/RouteManager.php b/src/ZM/Utils/Manager/RouteManager.php index 9159ea83..32fa2558 100644 --- a/src/ZM/Utils/Manager/RouteManager.php +++ b/src/ZM/Utils/Manager/RouteManager.php @@ -10,7 +10,6 @@ use ZM\Annotation\Http\Controller; use ZM\Annotation\Http\RequestMapping; use ZM\Console\Console; use ZM\Http\StaticFileHandler; -use ZM\Store\LightCacheInside; /** * 路由管理器,2.5版本更改了命名空间 @@ -50,17 +49,14 @@ class RouteManager $tail = trim($route, '/'); $route_name = ($tail === '' ? '' : '/') . $tail . '/{filename}'; Console::debug('添加静态文件路由:' . $route_name); - $route = new Route($route_name, ['_class' => RouteManager::class, '_method' => 'onStaticRoute']); - // echo $path.PHP_EOL; - LightCacheInside::set('static_route', $route->getPath(), $path); + $route = new Route($route_name, ['_class' => __CLASS__, '_method' => 'onStaticRoute'], [], compact('path')); self::$routes->add(md5($route_name), $route); } - public function onStaticRoute($params) + public function onStaticRoute(array $params) { - $route_path = self::$routes->get($params['_route'])->getPath(); - if (($path = LightCacheInside::get('static_route', $route_path)) === null) { + if (($path = self::$routes->get($params['_route'])->getOption('path')) === null) { ctx()->getResponse()->endWithStatus(404); return false; }