From 782ee8fcf84d693ff799b01ffc2aa4dcc9a2daa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E7=9F=B3=E6=B1=89?= Date: Thu, 15 Oct 2020 17:25:53 +0800 Subject: [PATCH] update app/Http/Middleware/ParamsValidation.php. --- app/Http/Middleware/ParamsValidation.php | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/Http/Middleware/ParamsValidation.php b/app/Http/Middleware/ParamsValidation.php index 2e57487..7927928 100644 --- a/app/Http/Middleware/ParamsValidation.php +++ b/app/Http/Middleware/ParamsValidation.php @@ -32,6 +32,37 @@ class ParamsValidation if (!class_exists($RulesClass)) { throw new DevException(); } + + $path = $request->path(); + + // 处理参数在路由上面的 + $rRoute = $request->route(); + if( isset($rRoute[2]) && count($rRoute[2])>0 ) + { + $RouteList = Utils::getRouteList(); + $parasKey = $rRoute[2]; + $path = array_filter($RouteList, function($v) use ($parasKey, $path) { + $vv = $v; + foreach( $parasKey as $pk=>$pv ) + { + if( strpos($v, $pk) === false ) return false; + + $vv = str_replace("{".$pk."}", $pv, $vv); + } + + if( substr($vv, 0,1)==='/' ) $vv = substr($vv, 1); + if( $vv != $path ) return false; + + return true; + }); + + + if( count($path)>1 ) throw new DevException(); + + $path = current($path); + if( substr($path, 0,1)==='/' ) $path = substr($path, 1); + } + $rules = new $RulesClass($request->route()->uri, $request); HandleValidator::execute($request->input(), $rules); -- Gitee