@@ -108,7 +108,7 @@ public function validate($value, $constraints = null, $groups = null)
108
108
$ this ->validateGenericNode (
109
109
$ value ,
110
110
$ previousObject ,
111
- \is_object ($ value ) ? spl_object_hash ($ value ) : null ,
111
+ \is_object ($ value ) ? $ this -> generateCacheKey ($ value ) : null ,
112
112
$ metadata ,
113
113
$ this ->defaultPropertyPath ,
114
114
$ groups ,
@@ -176,7 +176,7 @@ public function validateProperty($object, $propertyName, $groups = null)
176
176
177
177
$ propertyMetadatas = $ classMetadata ->getPropertyMetadata ($ propertyName );
178
178
$ groups = $ groups ? $ this ->normalizeGroups ($ groups ) : $ this ->defaultGroups ;
179
- $ cacheKey = spl_object_hash ($ object );
179
+ $ cacheKey = $ this -> generateCacheKey ($ object );
180
180
$ propertyPath = PropertyPath::append ($ this ->defaultPropertyPath , $ propertyName );
181
181
182
182
$ previousValue = $ this ->context ->getValue ();
@@ -224,7 +224,7 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr
224
224
if (\is_object ($ objectOrClass )) {
225
225
$ object = $ objectOrClass ;
226
226
$ class = \get_class ($ object );
227
- $ cacheKey = spl_object_hash ($ objectOrClass );
227
+ $ cacheKey = $ this -> generateCacheKey ($ objectOrClass );
228
228
$ propertyPath = PropertyPath::append ($ this ->defaultPropertyPath , $ propertyName );
229
229
} else {
230
230
// $objectOrClass contains a class name
@@ -313,7 +313,7 @@ private function validateObject($object, string $propertyPath, array $groups, in
313
313
314
314
$ this ->validateClassNode (
315
315
$ object ,
316
- spl_object_hash ($ object ),
316
+ $ this -> generateCacheKey ($ object ),
317
317
$ classMetadata ,
318
318
$ propertyPath ,
319
319
$ groups ,
@@ -429,7 +429,7 @@ private function validateClassNode($object, ?string $cacheKey, ClassMetadataInte
429
429
$ defaultOverridden = false ;
430
430
431
431
// Use the object hash for group sequences
432
- $ groupHash = \is_object ($ group ) ? spl_object_hash ($ group ) : $ group ;
432
+ $ groupHash = \is_object ($ group ) ? $ this -> generateCacheKey ($ group, true ) : $ group ;
433
433
434
434
if ($ context ->isGroupValidated ($ cacheKey , $ groupHash )) {
435
435
// Skip this group when validating the properties and when
@@ -740,7 +740,7 @@ private function validateInGroup($value, ?string $cacheKey, MetadataInterface $m
740
740
// Prevent duplicate validation of constraints, in the case
741
741
// that constraints belong to multiple validated groups
742
742
if (null !== $ cacheKey ) {
743
- $ constraintHash = spl_object_hash ($ constraint );
743
+ $ constraintHash = $ this -> generateCacheKey ($ constraint, true );
744
744
// instanceof Valid: In case of using a Valid constraint with many groups
745
745
// it makes a reference object get validated by each group
746
746
if ($ constraint instanceof Composite || $ constraint instanceof Valid) {
@@ -772,4 +772,22 @@ private function validateInGroup($value, ?string $cacheKey, MetadataInterface $m
772
772
}
773
773
}
774
774
}
775
+
776
+ /**
777
+ * @param object $object
778
+ */
779
+ private function generateCacheKey ($ object , bool $ dependsOnPropertyPath = false ): string
780
+ {
781
+ if ($ this ->context instanceof ExecutionContext) {
782
+ $ cacheKey = $ this ->context ->generateCacheKey ($ object );
783
+ } else {
784
+ $ cacheKey = spl_object_hash ($ object );
785
+ }
786
+
787
+ if ($ dependsOnPropertyPath ) {
788
+ $ cacheKey .= $ this ->context ->getPropertyPath ();
789
+ }
790
+
791
+ return $ cacheKey ;
792
+ }
775
793
}
0 commit comments