@@ -48,6 +48,10 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
48
48
private $ validatorFactory ;
49
49
private $ objectInitializers ;
50
50
51
+ private $ validatedObjectsReferences = [];
52
+ private $ validatedConstraintsReferences = [];
53
+ private $ initializedObjectsReferences = [];
54
+
51
55
/**
52
56
* Creates a validator for the given context.
53
57
*
@@ -442,6 +446,10 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
442
446
{
443
447
$ context ->setNode ($ object , $ object , $ metadata , $ propertyPath );
444
448
449
+ if (!isset ($ this ->initializedObjectsReferences [$ cacheKey ])) {
450
+ $ this ->initializedObjectsReferences [$ cacheKey ] = $ object ;
451
+ }
452
+
445
453
if (!$ context ->isObjectInitialized ($ cacheKey )) {
446
454
foreach ($ this ->objectInitializers as $ initializer ) {
447
455
$ initializer ->initialize ($ object );
@@ -457,7 +465,15 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
457
465
$ defaultOverridden = false ;
458
466
459
467
// Use the object hash for group sequences
460
- $ groupHash = \is_object ($ group ) ? spl_object_hash ($ group ) : $ group ;
468
+ if (\is_object ($ group )) {
469
+ $ groupHash = spl_object_hash ($ group );
470
+
471
+ if (!isset ($ this ->validatedObjectsReferences [$ groupHash ])) {
472
+ $ this ->validatedObjectsReferences [$ groupHash ] = $ group ;
473
+ }
474
+ } else {
475
+ $ groupHash = $ group ;
476
+ }
461
477
462
478
if ($ context ->isGroupValidated ($ cacheKey , $ groupHash )) {
463
479
// Skip this group when validating the properties and when
@@ -790,6 +806,10 @@ private function validateInGroup($value, $cacheKey, MetadataInterface $metadata,
790
806
// that constraints belong to multiple validated groups
791
807
if (null !== $ cacheKey ) {
792
808
$ constraintHash = spl_object_hash ($ constraint );
809
+ if (!isset ($ this ->validatedConstraintsReferences [$ constraintHash ])) {
810
+ $ this ->validatedConstraintsReferences [$ constraintHash ] = $ constraint ;
811
+ }
812
+
793
813
// instanceof Valid: In case of using a Valid constraint with many groups
794
814
// it makes a reference object get validated by each group
795
815
if ($ constraint instanceof Composite || $ constraint instanceof Valid) {
0 commit comments