Skip to content

Commit ffbdfdd

Browse files
committed
some logic update
1 parent d30a96c commit ffbdfdd

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -657,14 +657,14 @@ $v = Validation::make($_POST, [
657657

658658
```php
659659
[
660-
'goods' => [
661-
'apple' => 34,
662-
'pear' => 50,
663-
],
664-
'users' => [
665-
['id' => 34, 'name' => 'tom'],
666-
['id' => 89, 'name' => 'john'],
667-
]
660+
'goods' => [
661+
'apple' => 34,
662+
'pear' => 50,
663+
],
664+
'users' => [
665+
['id' => 34, 'name' => 'tom'],
666+
['id' => 89, 'name' => 'john'],
667+
]
668668
]
669669
```
670670

@@ -679,6 +679,8 @@ $v = Validation::make($_POST, [
679679
['users.*.name', 'each', 'string', 'min' => 5],
680680
```
681681

682+
> 对于带有通配符`*`的字段, 添加过滤器是无效的
683+
682684
## 一些关键方法API
683685

684686
### 设置验证场景

src/ValidationTrait.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,30 +204,30 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
204204
}
205205

206206
$value = $this->getByPath($field, $defValue);
207-
// $hasWildcard = (bool)strpos($field, '*');
208207

209-
// mark field is safe. not need validate. like. 'created_at'
210-
if ($validator === 'safe') {
211-
$this->setSafe($field, $value);
212-
continue;
213-
}
214-
215-
// required* 系列字段检查器 || 文件资源检查
216-
if (\is_string($validator) && (self::isCheckRequired($validator) || self::isCheckFile($validator))) {
217-
if (!$this->fieldValidate($field, $value, $validator, $args, $defMsg) && $this->isStopOnError()) {
218-
break;
208+
if (\is_string($validator)) {
209+
if ($validator === 'safe') {
210+
$this->setSafe($field, $value);
211+
continue;
219212
}
220213

221-
continue;
214+
// required*系列字段检查 || 文件资源检查
215+
if (self::isCheckRequired($validator) || self::isCheckFile($validator)) {
216+
if (!$this->fieldValidate($field, $value, $validator, $args, $defMsg) && $this->isStopOnError()) {
217+
break;
218+
}
219+
220+
continue;
221+
}
222222
}
223223

224224
// 设定了为空跳过 并且 值为空
225225
if ($skipOnEmpty && Helper::call($isEmpty, $value)) {
226226
continue;
227227
}
228228

229-
// 字段值过滤
230-
if ($filters) {
229+
// 字段值过滤(有通配符`*`的字段, 不应用过滤器)
230+
if ($filters && !strpos($field, '.*')) {
231231
$value = $this->valueFiltering($value, $filters);
232232
$this->data[$field] = $value;
233233
}

0 commit comments

Comments
 (0)