[Validator] Fix access to root object when using composite constraint

This commit is contained in:
Gabriel Ostrolucký 2017-12-17 17:47:15 +01:00
parent 76b7cacdd3
commit b18cdcf417
2 changed files with 4 additions and 1 deletions

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Validator\Tests\Validator;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Expression;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Traverse;
@ -648,6 +649,7 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
$called = false;
$entity = new Entity();
$entity->firstName = 'Bernhard';
$entity->data = array('firstName' => 'Bernhard');
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, &$called) {
$called = true;
@ -656,6 +658,7 @@ abstract class Abstract2Dot5ApiTest extends AbstractValidatorTest
$this->metadata->addConstraint(new Callback($callback));
$this->metadata->addPropertyConstraint('firstName', new Callback($callback));
$this->metadata->addPropertyConstraint('data', new Collection(array('firstName' => new Expression('value == this.firstName'))));
$this->validator->validate($entity);

View File

@ -108,7 +108,7 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
$this->validateGenericNode(
$value,
null,
$previousObject,
is_object($value) ? spl_object_hash($value) : null,
$metadata,
$this->defaultPropertyPath,