Implement an error object
Created by: tflori
Currently the validators need to build error with defined keys that are not guessable by the IDE. The validators can build it with self::buildError()
or \Verja\Validator::buildError
but it would be more nice if they can just use the constructor of \Verja\Error
.
Example:
$validator = new Validator\Callback(function ($value) use ($em) {
return $em->fetch(User::class)->where('username', $value)->count() ?
new Error('USERNAME_TAKEN', $value, 'value should be unique in user.username') : true;
});