@@ -59,6 +59,11 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
59
59
public function __construct (ClassMetadataFactoryInterface $ classMetadataFactory = null , NameConverterInterface $ nameConverter = null , PropertyTypeExtractorInterface $ propertyTypeExtractor = null , ClassDiscriminatorResolverInterface $ classDiscriminatorResolver = null , callable $ objectClassResolver = null , array $ defaultContext = [])
60
60
{
61
61
parent ::__construct ($ classMetadataFactory , $ nameConverter , $ defaultContext );
62
+
63
+ if (\array_key_exists (self ::MAX_DEPTH_HANDLER , $ this ->defaultContext ) && !\is_callable ($ this ->defaultContext [self ::MAX_DEPTH_HANDLER ])) {
64
+ throw new InvalidArgumentException (sprintf ('The %s given in the default context is not callable. ' , self ::MAX_DEPTH_HANDLER ));
65
+ }
66
+
62
67
$ this ->defaultContext [self ::EXCLUDE_FROM_CACHE_KEY ] = [self ::CIRCULAR_REFERENCE_LIMIT_COUNTERS ];
63
68
64
69
$ this ->propertyTypeExtractor = $ propertyTypeExtractor ;
@@ -86,7 +91,12 @@ public function normalize($object, $format = null, array $context = [])
86
91
if (!isset ($ context ['cache_key ' ])) {
87
92
$ context ['cache_key ' ] = $ this ->getCacheKey ($ format , $ context );
88
93
}
94
+
89
95
if (\array_key_exists (self ::CALLBACKS , $ context )) {
96
+ if (!\is_array ($ context [self ::CALLBACKS ])) {
97
+ throw new InvalidArgumentException ('The callbacks context must be a array of callable. ' );
98
+ }
99
+
90
100
foreach ($ context [self ::CALLBACKS ] as $ attribute => $ callback ) {
91
101
if (!\is_callable ($ callback )) {
92
102
throw new InvalidArgumentException (sprintf ('The callback given in the context for attribute "%s" is not callable. ' , $ attribute ));
@@ -105,6 +115,10 @@ public function normalize($object, $format = null, array $context = [])
105
115
$ attributesMetadata = $ this ->classMetadataFactory ? $ this ->classMetadataFactory ->getMetadataFor ($ class )->getAttributesMetadata () : null ;
106
116
$ maxDepthHandler = $ context [self ::MAX_DEPTH_HANDLER ] ?? $ this ->defaultContext [self ::MAX_DEPTH_HANDLER ] ?? $ this ->maxDepthHandler ;
107
117
118
+ if (null !== $ maxDepthHandler && !\is_callable ($ maxDepthHandler )) {
119
+ throw new InvalidArgumentException (sprintf ('The %s given in the context is not callable. ' , self ::MAX_DEPTH_HANDLER ));
120
+ }
121
+
108
122
foreach ($ attributes as $ attribute ) {
109
123
$ maxDepthReached = false ;
110
124
if (null !== $ attributesMetadata && ($ maxDepthReached = $ this ->isMaxDepthReached ($ attributesMetadata , $ class , $ attribute , $ context )) && !$ maxDepthHandler ) {
0 commit comments