0

im using https://github.com/Respect/Validation for validation. the package looked verry good so now i wanted to try it. I wanted to add some validation rules to a (decoded) jtw token, wich is a php object. and the validation method worked.

Now i wanted to add error messages but those do not seem to work?

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
        )

         */
    }
}

Why am I getting these messages because on the validate method, it returns true..

Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49
Reza
  • 880
  • 1
  • 10
  • 29

1 Answers1

0

You most likely need to pass the token to the validator and not a string JWT.

$validator->assert($this->jwt);
Mika Tuupola
  • 19,877
  • 5
  • 42
  • 49