From 61d796a2ead3d3d09b859e6f51ddffc711f50b54 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 20 Jun 2017 23:04:29 +0200 Subject: [PATCH] [Serializer] Implement missing context aware interfaces --- .../Component/Serializer/Encoder/ChainDecoder.php | 6 ++---- .../Component/Serializer/Encoder/ChainEncoder.php | 9 +++------ .../Serializer/Normalizer/ArrayDenormalizer.php | 6 ++---- src/Symfony/Component/Serializer/Serializer.php | 6 +++++- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php index a4cc9f67957e..930c419552d7 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainDecoder.php @@ -22,7 +22,7 @@ * * @final since version 3.3. */ -class ChainDecoder implements DecoderInterface /*, ContextAwareDecoderInterface*/ +class ChainDecoder implements ContextAwareDecoderInterface { protected $decoders = array(); protected $decoderByFormat = array(); @@ -43,10 +43,8 @@ final public function decode($data, $format, array $context = array()) /** * {@inheritdoc} */ - public function supportsDecoding($format/*, array $context = array()*/) + public function supportsDecoding($format, array $context = array()) { - $context = func_num_args() > 1 ? func_get_arg(1) : array(); - try { $this->getDecoder($format, $context); } catch (RuntimeException $e) { diff --git a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php index cfd8855bb815..ae12cc9f2916 100644 --- a/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php +++ b/src/Symfony/Component/Serializer/Encoder/ChainEncoder.php @@ -22,7 +22,7 @@ * * @final since version 3.3. */ -class ChainEncoder implements EncoderInterface /*, ContextAwareEncoderInterface*/ +class ChainEncoder implements ContextAwareEncoderInterface { protected $encoders = array(); protected $encoderByFormat = array(); @@ -43,10 +43,8 @@ final public function encode($data, $format, array $context = array()) /** * {@inheritdoc} */ - public function supportsEncoding($format/*, array $context = array()*/) + public function supportsEncoding($format, array $context = array()) { - $context = func_num_args() > 1 ? func_get_arg(1) : array(); - try { $this->getEncoder($format, $context); } catch (RuntimeException $e) { @@ -64,9 +62,8 @@ public function supportsEncoding($format/*, array $context = array()*/) * * @return bool */ - public function needsNormalization($format/*, array $context = array()*/) + public function needsNormalization($format, array $context = array()) { - $context = func_num_args() > 1 ? func_get_arg(1) : array(); $encoder = $this->getEncoder($format, $context); if (!$encoder instanceof NormalizationAwareInterface) { diff --git a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php index 56d27eb7bf20..817fe5111a9c 100644 --- a/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php +++ b/src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php @@ -24,7 +24,7 @@ * * @final since version 3.3. */ -class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterface +class ArrayDenormalizer implements ContextAwareDenormalizerInterface, SerializerAwareInterface { /** * @var SerializerInterface|DenormalizerInterface @@ -66,10 +66,8 @@ public function denormalize($data, $class, $format = null, array $context = arra /** * {@inheritdoc} */ - public function supportsDenormalization($data, $type, $format = null/*, array $context = array()*/) + public function supportsDenormalization($data, $type, $format = null, array $context = array()) { - $context = func_num_args() > 3 ? func_get_arg(3) : array(); - return substr($type, -2) === '[]' && $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context); } diff --git a/src/Symfony/Component/Serializer/Serializer.php b/src/Symfony/Component/Serializer/Serializer.php index f63c7d5c88e6..0911c67108d6 100644 --- a/src/Symfony/Component/Serializer/Serializer.php +++ b/src/Symfony/Component/Serializer/Serializer.php @@ -13,8 +13,12 @@ use Symfony\Component\Serializer\Encoder\ChainDecoder; use Symfony\Component\Serializer\Encoder\ChainEncoder; +use Symfony\Component\Serializer\Encoder\ContextAwareDecoderInterface; +use Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface; use Symfony\Component\Serializer\Encoder\EncoderInterface; use Symfony\Component\Serializer\Encoder\DecoderInterface; +use Symfony\Component\Serializer\Normalizer\ContextAwareDenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface; use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; @@ -37,7 +41,7 @@ * @author Lukas Kahwe Smith * @author Kévin Dunglas */ -class Serializer implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface +class Serializer implements SerializerInterface, ContextAwareNormalizerInterface, ContextAwareDenormalizerInterface, ContextAwareEncoderInterface, ContextAwareDecoderInterface { /** * @var Encoder\ChainEncoder