memcrab/validator

Additional static layer for respect validator

1.0.4 2021-07-26 06:51 UTC

This package is auto-updated.

Last update: 2024-10-24 22:21:00 UTC


README

Install

composer require memcrab/validator

Dependencies

- psr/log: "^1.0"
- respect/validation: "^2.1"

Usage

use Memcrab\Validator\Validator;
use Respect\Validation\Validator as v;

class Auth extends Validator
{

    public function authorization()
    {
        $this
            ->addBodyRule('email', v::email(), 'Email not valid', 400101)
            ->addBodyRule('password', v::length(8, 100), 'Password should be more than 8 symbols', 400102);
    }
}
<?php declare (strict_types = 1);
require_once __DIR__ . "/vendor/autoload.php";

use Memcrab\Validator\Validator;
use Memcrab\Validator\ValidatorException;

try {
  
  // ... getting request GET($getParramethers) and POST($postParramethers)  ...
  
  $Validator = new Auth($getParramethers, $postParramethers);
  $Validator->authorization();
  $Validator->validate();
  
} catch (ValidatorException $error) {
  // handle validation error
}

MIT Licensed