Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dongasai opened this issue Jul 27, 2020 · 3 comments
Open

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

dongasai opened this issue Jul 27, 2020 · 3 comments
Labels

Comments

@dongasai
Copy link
Contributor

dongasai commented Jul 27, 2020

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

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

// required*系列字段检查 || 文件资源检查
if (self::isCheckRequired($validator) || self::isCheckFile($validator)) {
$result = $this->fieldValidate($field, $value, $validator, $args, $defMsg);
if (false === $result && $stopOnError) {
break;
}
continue;
}

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

@inhere
Copy link
Owner

inhere commented Jul 28, 2020

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

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

@dongasai
Copy link
Contributor Author

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

@inhere
Copy link
Owner

inhere commented Jul 28, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants