Skip to content

Commit

Permalink
防止@required验证规则被覆盖
Browse files Browse the repository at this point in the history
一个字段添加多个验证规则的情况下@required如果不是最后一个,required会被覆盖为false
  • Loading branch information
wvfeng authored Mar 19, 2020
1 parent a043389 commit d3f5dd2
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/validator/src/ValidatorRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ public static function registerValidatorItem(string $className, string $property
throw new ValidatorException(sprintf('Only one `@XxxType` can be defined(propterty=%s)!', $propertyName));
}

self::$validators[$validateName]['properties'][$propertyName]['required'] = false;
if(!isset(self::$validators[$validateName]['properties'][$propertyName]['required'])) {
self::$validators[$validateName]['properties'][$propertyName]['required'] = false;
}

if ($objAnnotation instanceof Required) {
self::$validators[$validateName]['properties'][$propertyName]['required'] = true;
Expand Down

0 comments on commit d3f5dd2

Please sign in to comment.