@@ -59,6 +59,11 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
5959public function __construct (ClassMetadataFactoryInterface $ classMetadataFactory =null ,NameConverterInterface $ nameConverter =null ,PropertyTypeExtractorInterface $ propertyTypeExtractor =null ,ClassDiscriminatorResolverInterface $ classDiscriminatorResolver =null ,callable $ objectClassResolver =null ,array $ defaultContext = [])
6060 {
6161parent ::__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+
6267$ this ->defaultContext [self ::EXCLUDE_FROM_CACHE_KEY ] = [self ::CIRCULAR_REFERENCE_LIMIT_COUNTERS ];
6368
6469$ this ->propertyTypeExtractor =$ propertyTypeExtractor ;
@@ -86,7 +91,12 @@ public function normalize($object, $format = null, array $context = [])
8691if (!isset ($ context ['cache_key ' ])) {
8792$ context ['cache_key ' ] =$ this ->getCacheKey ($ format ,$ context );
8893 }
94+
8995if (\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+
90100foreach ($ context [self ::CALLBACKS ]as $ attribute =>$ callback ) {
91101if (!\is_callable ($ callback )) {
92102throw 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 = [])
105115$ attributesMetadata =$ this ->classMetadataFactory ?$ this ->classMetadataFactory ->getMetadataFor ($ class )->getAttributesMetadata () :null ;
106116$ maxDepthHandler =$ context [self ::MAX_DEPTH_HANDLER ] ??$ this ->defaultContext [self ::MAX_DEPTH_HANDLER ] ??$ this ->maxDepthHandler ;
107117
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+
108122foreach ($ attributesas $ attribute ) {
109123$ maxDepthReached =false ;
110124if (null !==$ attributesMetadata && ($ maxDepthReached =$ this ->isMaxDepthReached ($ attributesMetadata ,$ class ,$ attribute ,$ context )) && !$ maxDepthHandler ) {