rioter / validation
Installs: 26
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:framework-component
Requires
- php: >=5.5
- egulias/email-validator: ~1.2
Requires (Dev)
- phpunit/phpunit: >=4.8
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
- IsBool
- IsFloat
- IsInteger
- IsNumeric
- MinLength
- MaxLength
- Length
- MinNumber
- MaxNumber
- NumRange
- Positive
- Negative
- NotEmpty
- Equal
- NotEqual
- Matches
- Regexp