Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7c3e620

Browse filesBrowse files
committed
Fix, and document setCircularReferenceHandler's new parameters
1 parent a4dad43 commit 7c3e620
Copy full SHA for 7c3e620

File tree

1 file changed

+7
-3
lines changed
Filter options

1 file changed

+7
-3
lines changed

‎components/serializer.rst

Copy file name to clipboardExpand all lines: components/serializer.rst
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ When serializing, you can set a callback to format a specific object property::
545545
$encoder = new JsonEncoder();
546546
$normalizer = new GetSetMethodNormalizer();
547547

548-
$callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = null) {
548+
$callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = array()) {
549549
// Every parameters can be omitted if not used
550550
return $dateTime instanceof \DateTime ? $dateTime->format(\DateTime::ISO8601) : '';
551551
};
@@ -832,14 +832,18 @@ having unique identifiers::
832832
$encoder = new JsonEncoder();
833833
$normalizer = new ObjectNormalizer();
834834

835-
$normalizer->setCircularReferenceHandler(function ($object) {
835+
$normalizer->setCircularReferenceHandler(function ($object, string $format = null, array $context = array()) {
836+
// Every parameters can be omitted if not used
836837
return $object->getName();
837838
});
838839

839840
$serializer = new Serializer(array($normalizer), array($encoder));
840841
var_dump($serializer->serialize($org, 'json'));
841842
// {"name":"Les-Tilleuls.coop","members":[{"name":"K\u00e9vin", organization: "Les-Tilleuls.coop"}]}
842843

844+
.. versionadded:: 4.2
845+
The ``$format`` and ``$context`` parameters of ``setCircularReferenceHandler()`` were introduced in Symfony 4.2.
846+
843847
Handling Serialization Depth
844848
----------------------------
845849

@@ -968,7 +972,7 @@ having unique identifiers::
968972

969973
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
970974
$normalizer = new ObjectNormalizer($classMetadataFactory);
971-
$normalizer->setMaxDepthHandler(function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = null) {
975+
$normalizer->setMaxDepthHandler(function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = array()) {
972976
// Every parameters can be omitted if not used
973977
return '/foos/'.$innerObject->id;
974978
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.