Skip to content

Commit

Permalink
update ...
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 13, 2018
1 parent ffbdfdd commit 0232052
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ $v = Validation::make($_POST,[
### `isEmpty` -- 是否为空判断

是否为空判断, 这个判断作为 `skipOnEmpty` 的依据. 默认使用 `ValidatorList::isEmpty` 来判断.
是否为空判断, 这个判断作为 `skipOnEmpty` 的依据. 默认使用 `Validators::isEmpty` 来判断.

你也可以自定义判断规则:

Expand Down Expand Up @@ -634,6 +634,7 @@ $v = Validation::make($_POST, [
#### 提示和注意

- **请将 `required*` 系列规则写在规则列表的最前面**
- 规则上都支持添加过滤器
- 验证大小范围 `int` 是比较大小。 `string``array` 是检查长度。大小范围 是包含边界值的
- `size/range` `length` 可以只定义 `min` 或者 `max`
- 支持对数组的子级值验证
Expand Down Expand Up @@ -679,7 +680,7 @@ $v = Validation::make($_POST, [
['users.*.name', 'each', 'string', 'min' => 5],
```

> 对于带有通配符`*`的字段, 添加过滤器是无效的
- 对于带有通配符`*`的字段, 添加过滤器是无效的

## 一些关键方法API

Expand Down
2 changes: 1 addition & 1 deletion src/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
$fields = \is_string($fields) ? Helper::explode($fields) : (array)$fields;
$validator = $rule[0];

// 如何判断属性为空 默认使用 ValidatorList::isEmpty(). 也可自定义
// 如何判断属性为空 默认使用 Validators::isEmpty(). 也可自定义
$isEmpty = [Validators::class, 'isEmpty'];
if (!empty($rule['isEmpty']) && (\is_string($rule['isEmpty']) || $rule['isEmpty'] instanceof \Closure)) {
$isEmpty = $rule['isEmpty'];
Expand Down
8 changes: 2 additions & 6 deletions src/Validators.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Inhere\Validate\Utils\Helper;

/**
* Class ValidatorList
* Class Validators
* @package Inhere\Validate
*/
class Validators
Expand Down Expand Up @@ -983,11 +983,7 @@ public static function dateFormat($val, $format = 'Y-m-d')
}

// 校验日期的格式有效性
if (date($format, $unixTime) === $val) {
return true;
}

return false;
return date($format, $unixTime) === $val;
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/ValidatorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,13 @@ public function testDate()
$this->assertTrue(Validators::date(170526));
$this->assertTrue(Validators::date('20170526'));
}

public function testDateFormat()
{
$this->assertFalse(Validators::dateFormat('hello'));
// $t = strtotime('20170526');
// var_dump($t, time(), date('ymd', $t));
$this->assertFalse(Validators::dateFormat('170526', 'ymd'));
$this->assertTrue(Validators::dateFormat('20170526', 'Ymd'));
}
}

0 comments on commit 0232052

Please sign in to comment.