@@ -214,12 +214,8 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
214214
215215 // required* 系列字段检查器 || 文件资源检查
216216 if (\is_string ($ validator ) && (self ::isCheckRequired ($ validator ) || self ::isCheckFile ($ validator ))) {
217- if (!$ this ->fieldValidate ($ field , $ value , $ validator , $ args )) {
218- $ this ->addError ($ field , $ this ->getMessage ($ validator , $ field , $ args , $ defMsg ));
219-
220- if ($ this ->isStopOnError ()) {
221- break ;
222- }
217+ if (!$ this ->fieldValidate ($ field , $ value , $ validator , $ args , $ defMsg ) && $ this ->isStopOnError ()) {
218+ break ;
223219 }
224220
225221 continue ;
@@ -237,12 +233,8 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
237233 }
238234
239235 // 字段值验证检查
240- if (!$ this ->valueValidate ($ field , $ value , $ validator , $ args )) {
241- $ this ->addError ($ field , $ this ->getMessage ($ validator , $ field , $ args , $ defMsg ));
242-
243- if ($ this ->isStopOnError ()) {
244- break ;
245- }
236+ if (!$ this ->valueValidate ($ field , $ value , $ validator , $ args , $ defMsg ) && $ this ->isStopOnError ()) {
237+ break ;
246238 }
247239 }
248240
@@ -276,10 +268,11 @@ public function validate(array $onlyChecked = null, $stopOnError = null)
276268 * @param mixed $value 属性值
277269 * @param string $validator required* 验证器
278270 * @param array $args 验证需要的参数
271+ * @param string $defMsg
279272 * @return bool
280273 * @throws \InvalidArgumentException
281274 */
282- protected function fieldValidate (string $ field , $ value , string $ validator , array $ args )
275+ protected function fieldValidate (string $ field , $ value , string $ validator , array $ args, $ defMsg )
283276 {
284277 // required 检查
285278 if ($ validator === 'required ' ) {
@@ -305,6 +298,8 @@ protected function fieldValidate(string $field, $value, string $validator, array
305298 return true ;
306299 }
307300
301+ $ this ->addError ($ field , $ this ->getMessage ($ validator , $ field , $ args , $ defMsg ));
302+
308303 return false ;
309304 }
310305
@@ -314,10 +309,10 @@ protected function fieldValidate(string $field, $value, string $validator, array
314309 * @param mixed $value 属性值
315310 * @param \Closure|string $validator 验证器
316311 * @param array $args 验证需要的参数
312+ * @param string $defMsg
317313 * @return bool
318- * @throws \InvalidArgumentException
319314 */
320- protected function valueValidate (string $ field , $ value , $ validator , array $ args )
315+ protected function valueValidate (string $ field , $ value , $ validator , array $ args, $ defMsg )
321316 {
322317 // if field don't exists.
323318 if (null === $ value ) {
@@ -340,7 +335,6 @@ protected function valueValidate(string $field, $value, $validator, array $args)
340335 } elseif (method_exists ($ this , $ method = $ validator . 'Validator ' )) {
341336 $ passed = $ this ->$ method ($ value , ...$ args );
342337
343- // $validator is a method of the class 'ValidatorList'
344338 } elseif (method_exists (ValidatorList::class, $ validator )) {
345339 $ passed = ValidatorList::$ validator ($ value , ...$ args );
346340
@@ -352,7 +346,6 @@ protected function valueValidate(string $field, $value, $validator, array $args)
352346 }
353347 } else {
354348 $ passed = Helper::call ($ validator , $ value , ...$ args );
355- // throw new \InvalidArgumentException('Validator type is error, must is String or Closure!');
356349 }
357350
358351 // validate success, save value to safeData
@@ -362,6 +355,8 @@ protected function valueValidate(string $field, $value, $validator, array $args)
362355 return true ;
363356 }
364357
358+ $ this ->addError ($ field , $ this ->getMessage ($ validator , $ field , $ args , $ defMsg ));
359+
365360 return false ;
366361 }
367362
@@ -482,13 +477,32 @@ protected function prepareRule(array &$rule)
482477 ******************************************************************************/
483478
484479 /**
485- * @param string $path 'users.*.id'
480+ * @param string $path 'users.*.id' 'goods.*' 'foo.bar.*.id'
481+ * @param null|mixed $default
486482 * @return mixed
487483 */
488- protected function getByWildcard (string $ path )
484+ protected function getByWildcard (string $ path, $ default = null )
489485 {
486+ list ($ first , $ last ) = explode ('.* ' , $ path , 2 );
487+ $ recently = Helper::getValueOfArray ($ this ->data , $ first , $ default );
488+
489+ // 'goods.*'
490+ if ('' === $ last ) {
491+ return $ recently ;
492+ }
493+
494+ if (!$ recently || !\is_array ($ recently )) {
495+ return $ default ;
496+ }
497+
498+ $ last = trim ($ last , '. ' );
490499 $ result = [];
491500
501+ foreach ($ recently as $ item ) {
502+ $ result [] = $ item [$ last ];
503+ }
504+
505+ return $ result ;
492506 }
493507
494508 /**
0 commit comments