Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Revert deprecation of ContextAwareEncoderInterface and ContextAwareDecoderInterface #47150

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 1 commit into from
Aug 21, 2022
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
6 changes: 3 additions & 3 deletions .github/expected-missing-return-types.diff
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,11 @@ index f38069e471..0966eb3e89 100644
+ public function decode(string $data, string $format, array $context = []): mixed;

/**
@@ -45,4 +45,4 @@ interface DecoderInterface
@@ -44,4 +44,4 @@ interface DecoderInterface
* @return bool
*/
- public function supportsDecoding(string $format /* , array $context = [] */);
+ public function supportsDecoding(string $format /* , array $context = [] */): bool;
- public function supportsDecoding(string $format);
+ public function supportsDecoding(string $format): bool;
}
diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
index 44ba45f581..3398115497 100644
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ CHANGELOG
* Set `Context` annotation as not final
* Deprecate `ContextAwareNormalizerInterface`, use `NormalizerInterface` instead
* Deprecate `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
* Deprecate `ContextAwareEncoderInterface`, use `EncoderInterface` instead
* Deprecate `ContextAwareDecoderInterface`, use `DecoderInterface` instead
* Deprecate supporting denormalization for `AbstractUid` in `UidNormalizer`, use one of `AbstractUid` child class instead
* Deprecate denormalizing to an abstract class in `UidNormalizer`
* Add support for `can*()` methods to `ObjectNormalizer`
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Serializer/Encoder/ChainDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ private function getDecoder(string $format, array $context): DecoderInterface
return $this->decoders[$this->decoderByFormat[$format]];
}

$cache = true;
foreach ($this->decoders as $i => $decoder) {
$cache = $cache && !$decoder instanceof ContextAwareDecoderInterface;
if ($decoder->supportsDecoding($format, $context)) {
$this->decoderByFormat[$format] = $i;
if ($cache) {
$this->decoderByFormat[$format] = $i;
}

return $decoder;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Serializer/Encoder/ChainEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ private function getEncoder(string $format, array $context): EncoderInterface
return $this->encoders[$this->encoderByFormat[$format]];
}

$cache = true;
foreach ($this->encoders as $i => $encoder) {
$cache = $cache && !$encoder instanceof ContextAwareEncoderInterface;
if ($encoder->supportsEncoding($format, $context)) {
$this->encoderByFormat[$format] = $i;
if ($cache) {
$this->encoderByFormat[$format] = $i;
}

return $encoder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* Adds the support of an extra $context parameter for the supportsDecoding method.
*
* @author Kévin Dunglas <[email protected]>
*
* @deprecated since symfony/serializer 6.1, use DecoderInterface instead
*/
interface ContextAwareDecoderInterface extends DecoderInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
* Adds the support of an extra $context parameter for the supportsEncoding method.
*
* @author Kévin Dunglas <[email protected]>
*
* @deprecated since symfony/serializer 6.1, use EncoderInterface instead
*/
interface ContextAwareEncoderInterface extends EncoderInterface
{
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Serializer/Encoder/CsvEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@ public function encode(mixed $data, string $format, array $context = []): string

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsEncoding(string $format /* , array $context = [] */): bool
public function supportsEncoding(string $format): bool
{
return self::FORMAT === $format;
}
Expand Down Expand Up @@ -212,10 +210,8 @@ public function decode(string $data, string $format, array $context = []): mixed

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsDecoding(string $format /* , array $context = [] */): bool
public function supportsDecoding(string $format): bool
{
return self::FORMAT === $format;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ public function decode(string $data, string $format, array $context = []);
/**
* Checks whether the deserializer can decode from given format.
*
* @param string $format Format name
* @param array $context Options that decoders have access to
* @param string $format Format name
*
* @return bool
*/
public function supportsDecoding(string $format /* , array $context = [] */);
public function supportsDecoding(string $format);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public function encode(mixed $data, string $format, array $context = []): string
/**
* Checks whether the serializer can encode to given format.
*
* @param string $format Format name
* @param array $context Options that normalizers/encoders have access to
* @param string $format Format name
*/
public function supportsEncoding(string $format /* , array $context = [] */): bool;
public function supportsEncoding(string $format): bool;
}
4 changes: 1 addition & 3 deletions src/Symfony/Component/Serializer/Encoder/JsonDecode.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ public function decode(string $data, string $format, array $context = []): mixed

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsDecoding(string $format /* , array $context = [] */): bool
public function supportsDecoding(string $format): bool
{
return JsonEncoder::FORMAT === $format;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/Serializer/Encoder/JsonEncode.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@ public function encode(mixed $data, string $format, array $context = []): string

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsEncoding(string $format /* , array $context = [] */): bool
public function supportsEncoding(string $format): bool
{
return JsonEncoder::FORMAT === $format;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Serializer/Encoder/JsonEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,16 @@ public function decode(string $data, string $format, array $context = []): mixed

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsEncoding(string $format /* , array $context = [] */): bool
public function supportsEncoding(string $format): bool
{
return self::FORMAT === $format;
}

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsDecoding(string $format /* , array $context = [] */): bool
public function supportsDecoding(string $format): bool
{
return self::FORMAT === $format;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,16 @@ public function decode(string $data, string $format, array $context = []): mixed

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsEncoding(string $format /* , array $context = [] */): bool
public function supportsEncoding(string $format): bool
{
return self::FORMAT === $format;
}

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsDecoding(string $format /* , array $context = [] */): bool
public function supportsDecoding(string $format): bool
{
return self::FORMAT === $format;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Symfony/Component/Serializer/Encoder/YamlEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ public function encode(mixed $data, string $format, array $context = []): string

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsEncoding(string $format /* , array $context = [] */): bool
public function supportsEncoding(string $format): bool
{
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
}
Expand All @@ -87,10 +85,8 @@ public function decode(string $data, string $format, array $context = []): mixed

/**
* {@inheritdoc}
*
* @param array $context
*/
public function supportsDecoding(string $format /* , array $context = [] */): bool
public function supportsDecoding(string $format): bool
{
return self::FORMAT === $format || self::ALTERNATIVE_FORMAT === $format;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Encoder\ChainDecoder;
use Symfony\Component\Serializer\Encoder\ContextAwareDecoderInterface;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Exception\RuntimeException;

Expand All @@ -28,7 +29,7 @@ class ChainDecoderTest extends TestCase

protected function setUp(): void
{
$this->decoder1 = $this->createMock(DecoderInterface::class);
$this->decoder1 = $this->createMock(ContextAwareDecoderInterface::class);
$this->decoder1
->method('supportsDecoding')
->willReturnMap([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Serializer\Debug\TraceableEncoder;
use Symfony\Component\Serializer\Encoder\ChainEncoder;
use Symfony\Component\Serializer\Encoder\ContextAwareEncoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Encoder\NormalizationAwareInterface;
use Symfony\Component\Serializer\Exception\RuntimeException;
Expand All @@ -30,7 +31,7 @@ class ChainEncoderTest extends TestCase

protected function setUp(): void
{
$this->encoder1 = $this->createMock(EncoderInterface::class);
$this->encoder1 = $this->createMock(ContextAwareEncoderInterface::class);
$this->encoder1
->method('supportsEncoding')
->willReturnMap([
Expand Down Expand Up @@ -106,7 +107,7 @@ public function testNeedsNormalizationTraceableEncoder()

class NormalizationAwareEncoder implements EncoderInterface, NormalizationAwareInterface
{
public function supportsEncoding(string $format, array $context = []): bool
public function supportsEncoding(string $format): bool
{
return true;
}
Expand Down