php-validate icon indicating copy to clipboard operation
php-validate copied to clipboard

为什么存在required验证的特殊分支?

Open dongasai opened this issue 5 years ago • 3 comments
trafficstars

https://github.com/inhere/php-validate/blob/master/src/ValidationTrait.php#L311

如上,safe的独立分支(标记安全的字段不需要其他验证),但是这个分支导致了 后续的after不可用

https://github.com/inhere/php-validate/blob/3749f60dffaaaeb288bf256d096af9bd41ddd975/src/ValidationTrait.php#L316-L323

如上required的分支是出于什么考虑?

dongasai avatar Jul 27 '20 13:07 dongasai

因为 required* 检查,字段都可能不存在。这一类型的检查都是先检查字段是否存在,再检查值是否有效

后续的其他验证器,都是直接检查值了。

inhere avatar Jul 28 '20 04:07 inhere

多个验证器能够按照顺序去检查的

dongasai avatar Jul 28 '20 05:07 dongasai

@dongasai :) 有兴趣的可以话可以clone 一个。调整下逻辑看看能不能跑通单元测试。我之前是发现有问题才这样分开的。

inhere avatar Jul 28 '20 09:07 inhere