rioter/validation

There is no license information available for the latest version (v2.0.0) of this package.

Installs: 26

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:framework-component

v2.0.0 2016-02-16 11:07 UTC

This package is not auto-updated.

Last update: 2024-11-01 18:34:58 UTC


README

ITCourses framework validation component

Installation

Package is available on Packagist, you can install it using Composer.

composer require rioter/validation

PHP 5.5+

Basic Usage

Use namespaces

use Rioter\Validation\Validator;
use Rioter\Validation\Rules;

Create object of Validator class

$v = new Validator();

For example you have $_POST data

$_POST = ['id'=>'12', 'name' => ' Alexandr'];

Add aliases

$v
    ->setAlias('name', 'Username')
    ->setAlias('id', 'Id пользователя')
;

Php standart functions

$v
    ->addFunc('name', 'trim')
;

Add rules

$v
    ->addRule('id', new Rules\IsNumeric())
    ->addRule('id', new Rules\IsBool())
    ->addRule('name', new Rules\MaxLength(4))
;

isValid return true if validation is passed and return false if validation is not passed

$v->isValid($_POST);

You can get array of errors

$v->getErrors();

Output:

Array
(
  [id] => 
    Array
    (
      [0] => 'Id пользователя должно быть булевым значением'
    ) 
  [name] => 
    Array
    (
      [0] => 'Username должен быть не более 4 символов'
    )
)

Rules

  • NotEmpty
  • Date
  • Email
  • IsBool
  • IsFloat
  • IsInteger
  • IsNumeric
  • MinLength
  • MaxLength
  • Length
  • MinNumber
  • MaxNumber
  • NumRange
  • Positive
  • Negative
  • NotEmpty
  • Equal
  • NotEqual
  • Matches
  • Regexp