almendra / validators
A simple type validator.
dev-master
2016-10-07 16:22 UTC
Requires (Dev)
- phpunit/phpunit: 5.4.6
This package is not auto-updated.
Last update: 2025-03-05 21:29:11 UTC
README
Installation
Through composer:
composer require almendra/validators
How to use it
-
- Stand alone
$validator = new Validator();
$result = $validator
-> integer(10)
-> min(3)
-> max(20)
-> validate();
-
- Within a controller
# SomeController extends Http\Controller or implements Http\Interfaces\ControllerInterface
$controller = new SomeController;
$controller -> validate(function($request, $validator) {
$result = $validator
-> string($request -> get('name'))
-> min(3)
-> max(20)
-> validate();
return $result;
});
It can also be used with a type homogeneus array:
$validator = new Validator();
$result = $validator
-> string($request -> all())
-> range(1, 255)
-> validate();
Support
Currently, the validator supports the following types: integer, string, double, float, file