Skip to content

Commit

Permalink
fixed bug:解决单元测试有未定义数组下标的警告信息导致不通过
Browse files Browse the repository at this point in the history
  • Loading branch information
cmpan committed Sep 18, 2017
1 parent 69c9811 commit 4b898ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name" : "windwork/util",
"description" : "windwork util component,Windwork 工具组件",
"version" : "0.6.0",
"time" : "2017-06-28 18:30:00",
"version" : "0.6.1",
"require" : {
"php" : ">=5.5.0"
},
Expand Down
10 changes: 5 additions & 5 deletions lib/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,21 @@ public function validate(array $data, array $rules, $firstErrBreak = false)
{
$this->errors = [];
foreach ($rules as $key => $fieldRule) {
// 待验证字符串
$string = @$data[$key];

// 为空并且允许为空则不检查
if(empty($data[$key]) && !array_key_exists('required', $fieldRule)) {
if(empty($string) && !array_key_exists('required', $fieldRule)) {
continue;
}

// 待验证字符串
$string = $data[$key];

foreach ($fieldRule as $method => $msg) {
$method = trim($method);

// 自定义正则,下标第一个字符不是字母
// 自定义格式必须是以正则匹配规则作为下标,提示消息作为值
if (preg_match("/[^a-z]/i", $method[0])) {
if(!preg_match($method, $data[$key])) {
if(!preg_match($method, $string)) {
$this->errors[] = $msg;
}

Expand Down

0 comments on commit 4b898ed

Please sign in to comment.