mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 07:12:47 +08:00
路由变量规则支持闭包
This commit is contained in:
@@ -1285,9 +1285,16 @@ class Route
|
|||||||
if (!$optional && !isset($m1[$key])) {
|
if (!$optional && !isset($m1[$key])) {
|
||||||
return false;
|
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] : '';
|
$var[$name] = isset($m1[$key]) ? $m1[$key] : '';
|
||||||
} elseif (!isset($m1[$key]) || 0 !== strcasecmp($val, $m1[$key])) {
|
} elseif (!isset($m1[$key]) || 0 !== strcasecmp($val, $m1[$key])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user