Skip to content

kot13/orthodox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Orthodox

Простой валидатор без зависимостей

Пример использования

Имеем такой набор данных:

$data = [
    'username' => 'demo',
    'email' => '[email protected]',
    'age' => 29,
    'parents' => [
        'mother' => [
            'fullName' => 'Mother',
            'age' => 'Forty',
        ],
        'father' => [
            'fullName' => ''
        ],
    ],
];

И такие правила валидации:

$rules = [
    'username'                  => 'required',
    'email'                     => 'required|email',
    'age'                       => 'number',
    'parents.mother.fullName'   => 'required',
    'parents.mother.age'        => 'number',
    'parents.father.fullName'   => 'required',
];

Вот так можно отвалидировать набор данных:

$o = new Orthodox;
$o->validate($data, $rules);

Проверить валидность:

if ($o->passes()) {
    echo "Passed!\n\r";
} else {
    echo "Not passed!\n\r";
    print_r($o->errors());
    echo "\n\r";
}

и получить массив ошибок

Array
(
    [parents.mother.age] => Array
        (
            [0] => Value must be a number.
        )

    [parents.father.fullName] => Array
        (
            [0] => Value is required.
        )

)

About

Easy PHP validator

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages