Support to rewrite the rules for scene when using validation. #7469
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
例如使用validation功能的以下场景时:
之前版本是会报错。如果删除$scenes["detail"]["phone"]的赋值后,会正常使用,但是场景只能引用下面定义的phone规则。
有时会遇到,A接口和B接口都需要用phone,但是A接口phone是必填,B接口phone是非必填,但是如果填写的话就需要走phone的规则。 如果用其他方式实现会比较复杂,例如创建一个新的验证器,那么message和attributes的方法都要复制过去。再或者写很多方法去进行手动验证,这样极不方便解耦和提高效率。
所以如果在scenes中可以直接将场景的使用的参数进行覆盖就可以大大减少很多工作量。