divineomega/omega-validator

Omega Validator

Fund package maintenance!
DivineOmega

v1.2.0 2020-01-27 09:59 UTC

This package is auto-updated.

Last update: 2024-11-27 21:27:02 UTC


README

Installation

To install Omega Validator, just run the following Composer command.

composer require divineomega/omega-validator

Usage

See the following example usage.

use DivineOmega\OmegaValidator\Rules\IsEmail;
use DivineOmega\OmegaValidator\Rules\IsString;
use DivineOmega\OmegaValidator\Rules\Required;
use DivineOmega\OmegaValidator\Translator;
use DivineOmega\OmegaValidator\Validator;

/* ... */

$validator = new Validator([
    'email' => '',
], [
    'email' => [
        new Required(),
        new IsEmail(),
        new IsString(),
    ],
]);

if ($validator->fails()) {

    // English messages
    var_dump($validator->messages());
    
    // array(1) {
    //  ["email"]=>
    //  array(2) {
    //    ["DivineOmega\OmegaValidator\Rules\Required"]=>
    //    string(22) "The email is required."
    //    ["DivineOmega\OmegaValidator\Rules\IsEmail"]=>
    //    string(40) "The email must be a valid email address."
    //  }
    // }

    // German messages
    var_dump($validator->messages(new Translator('de')));

    // Polish messages
    var_dump($validator->messages(new Translator('pl')));

    // etc...
}