[Validator] Added @validation:GroupSequence to annotation driver
This commit is contained in:
parent
6176063b30
commit
a71cad480a
@ -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'];
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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));
|
||||
|
Reference in New Issue
Block a user