From 6f8d5e263edcd8df82c4502c6651e0f1c954320b Mon Sep 17 00:00:00 2001 From: andrey1s Date: Sun, 4 Feb 2018 23:55:07 +0300 Subject: [PATCH] add context to serialize and deserialize --- src/Symfony/Component/Serializer/CHANGELOG.md | 1 + src/Symfony/Component/Serializer/Serializer.php | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Serializer/CHANGELOG.md b/src/Symfony/Component/Serializer/CHANGELOG.md index 057275e11b..450640d160 100644 --- a/src/Symfony/Component/Serializer/CHANGELOG.md +++ b/src/Symfony/Component/Serializer/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG * added getter for extra attributes in `ExtraAttributesException` * improved `CsvEncoder` to handle variable nested structures * CSV headers can be passed to the `CsvEncoder` via the `csv_headers` serialization context variable + * added `$context` when checking for encoding, decoding and normalizing in `Serializer` 3.3.0 ----- diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index 8a689dc61d..1b244177c7 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -108,11 +108,11 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz */ final public function serialize($data, $format, array $context = array()) { - if (!$this->supportsEncoding($format)) { + if (!$this->supportsEncoding($format, $context)) { throw new NotEncodableValueException(sprintf('Serialization for the format %s is not supported', $format)); } - if ($this->encoder->needsNormalization($format)) { + if ($this->encoder->needsNormalization($format, $context)) { $data = $this->normalize($data, $format, $context); } @@ -124,7 +124,7 @@ class Serializer implements SerializerInterface, NormalizerInterface, Denormaliz */ final public function deserialize($data, $type, $format, array $context = array()) { - if (!$this->supportsDecoding($format)) { + if (!$this->supportsDecoding($format, $context)) { throw new NotEncodableValueException(sprintf('Deserialization for the format %s is not supported', $format)); }