@@ -200,13 +200,14 @@ public function validate(array $onlyChecked = [], $hasErrorStop=false)
200200 foreach ($ attrs as $ attr ) {
201201 // 不在需要检查的列表内 || $skipOnEmpty is true && ValidatorList::isEmpty($data,$attr)
202202 if (
203- ($ onlyChecked && !in_array ($ attr , $ onlyChecked )) ||
203+ ($ onlyChecked && !in_array ($ attr , $ onlyChecked, true )) ||
204204 ( $ validator !== 'required ' && $ skipOnEmpty && call_user_func ($ isEmpty , $ data , $ attr ))
205205 ) {
206206 continue ;
207+ }
207208
208209 // mark attribute is safe. not need validate. like. 'created_at'
209- } elseif ( $ validator === 'safe ' ) {
210+ if ( $ validator === 'safe ' ) {
210211 $ this ->_safeData [$ attr ] = $ data [$ attr ];
211212 continue ;
212213 }
@@ -292,7 +293,7 @@ protected function doValidate($data, $attr, $validator, $args)
292293 throw new \InvalidArgumentException ("validator [ $ validator] don't exists! " );
293294 }
294295 } else {
295- throw new \InvalidArgumentException (" validator format is error, must is String or Closure !" );
296+ throw new \InvalidArgumentException (' Validator format is error, must is String or Closure !' );
296297 }
297298
298299 $ result = call_user_func_array ($ callback , $ args );
@@ -358,7 +359,7 @@ protected function collectRules()
358359
359360 // check validator
360361 if ( !is_string ($ rule [1 ]) && !($ rule [1 ] instanceof \Closure) ) {
361- throw new \InvalidArgumentException (" validator setting error!" );
362+ throw new \InvalidArgumentException (' Validator rule setting error!' );
362363 }
363364
364365 if ( empty ($ rule ['on ' ]) ) {
@@ -367,7 +368,7 @@ protected function collectRules()
367368 $ ruleScene = $ rule ['on ' ];
368369 $ ruleScene = is_string ($ ruleScene ) ? array_map ('trim ' ,explode (', ' , $ ruleScene )) : (array )$ ruleScene ;
369370
370- if ( in_array ($ scene ,$ ruleScene) ) {
371+ if (in_array ($ scene , $ ruleScene, true ) ) {
371372 unset($ rule ['on ' ]);
372373 $ availableRules [] = $ rule ;
373374 }
@@ -414,7 +415,6 @@ public function fail()
414415 /**
415416 * @param $attr
416417 * @param $msg
417- * @return mixed
418418 */
419419 public function addError ($ attr , $ msg )
420420 {
@@ -433,7 +433,7 @@ public function getErrors()
433433 * @param bool $onlyMsg
434434 * @return array|string
435435 */
436- public function firstError ($ onlyMsg= true )
436+ public function firstError ($ onlyMsg = true )
437437 {
438438 $ e = $ this ->_errors ;
439439 $ first = array_shift ($ e );
@@ -448,7 +448,7 @@ public function firstError($onlyMsg=true)
448448 * @param bool $onlyMsg
449449 * @return array|string
450450 */
451- public function lastError ($ onlyMsg= true )
451+ public function lastError ($ onlyMsg = true )
452452 {
453453 $ e = $ this ->_errors ;
454454 $ last = array_pop ($ e );
@@ -469,18 +469,22 @@ public function lastError($onlyMsg=true)
469469 'url ' => '{attr} not is url address! ' ,
470470 'email ' => '{attr} not is email address! ' ,
471471 'ip ' => '{attr} not is ip address! ' ,
472- 'required ' => '{attr} is not block ! ' ,
472+ 'required ' => 'parameter {attr} is required ! ' ,
473473 'length ' => '{attr} length must at rang {min} ~ {max} ' ,
474474 'size ' => '{attr} must be an integer and at rang {min} ~ {max} ' ,
475475 'min ' => '{attr} minimum boundary is {value} ' ,
476476 'max ' => '{attr} maximum boundary is {value} ' ,
477477 'in ' => '{attr} must in ({value}) ' ,
478478 'string ' => '{attr} must be a string ' ,
479+ 'compare ' => '{attr} must be equals to {compare} ' ,
479480 'isArray ' => '{attr} must be an array ' ,
480481 'callback ' => 'The custom callback validation fails of the [{attr}]! ' ,
481482 '_ ' => '{attr} validation is not through! ' ,
482483 ];
483484
485+ /**
486+ * @return array
487+ */
484488 public function getMessages ()
485489 {
486490 return array_merge (self ::$ _defaultMessages , $ this ->messages ());
@@ -496,7 +500,7 @@ public function getMessages()
496500 * @param string $msg 提示消息
497501 * @return string
498502 */
499- public function getMessage ($ name , array $ params , $ rule = [], $ msg =null )
503+ public function getMessage ($ name , array $ params , array $ rule = [], $ msg =null )
500504 {
501505 if ( !$ msg ) {
502506 $ msgList = $ this ->getMessages ();
0 commit comments