DavidePastore / Slim-Validation

A validation library for the Slim Framework. It internally uses Respect/Validation.
170 stars 30 forks source link

Optional validation and assert #76

Open tiborasandor opened 1 year ago

tiborasandor commented 1 year ago

The exception does not work in this form. Is there a solution for this?

try {
    $validator = new Rules\Optional(new Rules\Digit());
    $validator->assert($data);
    return null;
} catch(NestedValidationException $e) {
    return current($e->getMessages([
        'digit'  => 'error message',
    ]));
}