Skip to content

[Serializer] Deprecate context aware interfaces #16386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion controller/error_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ contents, create a new Normalizer that supports the ``FlattenException`` input::
];
}

public function supportsNormalization($data, string $format = null)
public function supportsNormalization($data, string $format = null, array $context = [])
{
return $data instanceof FlattenException;
}
Expand Down
11 changes: 2 additions & 9 deletions serializer/custom_encoders.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ create your own encoder that uses the
return Yaml::dump($data);
}

public function supportsEncoding(string $format)
public function supportsEncoding(string $format, array $context = [])
{
return 'yaml' === $format;
}
Expand All @@ -43,19 +43,12 @@ create your own encoder that uses the
return Yaml::parse($data);
}

public function supportsDecoding(string $format)
public function supportsDecoding(string $format, array $context = [])
{
return 'yaml' === $format;
}
}

.. tip::

If you need access to ``$context`` in your ``supportsDecoding`` or
``supportsEncoding`` method, make sure to implement
``Symfony\Component\Serializer\Encoder\ContextAwareDecoderInterface``
or ``Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface`` accordingly.


Registering it in your app
--------------------------
Expand Down
4 changes: 2 additions & 2 deletions serializer/custom_normalizer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ to customize the normalized data. To do that, leverage the ``ObjectNormalizer``:

use App\Entity\Topic;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

class TopicNormalizer implements ContextAwareNormalizerInterface
class TopicNormalizer implements NormalizerInterface
{
private $router;
private $normalizer;
Expand Down