@@ -545,10 +545,9 @@ When serializing, you can set a callback to format a specific object property::
545
545
$encoder = new JsonEncoder();
546
546
$normalizer = new GetSetMethodNormalizer();
547
547
548
- $callback = function ($dateTime) {
549
- return $dateTime instanceof \DateTime
550
- ? $dateTime->format(\DateTime::ISO8601)
551
- : '';
548
+ $callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = null) {
549
+ // Every parameters can be omitted if not used
550
+ return $dateTime instanceof \DateTime ? $dateTime->format(\DateTime::ISO8601) : '';
552
551
};
553
552
554
553
$normalizer->setCallbacks(array('createdAt' => $callback));
@@ -563,6 +562,11 @@ When serializing, you can set a callback to format a specific object property::
563
562
$serializer->serialize($person, 'json');
564
563
// Output: {"name":"cordoval", "age": 34, "createdAt": "2014-03-22T09:43:12-0500"}
565
564
565
+ .. versionadded :: 4.2
566
+ The ``$outerObject ``, ``$attributeName ``, ``$format `` and ``$context ``
567
+ parameters of the callback were introduced in Symfony 4.2.
568
+
569
+
566
570
.. _component-serializer-normalizers :
567
571
568
572
Normalizers
@@ -964,8 +968,9 @@ having unique identifiers::
964
968
965
969
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
966
970
$normalizer = new ObjectNormalizer($classMetadataFactory);
967
- $normalizer->setMaxDepthHandler(function ($foo) {
968
- return '/foos/'.$foo->id;
971
+ $normalizer->setMaxDepthHandler(function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = null) {
972
+ // Every parameters can be omitted if not used
973
+ return '/foos/'.$innerObject->id;
969
974
});
970
975
971
976
$serializer = new Serializer(array($normalizer));
@@ -984,6 +989,10 @@ having unique identifiers::
984
989
.. versionadded :: 4.1
985
990
The ``setMaxDepthHandler() `` method was introduced in Symfony 4.1.
986
991
992
+ .. versionadded :: 4.2
993
+ The ``$outerObject ``, ``$attributeName ``, ``$format `` and ``$context ``
994
+ parameters of ``setMaxDepthHandler() `` were introduced in Symfony 4.2.
995
+
987
996
Handling Arrays
988
997
---------------
989
998
0 commit comments