lphkxd / hyperf-validate Goto Github PK
View Code? Open in Web Editor NEWhyperf-validate 支持request 和方法场景验证,兼容tp5写法 支持控制器注解验证、方法注解验证
hyperf-validate 支持request 和方法场景验证,兼容tp5写法 支持控制器注解验证、方法注解验证
目前只支持注解验证吗,还能不能在控制器里面直接调用验证方法,用于捕获异常
PHP Parse error: syntax error, unexpected 'string' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /home/hyperf/vendor/mzh/hyperf-validate/src/Annotations/RequestValidation.php on line 18。
环境 "hyperf/guzzle": "~1.1.0",
"php": ">=7.2",
"ext-swoole": ">=4.4",
use Mzh\Validate\Annotations\RequestValidation;
/**
* @AutoController()
*/
class User extends AbstractController
{
/**
* @RequestValidation(mode="User",scene="login",filter=true,throw=true)
*/
public function login(RequestInterface $request,Jwt $jwt)
{
$username = $request->input('username');
$password = $request->input('password');
$systemUser = SystemUser::query()->where("username",$username)->first();
if (!$systemUser){
return ApiOutput::fail("帐号不存在");
}
if (crypt($password) == $systemUser->password) {
$userData = [
'uid' => $systemUser->id,
'username' => $systemUser->username,
];
$token = (string)$jwt->getToken($userData);
$info = [
"token" => $token,
"ttl" => 7200
];
return ApiOutput::success($info);
}else{
return ApiOutput::fail("密码错误");
}
return ApiOutput::fail("登陆失败");
}
}
请问hyperf升级2.2版本之后,这个包怎么做对应升级呢
`<?php
declare(strict_types=1);
namespace App\Validate;
use Mzh\Validate\Validate\Validate;
class AuthValidation extends Validate
{
protected $rule = [
'device' => 'require|length:32',
'platform' => 'require|lower|in:android,ios',
'system' => 'require',
'version' => 'require|number|length:5',
];
protected $field = [
'version' => 'APP版本',
];
protected $scene = [
'guest' => ['device', 'platform', 'system', 'version'],
];
}`
/**
* 游客访问
* @RequestMapping(path="guest", methods="POST")
* @RequestValidation(mode="Auth",scene="guest",filter=true,throw=true)
*/
public function guest()
{
}
传递错误的数据进去,依然通过校验,使用scene不能直接使用rule的规则么?必须scene里面每个字段都要独立定义规则,这样好麻烦咦
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.