kekrozsak/vendor/symfony/symfony/src/Symfony/Component/Validator
Polonkai Gergely 9d0d2ce524 Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
..
Constraints Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
Exception Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
Mapping Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
Resources/translations Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
Tests Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
.gitignore Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
CHANGELOG.md Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
Constraint.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
ConstraintValidator.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
ConstraintValidatorFactory.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
ConstraintValidatorFactoryInterface.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ConstraintValidatorInterface.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ConstraintViolation.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
ConstraintViolationList.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ExecutionContext.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
GlobalExecutionContext.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
GraphWalker.php Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
GroupSequenceProviderInterface.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
LICENSE Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
ObjectInitializerInterface.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
README.md Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
Validator.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ValidatorContext.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ValidatorContextInterface.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ValidatorFactory.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
ValidatorInterface.php Updated to Symfony 2.1 BETA3 2012-07-16 21:40:19 +02:00
composer.json Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00
phpunit.xml.dist Initial commit with Symfony 2.1+Vendors 2012-07-01 09:52:20 +02:00

README.md

Validator Component

This component is based on the JSR-303 Bean Validation specification and enables specifying validation rules for classes using XML, YAML or annotations, which can then be checked against instances of these classes.

use Symfony\Component\Validator\Validator;
use Symfony\Component\Validator\Mapping\ClassMetadataFactory;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ConstraintValidatorFactory;

$validator = new Validator(
    new ClassMetadataFactory(new StaticMethodLoader()),
    new ConstraintValidatorFactory()
);

$constraint = new Assert\Collection(array(
    'name' => new Assert\Collection(array(
        'first_name' => new Assert\MinLength(101),
        'last_name'  => new Assert\MinLength(1),
    )),
    'email'    => new Assert\Email(),
    'simple'   => new Assert\MinLength(102),
    'gender'   => new Assert\Choice(array(3, 4)),
    'file'     => new Assert\File(),
    'password' => new Assert\MinLength(60),
));

$violations = $validator->validateValue($input, $constraint);

Resources

Silex integration:

https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/ValidatorServiceProvider.php

Documentation:

http://symfony.com/doc/2.0/book/validation.html

JSR-303 Specification:

http://jcp.org/en/jsr/detail?id=303

You can run the unit tests with the following command:

phpunit

If you also want to run the unit tests that depend on other Symfony Components, install dev dependencies before running PHPUnit:

php composer.phar install --dev