8000 [Serializer] Give access to the context to support* methods by dunglas · Pull Request #19371 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Give access to the context to support* methods #19371

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove commented code
  • Loading branch information
dunglas committed Feb 13, 2017
commit 1de76098645d815aedaa3a6efbb6ba931862414a
5 changes: 2 additions & 3 deletions src/Symfony/Component/Serializer/Encoder/ChainDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @final since version 3.3.
*/
class ChainDecoder implements DecoderInterface/*, ContextAwareDecoderInterface*/
class ChainDecoder implements ContextAwareDecoderInterface
{
protected $decoders = array();
protected $decoderByFormat = array();
Expand All @@ -43,9 +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) {
Expand Down
8 changes: 3 additions & 5 deletions src/Symfony/Component/Serializer/Encoder/ChainEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @final since version 3.3.
*/
class ChainEncoder implements EncoderInterface/*, ContextAwareEncoderInterface*/
class ChainEncoder implements ContextAwareEncoderInterface
{
protected $encoders = array();
protected $encoderByFormat = array();
Expand All @@ -43,9 +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) {
Expand All @@ -63,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Alexander M. Turek <me@derrabus.de>
*/
class ArrayDenormalizer implements DenormalizerInterface, SerializerAwareInterface
class ArrayDenormalizer implements ContextAwareDenormalizerInterface, SerializerAwareInterface
{
/**
* @var SerializerInterface|DenormalizerInterface
Expand Down Expand Up @@ -64,10 +64,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);
}
Expand Down
22 changes: 9 additions & 13 deletions src/Symfony/Component/Serializer/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +41,7 @@
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
* @author Kévin Dunglas <dunglas@gmail.com>
*/
class Serializer implements SerializerInterface, NormalizerInterface, DenormalizerInterface, EncoderInterface, DecoderInterface
class Serializer implements SerializerInterface, ContextAwareNormalizerInterface, ContextAwareDenormalizerInterface , ContextAwareEncoderInterface, ContextAwareDecoderInterface
{
/**
* @var Encoder\ChainEncoder
Expand Down Expand Up @@ -177,20 +181,16 @@ public function denormalize($data, $type, $format = null, array $context = array
/**
* {@inheritdoc}
*/
public function supportsNormalization($data, $format = null/*, array $context = array()*/)
public function supportsNormalization($data, $format = null, array $context = array())
{
$context = 3 === func_num_args() ? func_get_arg(2) : array();

return null !== $this->getNormalizer($data, $format, $context);
}

/**
* {@inheritdoc}
*/ 91EA
public function supportsDenormalization($data, $type, $format = null/*, array $context = array()*/)
public function supportsDenormalization($data, $type, $format = null, array $context = array())
{
$context = 4 === func_num_args() ? func_get_arg(3) : array();

return null !== $this->getDenormalizer($data, $type, $format, $context);
}

Expand Down Expand Up @@ -276,20 +276,16 @@ private function denormalizeObject($data, $class, $format, array $context = arra
/**
* {@inheritdoc}
*/
public function supportsEncoding($format/*, array $context = array()*/)
public function supportsEncoding($format, array $context = array())
{
$context = 2 === func_num_args() ? func_get_arg(1) : array();

return $this->encoder->supportsEncoding($format, $context);
}

/**
* {@inheritdoc}
*/
public function supportsDecoding($format/*, array $context = array()*/)
public function supportsDecoding($format, array $context = array())
{
$context = 2 === func_num_args() ? func_get_arg(1) : array();

return $this->decoder->supportsDecoding($format, $context);
}
}
0