Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit59a7e51

Browse files
committed
feature#11584 Update serializer.rst: deprecate the setCallbacks (votanlean)
This PR was merged into the 4.2 branch.Discussion----------Update serializer.rst: deprecate the setCallbacksChange the deprecated setCallbacks method to the callbacks context option<!--If your pull request fixes a BUG, use the oldest maintained branch that containsthe bug (seehttps://symfony.com/roadmap for the list of maintained branches).If your pull request documents a NEW FEATURE, use the same Symfony branch wherethe feature was introduced (and `master` for features of unreleased versions).-->Commits-------695b706 Update serializer.rst: deprecate the setCallbacks
2 parents4f31753 +695b706 commit59a7e51

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

‎components/serializer.rst‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,12 @@ and ``remove``.
623623
Using Callbacks to Serialize Properties with Object Instances
624624
-------------------------------------------------------------
625625

626+
..deprecated::4.2
627+
628+
The:method:`Symfony\\Component\\Serializer\\Normalizer\\AbstractNormalizer::setCallbacks`
629+
method is deprecated since Symfony 4.2. Use the ``callbacks``
630+
key of the context instead.
631+
626632
When serializing, you can set a callback to format a specific object property::
627633

628634
use App\Model\Person;
@@ -631,14 +637,19 @@ When serializing, you can set a callback to format a specific object property::
631637
use Symfony\Component\Serializer\Serializer;
632638

633639
$encoder = new JsonEncoder();
634-
$normalizer = new GetSetMethodNormalizer();
635640

636641
// all callback parameters are optional (you can omit the ones you don't use)
637642
$callback = function ($innerObject, $outerObject, string $attributeName, string $format = null, array $context = []) {
638643
return $innerObject instanceof \DateTime ? $innerObject->format(\DateTime::ISO8601) : '';
639644
};
640645

641-
$normalizer->setCallbacks(['createdAt' => $callback]);
646+
$defaultContext = [
647+
AbstractNormalizer::CALLBACKS => [
648+
'createdAt' => $callback,
649+
],
650+
];
651+
652+
$normalizer = new GetSetMethodNormalizer(null, null, null, null, null, $defaultContext);
642653

643654
$serializer = new Serializer([$normalizer], [$encoder]);
644655

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp