From 2d12e1dc48092abc149ebadd0cd8896a47ceba84 Mon Sep 17 00:00:00 2001 From: lf <40257554+onlomk@users.noreply.github.com> Date: Mon, 3 Nov 2025 17:40:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=AF=E7=94=B1=E4=B8=AD?= =?UTF-8?q?=E9=97=B4=E4=BB=B6=E6=95=B0=E7=BB=84=E4=BC=A0=E5=8F=82=EF=BC=8C?= =?UTF-8?q?=E5=92=8CwithoutMiddleware=E7=9A=84=E5=86=B2=E7=AA=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 路由中间件,使用数组方式传参,再进行 withoutMiddleware 排除中间件 异常 #3113 --- src/think/route/Dispatch.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/think/route/Dispatch.php b/src/think/route/Dispatch.php index bde9889725..347d2f2e0d 100644 --- a/src/think/route/Dispatch.php +++ b/src/think/route/Dispatch.php @@ -86,7 +86,15 @@ protected function doRouteAfter(): void // 添加中间件 if (!empty($option['middleware'])) { if (isset($option['without_middleware'])) { - $middleware = !empty($option['without_middleware']) ? array_diff($option['middleware'], $option['without_middleware']) : []; + $middleware = []; + foreach ($option['middleware'] as $m) { + // $m 可能是 [类名, 参数数组] 或 字符串类名/闭包 + $classOrClosure = is_array($m) ? $m[0] : $m; + // 如果不在排除列表里,保留原始 $m + if (empty($option['without_middleware']) || !in_array($classOrClosure, $option['without_middleware'], true)) { + $middleware[] = $m; + } + } } else { $middleware = $option['middleware']; }