Code Monkey home page Code Monkey logo

hyperf-validate's People

Contributors

great-zh avatar lphkxd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyperf-validate's Issues

在项目使用出现这个异常,看hyperf注解使用跟源码也没问题,不明原因,求救

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("登陆失败");
    }
}

场景验证器无效

`<?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里面每个字段都要独立定义规则,这样好麻烦咦

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.