Php Respect\Validation 库异常显示错误但验证方法 returns true

Php Respect\Validation libary exceptions shows errors but validate method returns true

我使用 https://github.com/Respect/Validation 进行验证。包装看起来非常好,所以现在我想尝试一下。我想向(解码的)jtw 令牌添加一些验证规则,这是一个 php 对象。并且验证方法有效。

现在我想添加错误消息,但那些似乎不起作用?

public function validateJwt($request, $response)
{


    $validator = v::objectType()->attribute('data');
    $validator->validate($this->jwt);
    var_dump($validator->validate($this->jwt)); // <-- this returns true

    try {
        $validator->assert('JWT');
    } catch(NestedValidationException $exception) {
        print_r($exception->getMessages());
        /*

        Array
        (
            [0] => "JWT" must be an object
            [1] => Attribute data must be present
        )

         */
    }
}

为什么我会收到这些消息,因为在验证方法中,它 returns 正确..

您很可能需要将令牌而不是字符串传递给验证器 JWT

$validator->assert($this->jwt);