Skip to content

Commit 50bb84d

Browse files
committed
[Validator] Optimized RecursiveContextualValidator
1 parent eed29d8 commit 50bb84d

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/Symfony/Component/Validator/NodeVisitor/NodeValidationVisitor.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,18 @@ public function visit(Node $node, ExecutionContextInterface $context)
103103
$context->markObjectAsValidatedForGroup($objectHash, $groupHash);
104104
}
105105

106-
// Validate normal group
107-
if (!$group instanceof GroupSequence) {
108-
$this->validateNodeForGroup($node, $group, $context, $objectHash);
106+
if ($group instanceof GroupSequence) {
107+
// Traverse group sequence until a violation is generated
108+
$this->traverseGroupSequence($node, $group, $context);
109+
110+
// Skip the group sequence when validating successor nodes
111+
unset($node->groups[$key]);
109112

110113
continue;
111114
}
112115

113-
// Traverse group sequence until a violation is generated
114-
$this->traverseGroupSequence($node, $group, $context);
115-
116-
// Skip the group sequence when validating successor nodes
117-
unset($node->groups[$key]);
116+
// Validate normal group
117+
$this->validateNodeForGroup($node, $group, $context, $objectHash);
118118
}
119119

120120
return true;

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ protected function normalizeGroups($groups)
268268
*/
269269
private function traverseClassNode($value, ClassMetadataInterface $metadata = null, $propertyPath, array $groups, $cascadedGroups, $traversalStrategy, ExecutionContextInterface $context)
270270
{
271+
// Replace "Default" group by group sequence, if appropriate
272+
$groups = $this->replaceDefaultGroup($value, $metadata, $groups);
273+
271274
$groups = $this->validateNode($value, $value, $metadata, $propertyPath, $groups, $traversalStrategy, $context);
272275

273276
if (0 === count($groups)) {
@@ -566,10 +569,6 @@ public function validateNode($value, $object, MetadataInterface $metadata = null
566569
$context->setMetadata($metadata);
567570
$context->setPropertyPath($propertyPath);
568571

569-
if ($metadata instanceof ClassMetadataInterface) {
570-
$groups = $this->replaceDefaultGroup($value, $metadata, $groups);
571-
}
572-
573572
$objectHash = is_object($object) ? spl_object_hash($object) : null;
574573

575574
// if group (=[<G1,G2>,G3,G4]) contains group sequence (=<G1,G2>)
@@ -599,18 +598,18 @@ public function validateNode($value, $object, MetadataInterface $metadata = null
599598
$context->markObjectAsValidatedForGroup($objectHash, $groupHash);
600599
}
601600

602-
// Validate normal group
603-
if (!$group instanceof GroupSequence) {
604-
$this->validateNodeForGroup($value, $objectHash, $metadata, $group, $context);
601+
if ($group instanceof GroupSequence) {
602+
// Traverse group sequence until a violation is generated
603+
$this->stepThroughGroupSequence($value, $object, $metadata, $propertyPath, $traversalStrategy, $group, $context);
604+
605+
// Skip the group sequence when validating successor nodes
606+
unset($groups[$key]);
605607

606608
continue;
607609
}
608610

609-
// Traverse group sequence until a violation is generated
610-
$this->stepThroughGroupSequence($value, $object, $metadata, $propertyPath, $traversalStrategy, $group, $context);
611-
612-
// Skip the group sequence when validating successor nodes
613-
unset($groups[$key]);
611+
// Validate normal group
612+
$this->validateNodeForGroup($value, $objectHash, $metadata, $group, $context);
614613
}
615614

616615
return $groups;

0 commit comments

Comments
 (0)