Skip to content

Commit 1afd138

Browse files
committed
bug #11439 custom encoders interface signature (PandaaAgency)
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
2 parents 500b8fc + 754a62b commit 1afd138

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

serializer/custom_encoders.rst

+8-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ create your own encoder that uses the
3232
return Yaml::dump($data);
3333
}
3434

35-
public function supportsEncoding($format, array $context = [])
35+
public function supportsEncoding($format)
3636
{
3737
return 'yaml' === $format;
3838
}
@@ -42,12 +42,18 @@ create your own encoder that uses the
4242
return Yaml::parse($data);
4343
}
4444

45-
public function supportsDecoding($format, array $context = [])
45+
public function supportsDecoding($format)
4646
{
4747
return 'yaml' === $format;
4848
}
4949
}
5050

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
55+
56+
5157
Registering it in your app
5258
--------------------------
5359

0 commit comments

Comments
 (0)