From cbd4c2c98c5ae31dc9dcf350ca78132949bb6625 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Wed, 19 Oct 2016 22:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=8F=98=E9=87=8F=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=94=AF=E6=8C=81=E9=97=AD=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Route.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/think/Route.php b/library/think/Route.php index 8ecbcb7e..c97f0cb5 100644 --- a/library/think/Route.php +++ b/library/think/Route.php @@ -1285,9 +1285,16 @@ class Route if (!$optional && !isset($m1[$key])) { return false; } - if (isset($m1[$key]) && isset($pattern[$name]) && !preg_match('/^' . $pattern[$name] . '$/', $m1[$key])) { + if (isset($m1[$key]) && isset($pattern[$name])) { // 检查变量规则 - return false; + if ($pattern[$name] instanceof \Closure) { + $result = call_user_func_array($pattern[$name], [$m1[$key]]); + if (false === $result) { + return false; + } + } elseif (!preg_match('/^' . $pattern[$name] . '$/', $m1[$key])) { + return false; + } } $var[$name] = isset($m1[$key]) ? $m1[$key] : ''; } elseif (!isset($m1[$key]) || 0 !== strcasecmp($val, $m1[$key])) {