@@ -218,14 +218,14 @@ public function validate(array $onlyChecked = [], $stopOnError = null)
218
218
foreach ($ attrs as $ attr ) {
219
219
$ value = $ this ->getValue ($ attr );
220
220
221
- // mark attribute is safe. not need validate. like. 'created_at'
222
- if ($ validator === 'safe ' ) {
223
- $ this ->_safeData [$ attr ] = $ value ;
221
+ // 不在需要检查的列表内
222
+ if ($ onlyChecked && !in_array ($ attr , $ onlyChecked , true )) {
224
223
continue ;
225
224
}
226
225
227
- // 不在需要检查的列表内
228
- if ($ onlyChecked && !in_array ($ attr , $ onlyChecked , true )) {
226
+ // mark attribute is safe. not need validate. like. 'created_at'
227
+ if ($ validator === 'safe ' ) {
228
+ $ this ->_safeData [$ attr ] = $ value ;
229
229
continue ;
230
230
}
231
231
@@ -300,22 +300,23 @@ protected function requiredValidate($attr, $value, $validator, $args)
300
300
$ result = $ this ->required ($ attr );
301
301
302
302
// 其他 required* 方法
303
- } else {
303
+ } elseif ( method_exists ( $ this , $ validator )) {
304
304
// 压入当前属性/字段名
305
305
array_unshift ($ args , $ attr );
306
306
307
307
$ result = call_user_func_array ([$ this , $ validator ], $ args );
308
- }
309
-
310
- // failed
311
- if (!$ result ) {
312
- return false ;
308
+ } else {
309
+ throw new \InvalidArgumentException ("The validator [ $ validator] is not exists! " );
313
310
}
314
311
315
312
// validate success, save value to safeData
316
- $ this ->collectSafeValue ($ attr , $ value );
313
+ if ($ result ) {
314
+ $ this ->collectSafeValue ($ attr , $ value );
317
315
318
- return true ;
316
+ return true ;
317
+ }
318
+
319
+ return false ;
319
320
}
320
321
321
322
/**
@@ -364,14 +365,14 @@ protected function doValidate($data, $attr, $value, $validator, $args)
364
365
throw new \InvalidArgumentException ('Validator type is error, must is String or Closure! ' );
365
366
}
366
367
367
- if (!call_user_func_array ($ callback , $ args )) {
368
- return false ;
369
- }
370
-
371
368
// validate success, save value to safeData
372
- $ this ->collectSafeValue ($ attr , $ value );
369
+ if (call_user_func_array ($ callback , $ args )) {
370
+ $ this ->collectSafeValue ($ attr , $ value );
373
371
374
- return true ;
372
+ return true ;
373
+ }
374
+
375
+ return false ;
375
376
}
376
377
377
378
/**
@@ -456,6 +457,11 @@ protected function collectRules()
456
457
// return $this->_availableRules;
457
458
}
458
459
460
+ /**
461
+ * collect Safe Value
462
+ * @param string $attr
463
+ * @param mixed $value
464
+ */
459
465
protected function collectSafeValue ($ attr , $ value )
460
466
{
461
467
// 进行的是子级属性检查 eg: 'goods.apple'
@@ -720,6 +726,7 @@ public function lastError($onlyMsg = true)
720
726
'num ' => '{attr} must be an integer greater than 0! ' ,
721
727
'number ' => '{attr} must be an integer greater than 0! ' ,
722
728
'bool ' => '{attr} must be is boolean! ' ,
729
+ 'boolean ' => '{attr} must be is boolean! ' ,
723
730
'float ' => '{attr} must be is float! ' ,
724
731
'url ' => '{attr} is not a url address! ' ,
725
732
'email ' => '{attr} is not a email address! ' ,
@@ -741,6 +748,10 @@ public function lastError($onlyMsg = true)
741
748
'compare ' => '{attr} must be equals to {value0} ' ,
742
749
'same ' => '{attr} must be equals to {value0} ' ,
743
750
'isArray ' => '{attr} must be an array ' ,
751
+ 'isMap ' => '{attr} must be an array and is key-value format ' ,
752
+ 'isList ' => '{attr} must be an array of nature ' ,
753
+ 'intList ' => '{attr} must be an array and value is all integers ' ,
754
+ 'strList ' => '{attr} must be an array and value is all strings ' ,
744
755
'json ' => '{attr} must be an json string ' ,
745
756
'callback ' => '{attr} don \'t pass the test and verify! ' ,
746
757
'_ ' => '{attr} validation is not through! ' ,
0 commit comments