@@ -218,14 +218,14 @@ public function validate(array $onlyChecked = [], $stopOnError = null)
218218 foreach ($ attrs as $ attr ) {
219219 $ value = $ this ->getValue ($ attr );
220220
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 )) {
224223 continue ;
225224 }
226225
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 ;
229229 continue ;
230230 }
231231
@@ -300,22 +300,23 @@ protected function requiredValidate($attr, $value, $validator, $args)
300300 $ result = $ this ->required ($ attr );
301301
302302 // 其他 required* 方法
303- } else {
303+ } elseif ( method_exists ( $ this , $ validator )) {
304304 // 压入当前属性/字段名
305305 array_unshift ($ args , $ attr );
306306
307307 $ 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! " );
313310 }
314311
315312 // validate success, save value to safeData
316- $ this ->collectSafeValue ($ attr , $ value );
313+ if ($ result ) {
314+ $ this ->collectSafeValue ($ attr , $ value );
317315
318- return true ;
316+ return true ;
317+ }
318+
319+ return false ;
319320 }
320321
321322 /**
@@ -364,14 +365,14 @@ protected function doValidate($data, $attr, $value, $validator, $args)
364365 throw new \InvalidArgumentException ('Validator type is error, must is String or Closure! ' );
365366 }
366367
367- if (!call_user_func_array ($ callback , $ args )) {
368- return false ;
369- }
370-
371368 // validate success, save value to safeData
372- $ this ->collectSafeValue ($ attr , $ value );
369+ if (call_user_func_array ($ callback , $ args )) {
370+ $ this ->collectSafeValue ($ attr , $ value );
373371
374- return true ;
372+ return true ;
373+ }
374+
375+ return false ;
375376 }
376377
377378 /**
@@ -456,6 +457,11 @@ protected function collectRules()
456457 // return $this->_availableRules;
457458 }
458459
460+ /**
461+ * collect Safe Value
462+ * @param string $attr
463+ * @param mixed $value
464+ */
459465 protected function collectSafeValue ($ attr , $ value )
460466 {
461467 // 进行的是子级属性检查 eg: 'goods.apple'
@@ -720,6 +726,7 @@ public function lastError($onlyMsg = true)
720726 'num ' => '{attr} must be an integer greater than 0! ' ,
721727 'number ' => '{attr} must be an integer greater than 0! ' ,
722728 'bool ' => '{attr} must be is boolean! ' ,
729+ 'boolean ' => '{attr} must be is boolean! ' ,
723730 'float ' => '{attr} must be is float! ' ,
724731 'url ' => '{attr} is not a url address! ' ,
725732 'email ' => '{attr} is not a email address! ' ,
@@ -741,6 +748,10 @@ public function lastError($onlyMsg = true)
741748 'compare ' => '{attr} must be equals to {value0} ' ,
742749 'same ' => '{attr} must be equals to {value0} ' ,
743750 '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 ' ,
744755 'json ' => '{attr} must be an json string ' ,
745756 'callback ' => '{attr} don \'t pass the test and verify! ' ,
746757 '_ ' => '{attr} validation is not through! ' ,
0 commit comments