mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 07:32:48 +08:00
改进验证类的场景设置
This commit is contained in:
@@ -237,6 +237,19 @@ class Validate
|
|||||||
|
|
||||||
// 分析验证规则
|
// 分析验证规则
|
||||||
$scene = $this->getScene($scene);
|
$scene = $this->getScene($scene);
|
||||||
|
if (is_array($scene)) {
|
||||||
|
// 处理场景验证字段
|
||||||
|
$change = [];
|
||||||
|
$array = [];
|
||||||
|
foreach ($scene as $k => $val) {
|
||||||
|
if (is_numeric($k)) {
|
||||||
|
$array[] = $val;
|
||||||
|
} else {
|
||||||
|
$array[] = $k;
|
||||||
|
$change[$k] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($rules as $key => $item) {
|
foreach ($rules as $key => $item) {
|
||||||
// field => rule1|rule2... field=>['rule1','rule2',...]
|
// field => rule1|rule2... field=>['rule1','rule2',...]
|
||||||
@@ -264,8 +277,13 @@ class Validate
|
|||||||
if (!empty($scene)) {
|
if (!empty($scene)) {
|
||||||
if ($scene instanceof \Closure && !call_user_func_array($scene, [$key, &$data])) {
|
if ($scene instanceof \Closure && !call_user_func_array($scene, [$key, &$data])) {
|
||||||
continue;
|
continue;
|
||||||
} elseif (is_array($scene) && !in_array($key, $scene)) {
|
} elseif (is_array($scene)) {
|
||||||
continue;
|
if (!in_array($key, $array)) {
|
||||||
|
continue;
|
||||||
|
} elseif (isset($change[$key])) {
|
||||||
|
// 重载某个验证规则
|
||||||
|
$rule = $change[$key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user