改进验证类的场景设置

This commit is contained in:
thinkphp
2016-05-27 18:23:23 +08:00
parent 849058b89b
commit 5b62ac29a2

View File

@@ -237,6 +237,19 @@ class Validate
// 分析验证规则
$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) {
// field => rule1|rule2... field=>['rule1','rule2',...]
@@ -264,8 +277,13 @@ class Validate
if (!empty($scene)) {
if ($scene instanceof \Closure && !call_user_func_array($scene, [$key, &$data])) {
continue;
} elseif (is_array($scene) && !in_array($key, $scene)) {
continue;
} elseif (is_array($scene)) {
if (!in_array($key, $array)) {
continue;
} elseif (isset($change[$key])) {
// 重载某个验证规则
$rule = $change[$key];
}
}
}