mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 15:12:48 +08:00
自动验证的错误信息返回格式调整 由验证方法决定返回数组还是字符串
This commit is contained in:
@@ -1044,7 +1044,7 @@ class Model
|
|||||||
// 匿名函数验证 支持传入当前字段和所有字段两个数据
|
// 匿名函数验证 支持传入当前字段和所有字段两个数据
|
||||||
$result = call_user_func_array($val, [$value, &$data]);
|
$result = call_user_func_array($val, [$value, &$data]);
|
||||||
} elseif (is_string($val)) {
|
} elseif (is_string($val)) {
|
||||||
// 行为验证
|
// 行为验证 用于一次性批量验证
|
||||||
$result = Hook::exec($val, '', $data);
|
$result = Hook::exec($val, '', $data);
|
||||||
} else {
|
} else {
|
||||||
// 验证字段规则
|
// 验证字段规则
|
||||||
@@ -1052,14 +1052,11 @@ class Model
|
|||||||
}
|
}
|
||||||
if (true !== $result) {
|
if (true !== $result) {
|
||||||
// 没有返回true 则表示验证失败
|
// 没有返回true 则表示验证失败
|
||||||
if (is_array($result)) {
|
if (!empty($options['patch'])) {
|
||||||
// 返回组装的错误信息
|
// 批量验证
|
||||||
$this->error = $result;
|
$this->error[] = $result;
|
||||||
} else {
|
} else {
|
||||||
$this->error[] = ['key' => $key, 'error' => $result];
|
$this->error = $result;
|
||||||
}
|
|
||||||
if (empty($options['patch'])) {
|
|
||||||
// 不是批量验证则返回
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1187,7 +1184,7 @@ class Model
|
|||||||
// 行为验证
|
// 行为验证
|
||||||
$result = Hook::exec($rule, '', $data);
|
$result = Hook::exec($rule, '', $data);
|
||||||
break;
|
break;
|
||||||
case 'filter': // 使用filter_var验证
|
case 'filter': // 使用filter_var验证
|
||||||
$result = filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options);
|
$result = filter_var($value, is_int($rule) ? $rule : filter_id($rule), $options);
|
||||||
break;
|
break;
|
||||||
case 'confirm':
|
case 'confirm':
|
||||||
@@ -1198,8 +1195,8 @@ class Model
|
|||||||
$range = is_array($rule) ? $rule : explode(',', $rule);
|
$range = is_array($rule) ? $rule : explode(',', $rule);
|
||||||
$result = 'in' == $type ? in_array($value, $range) : !in_array($value, $range);
|
$result = 'in' == $type ? in_array($value, $range) : !in_array($value, $range);
|
||||||
break;
|
break;
|
||||||
case 'between':// 验证是否在某个范围
|
case 'between': // 验证是否在某个范围
|
||||||
case 'notbetween': // 验证是否不在某个范围
|
case 'notbetween': // 验证是否不在某个范围
|
||||||
if (is_string($rule)) {
|
if (is_string($rule)) {
|
||||||
$rule = explode(',', $rule);
|
$rule = explode(',', $rule);
|
||||||
}
|
}
|
||||||
@@ -1215,7 +1212,7 @@ class Model
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// 验证失败返回错误信息
|
// 验证失败返回错误信息
|
||||||
return false === $result ? $msg : true;
|
return (is_array($result) || true === $result) ? $result : $msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user