[Validator] Optimized RecursiveContextualValidator
This commit is contained in:
parent
eed29d8ad3
commit
50bb84d06b
|
@ -103,18 +103,18 @@ class NodeValidationVisitor extends AbstractVisitor
|
||||||
$context->markObjectAsValidatedForGroup($objectHash, $groupHash);
|
$context->markObjectAsValidatedForGroup($objectHash, $groupHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate normal group
|
if ($group instanceof GroupSequence) {
|
||||||
if (!$group instanceof GroupSequence) {
|
// Traverse group sequence until a violation is generated
|
||||||
$this->validateNodeForGroup($node, $group, $context, $objectHash);
|
$this->traverseGroupSequence($node, $group, $context);
|
||||||
|
|
||||||
|
// Skip the group sequence when validating successor nodes
|
||||||
|
unset($node->groups[$key]);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse group sequence until a violation is generated
|
// Validate normal group
|
||||||
$this->traverseGroupSequence($node, $group, $context);
|
$this->validateNodeForGroup($node, $group, $context, $objectHash);
|
||||||
|
|
||||||
// Skip the group sequence when validating successor nodes
|
|
||||||
unset($node->groups[$key]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -268,6 +268,9 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
|
||||||
*/
|
*/
|
||||||
private function traverseClassNode($value, ClassMetadataInterface $metadata = null, $propertyPath, array $groups, $cascadedGroups, $traversalStrategy, ExecutionContextInterface $context)
|
private function traverseClassNode($value, ClassMetadataInterface $metadata = null, $propertyPath, array $groups, $cascadedGroups, $traversalStrategy, ExecutionContextInterface $context)
|
||||||
{
|
{
|
||||||
|
// Replace "Default" group by group sequence, if appropriate
|
||||||
|
$groups = $this->replaceDefaultGroup($value, $metadata, $groups);
|
||||||
|
|
||||||
$groups = $this->validateNode($value, $value, $metadata, $propertyPath, $groups, $traversalStrategy, $context);
|
$groups = $this->validateNode($value, $value, $metadata, $propertyPath, $groups, $traversalStrategy, $context);
|
||||||
|
|
||||||
if (0 === count($groups)) {
|
if (0 === count($groups)) {
|
||||||
|
@ -566,10 +569,6 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
|
||||||
$context->setMetadata($metadata);
|
$context->setMetadata($metadata);
|
||||||
$context->setPropertyPath($propertyPath);
|
$context->setPropertyPath($propertyPath);
|
||||||
|
|
||||||
if ($metadata instanceof ClassMetadataInterface) {
|
|
||||||
$groups = $this->replaceDefaultGroup($value, $metadata, $groups);
|
|
||||||
}
|
|
||||||
|
|
||||||
$objectHash = is_object($object) ? spl_object_hash($object) : null;
|
$objectHash = is_object($object) ? spl_object_hash($object) : null;
|
||||||
|
|
||||||
// if group (=[<G1,G2>,G3,G4]) contains group sequence (=<G1,G2>)
|
// if group (=[<G1,G2>,G3,G4]) contains group sequence (=<G1,G2>)
|
||||||
|
@ -599,18 +598,18 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
|
||||||
$context->markObjectAsValidatedForGroup($objectHash, $groupHash);
|
$context->markObjectAsValidatedForGroup($objectHash, $groupHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate normal group
|
if ($group instanceof GroupSequence) {
|
||||||
if (!$group instanceof GroupSequence) {
|
// Traverse group sequence until a violation is generated
|
||||||
$this->validateNodeForGroup($value, $objectHash, $metadata, $group, $context);
|
$this->stepThroughGroupSequence($value, $object, $metadata, $propertyPath, $traversalStrategy, $group, $context);
|
||||||
|
|
||||||
|
// Skip the group sequence when validating successor nodes
|
||||||
|
unset($groups[$key]);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Traverse group sequence until a violation is generated
|
// Validate normal group
|
||||||
$this->stepThroughGroupSequence($value, $object, $metadata, $propertyPath, $traversalStrategy, $group, $context);
|
$this->validateNodeForGroup($value, $objectHash, $metadata, $group, $context);
|
||||||
|
|
||||||
// Skip the group sequence when validating successor nodes
|
|
||||||
unset($groups[$key]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $groups;
|
return $groups;
|
||||||
|
|
Reference in New Issue