Skip to content

Commit

Permalink
some logic update
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 13, 2018
1 parent d30a96c commit ffbdfdd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@ $v = Validation::make($_POST, [

```php
[
'goods' => [
'apple' => 34,
'pear' => 50,
],
'users' => [
['id' => 34, 'name' => 'tom'],
['id' => 89, 'name' => 'john'],
]
'goods' => [
'apple' => 34,
'pear' => 50,
],
'users' => [
['id' => 34, 'name' => 'tom'],
['id' => 89, 'name' => 'john'],
]
]
```

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

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

### 设置验证场景
Expand Down
28 changes: 14 additions & 14 deletions src/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,30 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
}

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

// mark field is safe. not need validate. like. 'created_at'
if ($validator === 'safe') {
$this->setSafe($field, $value);
continue;
}

// required* 系列字段检查器 || 文件资源检查
if (\is_string($validator) && (self::isCheckRequired($validator) || self::isCheckFile($validator))) {
if (!$this->fieldValidate($field, $value, $validator, $args, $defMsg) && $this->isStopOnError()) {
break;
if (\is_string($validator)) {
if ($validator === 'safe') {
$this->setSafe($field, $value);
continue;
}

continue;
// required*系列字段检查 || 文件资源检查
if (self::isCheckRequired($validator) || self::isCheckFile($validator)) {
if (!$this->fieldValidate($field, $value, $validator, $args, $defMsg) && $this->isStopOnError()) {
break;
}

continue;
}
}

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

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

0 comments on commit ffbdfdd

Please sign in to comment.