Revert "merged branch blogsh/dynamic_constraints (PR #3114)"
This reverts commit6b9a355fb0
, reversing changes made to811ead8589
.
This commit is contained in:
parent
53b3c8304f
commit
63adb97cf2
@ -1,27 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* 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);
|
|
||||||
}
|
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Validator;
|
namespace Symfony\Component\Validator;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
|
use Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default implementation of the ValidatorInterface.
|
* The default implementation of the ValidatorInterface.
|
||||||
@ -58,13 +57,6 @@ class Validator implements ValidatorInterface
|
|||||||
public function validate($object, $groups = null)
|
public function validate($object, $groups = null)
|
||||||
{
|
{
|
||||||
$metadata = $this->metadataFactory->getClassMetadata(get_class($object));
|
$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) {
|
$walk = function(GraphWalker $walker, $group) use ($metadata, $object) {
|
||||||
return $walker->walkObject($metadata, $object, $group, '');
|
return $walker->walkObject($metadata, $object, $group, '');
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Symfony\Tests\Component\Validator\Fixtures;
|
|
||||||
|
|
||||||
use Symfony\Component\Validator\ConstraintProviderInterface;
|
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
|
||||||
|
|
||||||
class DynamicConstraintsEntity implements ConstraintProviderInterface
|
|
||||||
{
|
|
||||||
protected $validationEnabled = false;
|
|
||||||
protected $firstValue;
|
|
||||||
|
|
||||||
public function setValidation($enabled)
|
|
||||||
{
|
|
||||||
$this->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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,12 +15,10 @@ require_once __DIR__.'/Fixtures/Entity.php';
|
|||||||
require_once __DIR__.'/Fixtures/FailingConstraint.php';
|
require_once __DIR__.'/Fixtures/FailingConstraint.php';
|
||||||
require_once __DIR__.'/Fixtures/FailingConstraintValidator.php';
|
require_once __DIR__.'/Fixtures/FailingConstraintValidator.php';
|
||||||
require_once __DIR__.'/Fixtures/FakeClassMetadataFactory.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\Entity;
|
||||||
use Symfony\Tests\Component\Validator\Fixtures\FakeClassMetadataFactory;
|
use Symfony\Tests\Component\Validator\Fixtures\FakeClassMetadataFactory;
|
||||||
use Symfony\Tests\Component\Validator\Fixtures\FailingConstraint;
|
use Symfony\Tests\Component\Validator\Fixtures\FailingConstraint;
|
||||||
use Symfony\Tests\Component\Validator\Fixtures\DynamicConstraintsEntity;
|
|
||||||
use Symfony\Component\Validator\Validator;
|
use Symfony\Component\Validator\Validator;
|
||||||
use Symfony\Component\Validator\ConstraintViolation;
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
use Symfony\Component\Validator\ConstraintViolationList;
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
@ -123,38 +121,6 @@ class ValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals($violations, $result);
|
$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()
|
public function testValidateProperty()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user