[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) {
|
|
||||||
$this->validateNodeForGroup($node, $group, $context, $objectHash);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Traverse group sequence until a violation is generated
|
// Traverse group sequence until a violation is generated
|
||||||
$this->traverseGroupSequence($node, $group, $context);
|
$this->traverseGroupSequence($node, $group, $context);
|
||||||
|
|
||||||
// Skip the group sequence when validating successor nodes
|
// Skip the group sequence when validating successor nodes
|
||||||
unset($node->groups[$key]);
|
unset($node->groups[$key]);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate normal group
|
||||||
|
$this->validateNodeForGroup($node, $group, $context, $objectHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
$this->validateNodeForGroup($value, $objectHash, $metadata, $group, $context);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Traverse group sequence until a violation is generated
|
// Traverse group sequence until a violation is generated
|
||||||
$this->stepThroughGroupSequence($value, $object, $metadata, $propertyPath, $traversalStrategy, $group, $context);
|
$this->stepThroughGroupSequence($value, $object, $metadata, $propertyPath, $traversalStrategy, $group, $context);
|
||||||
|
|
||||||
// Skip the group sequence when validating successor nodes
|
// Skip the group sequence when validating successor nodes
|
||||||
unset($groups[$key]);
|
unset($groups[$key]);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate normal group
|
||||||
|
$this->validateNodeForGroup($value, $objectHash, $metadata, $group, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $groups;
|
return $groups;
|
||||||
|
Reference in New Issue
Block a user