From 754a62bd89c076ec98a2ed8fa69e4ef55a05ac2a Mon Sep 17 00:00:00 2001 From: Florian VANHECKE Date: Mon, 15 Apr 2019 19:51:46 +0200 Subject: [PATCH] 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. --- serializer/custom_encoders.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/serializer/custom_encoders.rst b/serializer/custom_encoders.rst index 904dc8a4aed..23f547dfaf9 100644 --- a/serializer/custom_encoders.rst +++ b/serializer/custom_encoders.rst @@ -32,7 +32,7 @@ create your own encoder that uses the return Yaml::dump($data); } - public function supportsEncoding($format, array $context = []) + public function supportsEncoding($format) { return 'yaml' === $format; } @@ -42,12 +42,18 @@ create your own encoder that uses the return Yaml::parse($data); } - public function supportsDecoding($format, array $context = []) + public function supportsDecoding($format) { return 'yaml' === $format; } } +.. tip:: + + If you need access to ``$context`` in your ``supportsDecoding`` or ``supportsEncoding`` method, make sure + to implements ``Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface`` or ``Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface`` interface + + Registering it in your app --------------------------