You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was merged into the 4.2 branch.
Discussion
----------
custom encoders interface signature
Fixes the documentation about encoders that was wrong.
Using `Symfony\Component\Serializer\Encoder\EncoderInterface` no `$context` parameter is passed to `supportsEncoding` method. You have to use the ContextAware version of it.
<!--
If your pull request fixes a BUG, use the oldest maintained branch that contains
the bug (see https://symfony.com/roadmap for the list of maintained branches).
If your pull request documents a NEW FEATURE, use the same Symfony branch where
the feature was introduced (and `master` for features of unreleased versions).
-->
Commits
-------
754a62b custom encoders interface signature
Copy file name to clipboardExpand all lines: serializer/custom_encoders.rst
+8-2
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ create your own encoder that uses the
32
32
return Yaml::dump($data);
33
33
}
34
34
35
-
public function supportsEncoding($format, array $context = [])
35
+
public function supportsEncoding($format)
36
36
{
37
37
return 'yaml' === $format;
38
38
}
@@ -42,12 +42,18 @@ create your own encoder that uses the
42
42
return Yaml::parse($data);
43
43
}
44
44
45
-
public function supportsDecoding($format, array $context = [])
45
+
public function supportsDecoding($format)
46
46
{
47
47
return 'yaml' === $format;
48
48
}
49
49
}
50
50
51
+
.. tip::
52
+
53
+
If you need access to ``$context`` in your ``supportsDecoding`` or ``supportsEncoding`` method, make sure
54
+
to implements ``Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface`` or ``Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface`` interface
0 commit comments