swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 788 forks source link

swoft2.0.6声明验证器,验证类型一直通不过 #1108

Closed AridanJohn closed 4 years ago

AridanJohn commented 4 years ago
Q A
Bug report? yes
Feature request? yes
Swoft version 2.0.6
Swoole version 4.4.7
PHP version 7.2.22
Runtime environment Docker etc.

Describe the bug

参数id为int类型,采用声明验证器,@IsInt()一直提示声明message,换成@IsString()也是一样,字段参数都是不为null

参数:$uid,$touid,$p 都不为null,接口有传递参数

错误提示:参考图三,一直提示自定义的message信息,ValidateType也有引用,使用ValidateType::Body 和ValidateType::GET都是如下提示,无法通过类型验证

图4方式,提示错误: [ERROR] App\Exception\Handler\HttpExceptionHandler:handle(44) Argument 1 passed to Swoft\Validator\Helper\ValidatorHelper::validatelength() must be of the type string, integer given, called in /var/www/swoft/vendor/swoft/validator/src/Rule/LengthRule.php on line 38

Screenshots

image image image

image

AridanJohn commented 4 years ago

莫名又好了,声明验证,可以同时支持POST和GET方式吗? 但是IsInt类型,验证不了,只能换成IsString, 参数:数字取到的值全部都是string

2.0.6 type=ValidateType::GET 不需要用括号引起来

stelin commented 4 years ago

现在没有强制类型验证,后面可以考虑严格,新增一个严格模式 @JasonYH

AridanJohn commented 4 years ago

现在没有强制类型验证,后面可以考虑严格,新增一个严格模式 @JasonYH

mongodb ,elasticsearch扩展 啥时候会上?

JasonYHZ commented 4 years ago

莫名又好了,声明验证,可以同时支持POST和GET方式吗? 但是IsInt类型,验证不了,只能换成IsString, 参数:数字取到的值全部都是string

2.0.6 type=ValidateType::GET 不需要用括号引起来

@validator 注解中 type 选项其实就是确定你验证 get还是post ,ValidateType::xx 这个类只是个预定义的标志,当然你也可以完全不用这个,直接用双引号写 'get' 或者 'body' 也是可以的。 关于你说的 IsInt 类型,其核心验证机制是使用 filter_var($value, FILTER_VALIDATE_INT) 函数进行校验的,可以允许是字符串,只要是纯数字的字符串也是可以通过校验的。