ebidtech / validator
A validator on top of Symfony validator
Installs: 48 089
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 14
Forks: 1
Open Issues: 1
Requires
- php: >=5.3.3
- symfony/validator: >=2.2.0
Requires (Dev)
- phpmd/phpmd: ~1.5.0
- phpunit/phpunit: 3.7.*
- satooshi/php-coveralls: dev-master
- squizlabs/php_codesniffer: 1.5.*
This package is not auto-updated.
Last update: 2024-12-17 01:26:11 UTC
README
A validator on top of Symfony validator.
Why to use?
Using Symfony validator with annotations or configuration (yml or xml) is just fine, but for simple cases, eg: validation of argument methods and throw exception is too verbose.
Eg:
Symfony way
use Symfony\Component\Validator\Validation; use Symfony\Component\Validator\Constraints\Type; class Test { public function getByName($name) { $violations = Validation::createValidator()->validateValue( $name, new Type(array('type' => 'string')) ); if (count($violations) != 0) { throw new \InvalidArgumentException((string) $violations); } } }
EBTValidator way
use EBT\Validator\ValidatorBasicExtended; class Test { public function getByName($name) { if (!ValidatorBasicExtended::isTypeString($name)) { throw new \InvalidArgumentException(ValidatorBasicExtended::getViolationsAsShortString()); } } }
Requirements
- PHP >= 5.3.3
Installation
The recommended way to install is through composer.
Just create a composer.json
file for your project:
{ "require": { "ebidtech/validator": "@stable" } }
Tip: browse ebidtech/validator
page to choose a stable version to use, avoid the @stable
meta constraint.
And run these two commands to install it:
$ curl -sS https://getcomposer.org/installer | php
$ composer install
Now you can add the autoloader, and you will have access to the library:
<?php require 'vendor/autoload.php';
Usage
The validators are divided according to the Symfony Validator:
- ValidatorBasic
- ValidatorString
- ValidatorNumber
- ValidatorDate
- ValidatorCollection
For each one exists a Extended version (Eg: ValidatorBasicExtended), that adds convenience alias methods. It exists also a ValidatorExtended that mix validations.
Contributing
See CONTRIBUTING file.
Credits
- Ebidtech developer team, validator Lead developer Eduardo Oliveira (eduardo.oliveira@ebidtech.com).
- All contributors
License
Validator library is released under the MIT License. See the bundled LICENSE file for details.