8000 bug #25529 [Validator] Fix access to root object when using composite… · symfony/symfony@d975ad6 · GitHub
[go: up one dir, main page]

Skip to content

Commit d975ad6

Browse files
committed
bug #25529 [Validator] Fix access to root object when using composite constraint (ostrolucky)
This PR was merged into the 2.7 branch. Discussion ---------- [Validator] Fix access to root object when using composite constraint | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12315, #20477, #21706 | License | MIT | Doc PR | Commits ------- b18cdcf [Validator] Fix access to root object when using composite constraint
2 parents 07a7f56 + b18cdcf commit d975ad6

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/Symfony/Component/Validator/Tests/Validator/Abstract2Dot5ApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Validator\Constraints\Callback;
1515
use Symfony\Component\Validator\Constraints\Collection;
16+
use Symfony\Component\Validator\Constraints\Expression;
1617
use Symfony\Component\Validator\Constraints\GroupSequence;
1718
use Symfony\Component\Validator\Constraints\NotNull;
1819
use Symfony\Component\Validator\Constraints\Traverse;
@@ -648,6 +649,7 @@ public function testAccessCurrentObject()
648649
$called = false;
649650
$entity = new Entity();
650651
$entity->firstName = 'Bernhard';
652+
$entity->data = array('firstName' => 'Bernhard');
651653

652654
$callback = function ($value, ExecutionContextInterface $context) use ($test, $entity, &$called) {
653655
$called = true;
@@ -656,6 +658,7 @@ public function testAccessCurrentObject()
656658

657659
$this->metadata->addConstraint(new Callback($callback));
658660
$this->metadata->addPropertyConstraint('firstName', new Callback($callback));
661+
$this->metadata->addPropertyConstraint('data', new Collection(array('firstName' => new Expression('value == this.firstName'))));
659662

660663
$this->validator->validate($entity);
661664

src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function validate($value, $constraints = null, $groups = null)
108108

109109
$this->validateGenericNode(
110110
$value,
111-
null,
111+
$previousObject,
112112
is_object($value) ? spl_object_hash($value) : null,
113113
$metadata,
114114
$this->defaultPropertyPath,

0 commit comments

Comments
 (0)
0