[Validator] Added @validation:GroupSequence to annotation driver

This commit is contained in:
Bernhard Schussek 2010-11-18 23:05:14 +01:00 committed by Fabien Potencier
parent 6176063b30
commit a71cad480a
4 changed files with 37 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace Symfony\Component\Validator\Constraints;
/*
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* Annotation for group sequences
*
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
*/
class GroupSequence
{
/**
* The members of the sequence
* @var array
*/
public $groups;
public function __construct(array $groups)
{
$this->groups = $groups['value'];
}
}

View File

@ -15,6 +15,7 @@ use Symfony\Component\Validator\Exception\MappingException;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\Validator\Constraints\Validation;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraint;
class AnnotationLoader implements LoaderInterface
@ -49,6 +50,8 @@ class AnnotationLoader implements LoaderInterface
foreach ($constraint->constraints as $constraint) {
$metadata->addConstraint($constraint);
}
} elseif ($constraint instanceof GroupSequence) {
$metadata->setGroupSequence($constraint->groups);
} elseif ($constraint instanceof Constraint) {
$metadata->addConstraint($constraint);
}

View File

@ -18,6 +18,7 @@ require_once __DIR__.'/EntityInterface.php';
* "foo" = {@validation:NotNull, @validation:Min(3)},
* "bar" = @validation:Min(5)
* })
* @validation:GroupSequence({"Foo", "Entity"})
*/
class Entity extends EntityParent implements EntityInterface
{

View File

@ -47,6 +47,7 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
$loader->loadClassMetadata($metadata);
$expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
$expected->setGroupSequence(array('Foo', 'Entity'));
$expected->addConstraint(new NotNull());
$expected->addConstraint(new ConstraintA());
$expected->addConstraint(new Min(3));
@ -111,6 +112,7 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
$expected = new ClassMetadata('Symfony\Tests\Component\Validator\Fixtures\Entity');
$expected->mergeConstraints($expected_parent);
$expected->setGroupSequence(array('Foo', 'Entity'));
$expected->addConstraint(new NotNull());
$expected->addConstraint(new ConstraintA());
$expected->addConstraint(new Min(3));