From 63adb97cf2f18f64f150fc3d5f458b5a86ba041b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 22 Jan 2012 16:50:02 +0100 Subject: [PATCH] Revert "merged branch blogsh/dynamic_constraints (PR #3114)" This reverts commit 6b9a355fb0d39c92180265e589bd2890afc50706, reversing changes made to 811ead8589fe0d310657161df6afe373873a4f39. --- .../Validator/ConstraintProviderInterface.php | 27 --------------- src/Symfony/Component/Validator/Validator.php | 8 ----- .../Fixtures/DynamicConstraintsEntity.php | 30 ---------------- .../Component/Validator/ValidatorTest.php | 34 ------------------- 4 files changed, 99 deletions(-) delete mode 100644 src/Symfony/Component/Validator/ConstraintProviderInterface.php delete mode 100644 tests/Symfony/Tests/Component/Validator/Fixtures/DynamicConstraintsEntity.php diff --git a/src/Symfony/Component/Validator/ConstraintProviderInterface.php b/src/Symfony/Component/Validator/ConstraintProviderInterface.php deleted file mode 100644 index c081d3ad13..0000000000 --- a/src/Symfony/Component/Validator/ConstraintProviderInterface.php +++ /dev/null @@ -1,27 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Component\Validator; - -use Symfony\Component\Validator\Mapping\ClassMetadata; - -/** - * Makes it possible to define dynamic constraints for an object. - */ -interface ConstraintProviderInterface -{ - /** - * Lets the user create dynamic constraints - * - * @param Mapping\ClassMetadata - */ - function loadDynamicValidatorMetadata(ClassMetadata $metadata); -} diff --git a/src/Symfony/Component/Validator/Validator.php b/src/Symfony/Component/Validator/Validator.php index 2327aa1c0b..d20a623256 100644 --- a/src/Symfony/Component/Validator/Validator.php +++ b/src/Symfony/Component/Validator/Validator.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Validator; use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface; -use Symfony\Component\Validator\Mapping\ClassMetadata; /** * The default implementation of the ValidatorInterface. @@ -58,13 +57,6 @@ class Validator implements ValidatorInterface public function validate($object, $groups = null) { $metadata = $this->metadataFactory->getClassMetadata(get_class($object)); - - if ($object instanceof ConstraintProviderInterface) { - $dynamicMetadata = new ClassMetadata(get_class($object)); - $dynamicMetadata->mergeConstraints($metadata); - $object->loadDynamicValidatorMetadata($dynamicMetadata); - $metadata = $dynamicMetadata; - } $walk = function(GraphWalker $walker, $group) use ($metadata, $object) { return $walker->walkObject($metadata, $object, $group, ''); diff --git a/tests/Symfony/Tests/Component/Validator/Fixtures/DynamicConstraintsEntity.php b/tests/Symfony/Tests/Component/Validator/Fixtures/DynamicConstraintsEntity.php deleted file mode 100644 index 41bfe44d39..0000000000 --- a/tests/Symfony/Tests/Component/Validator/Fixtures/DynamicConstraintsEntity.php +++ /dev/null @@ -1,30 +0,0 @@ -validationEnabled = $enabled; - } - - public function getSecondValue() - { - return null; - } - - public function loadDynamicValidatorMetadata(ClassMetadata $metadata) - { - if ($this->validationEnabled) { - $metadata->addPropertyConstraint('firstValue', new FailingConstraint()); - $metadata->addGetterConstraint('secondValue', new FailingConstraint()); - } - } -} diff --git a/tests/Symfony/Tests/Component/Validator/ValidatorTest.php b/tests/Symfony/Tests/Component/Validator/ValidatorTest.php index 38af8e31ba..86c8ee98a6 100644 --- a/tests/Symfony/Tests/Component/Validator/ValidatorTest.php +++ b/tests/Symfony/Tests/Component/Validator/ValidatorTest.php @@ -15,12 +15,10 @@ require_once __DIR__.'/Fixtures/Entity.php'; require_once __DIR__.'/Fixtures/FailingConstraint.php'; require_once __DIR__.'/Fixtures/FailingConstraintValidator.php'; require_once __DIR__.'/Fixtures/FakeClassMetadataFactory.php'; -require_once __DIR__.'/Fixtures/DynamicConstraintsEntity.php'; use Symfony\Tests\Component\Validator\Fixtures\Entity; use Symfony\Tests\Component\Validator\Fixtures\FakeClassMetadataFactory; use Symfony\Tests\Component\Validator\Fixtures\FailingConstraint; -use Symfony\Tests\Component\Validator\Fixtures\DynamicConstraintsEntity; use Symfony\Component\Validator\Validator; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationList; @@ -123,38 +121,6 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase $this->assertEquals($violations, $result); } - - public function testValidate_constraintProvider() - { - $entity = new DynamicConstraintsEntity(); - $metadata = new ClassMetadata(get_class($entity)); - $this->factory->addClassMetadata($metadata); - - $entity->setValidation(true); - - $violations = new ConstraintViolationList(); - $violations->add(new ConstraintViolation( - '', - array(), - $entity, - 'firstValue', - '' - )); - $violations->add(new ConstraintViolation( - '', - array(), - $entity, - 'secondValue', - '' - )); - - $this->assertEquals($violations, $this->validator->validate($entity)); - - $entity->setValidation(false); - - $violations = new ConstraintViolationList(); - $this->assertEquals($violations, $this->validator->validate($entity)); - } public function testValidateProperty() {