S
S
SmilerOFF2017-04-09 16:10:01
PHP
SmilerOFF, 2017-04-09 16:10:01

How to convert LIVR validation rules to php?

I decided to try the validation libraries on the LIVR validation syntax livr-spec.org
The point is that the same rules should work both in the frontend and in the backend. I bribed the idea that once I set the rules in the syntax

{
    name: 'required',
    email: ['required', 'email'],
    gender: { one_of: ['male', 'female'] },
    phone: {max_length: 10},
    password: ['required', {min_length: 10} ],
    password2: { equal_to_field: 'password' }
}

And then the library for JS https://github.com/koorchik/js-validator-livr will do everything by itself (and it really does).
And the php library https://github.com/WebbyLab/php-validator-livr will deal with server-side validation (and it also works).
And I don’t know how to convert the source code of the validation rules to such that the PHP library understands. She needs to feed them like this:
$validator  = new Validator\LIVR( [
        'name'      =>  'required',
        'email'     =>  [ 'required', 'email'],
        'gender'    =>  [ 'one_of'     => ['male', 'female'] ],
        'phone'     =>  [ 'max_length' => 10 ],
        'password'  =>  [ 'required', ['min_length' => 10] ],
        'password2' =>  [ 'equal_to_field' => 'password' ]
    ] );

I thought it was json, but it doesn't seem to be.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SmilerOFF, 2017-04-09
@SmilerOFF

If anyone needs it in the future, then this is Json5.
You need to google the php library to work with json5.

A
Arekus, 2017-04-09
@Arekus

new Validator\LIVR(json_explode($livr_for_js, 1))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question