mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-23 08:35:35 +08:00
refactor RouteManager static file routing (#105)
This commit is contained in:
@@ -10,7 +10,6 @@ use ZM\Annotation\Http\Controller;
|
|||||||
use ZM\Annotation\Http\RequestMapping;
|
use ZM\Annotation\Http\RequestMapping;
|
||||||
use ZM\Console\Console;
|
use ZM\Console\Console;
|
||||||
use ZM\Http\StaticFileHandler;
|
use ZM\Http\StaticFileHandler;
|
||||||
use ZM\Store\LightCacheInside;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 路由管理器,2.5版本更改了命名空间
|
* 路由管理器,2.5版本更改了命名空间
|
||||||
@@ -50,17 +49,14 @@ class RouteManager
|
|||||||
$tail = trim($route, '/');
|
$tail = trim($route, '/');
|
||||||
$route_name = ($tail === '' ? '' : '/') . $tail . '/{filename}';
|
$route_name = ($tail === '' ? '' : '/') . $tail . '/{filename}';
|
||||||
Console::debug('添加静态文件路由:' . $route_name);
|
Console::debug('添加静态文件路由:' . $route_name);
|
||||||
$route = new Route($route_name, ['_class' => RouteManager::class, '_method' => 'onStaticRoute']);
|
$route = new Route($route_name, ['_class' => __CLASS__, '_method' => 'onStaticRoute'], [], compact('path'));
|
||||||
// echo $path.PHP_EOL;
|
|
||||||
LightCacheInside::set('static_route', $route->getPath(), $path);
|
|
||||||
|
|
||||||
self::$routes->add(md5($route_name), $route);
|
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 = self::$routes->get($params['_route'])->getOption('path')) === null) {
|
||||||
if (($path = LightCacheInside::get('static_route', $route_path)) === null) {
|
|
||||||
ctx()->getResponse()->endWithStatus(404);
|
ctx()->getResponse()->endWithStatus(404);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user