Skip to content
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

[Serializer] Remove BC layer #50736

Merged
merged 1 commit into from
Jun 30, 2023
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
61 changes: 30 additions & 31 deletions .github/expected-missing-return-types.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11912,84 +11912,83 @@ index b684fddb2f..ade2242791 100644
{
return $this->data;
diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
index 079b1e7a9e..e3cfe43e67 100644
index efe4a6e0e1..fbf291af7e 100644
--- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
@@ -221,5 +221,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
@@ -211,5 +211,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
* @throws LogicException if the 'allow_extra_attributes' context variable is false and no class metadata factory is provided
*/
- protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false)
+ protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false): array|bool
{
$allowExtraAttributes = $context[self::ALLOW_EXTRA_ATTRIBUTES] ?? $this->defaultContext[self::ALLOW_EXTRA_ATTRIBUTES];
@@ -271,5 +271,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
@@ -261,5 +261,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
* @return bool
*/
- protected function isAllowedAttribute(object|string $classOrObject, string $attribute, string $format = null, array $context = [])
+ protected function isAllowedAttribute(object|string $classOrObject, string $attribute, string $format = null, array $context = []): bool
{
$ignoredAttributes = $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES];
@@ -322,5 +322,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
@@ -312,5 +312,5 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
* @throws MissingConstructorArgumentsException
*/
- protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null)
+ protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null): object
{
if (null !== $object = $this->extractObjectToPopulate($class, $context, self::OBJECT_TO_POPULATE)) {
diff --git a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
index 0dba039bc0..576445825e 100644
index 4f061239b9..85c9f17a83 100644
--- a/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+++ b/src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
@@ -143,5 +143,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -141,5 +141,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return bool
*/
- public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */)
+ public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */): bool
- public function supportsNormalization(mixed $data, string $format = null, array $context = [])
+ public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
{
return \is_object($data) && !$data instanceof \Traversable;
@@ -151,5 +151,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -149,5 +149,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return array|string|int|float|bool|\ArrayObject|null
*/
- public function normalize(mixed $object, string $format = null, array $context = [])
+ public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
{
if (!isset($context['cache_key'])) {
@@ -235,5 +235,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -233,5 +233,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return object
*/
- protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null)
+ protected function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, array|bool $allowedAttributes, string $format = null): object
{
if ($class !== $mappedClass = $this->getMappedClass($data, $class, $context)) {
@@ -286,5 +286,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -284,5 +284,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return string[]
*/
- abstract protected function extractAttributes(object $object, string $format = null, array $context = []);
+ abstract protected function extractAttributes(object $object, string $format = null, array $context = []): array;

/**
@@ -293,5 +293,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -291,10 +291,10 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return mixed
*/
- abstract protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []);
+ abstract protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []): mixed;

/**
@@ -300,5 +300,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return bool
*/
- public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */)
+ public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */): bool
- public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = [])
+ public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
{
return class_exists($type) || (interface_exists($type, false) && null !== $this->classDiscriminatorResolver?->getMappingForClass($type));
@@ -308,5 +308,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -304,5 +304,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return mixed
*/
- public function denormalize(mixed $data, string $type, string $format = null, array $context = [])
+ public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
{
if (!isset($context['cache_key'])) {
@@ -414,5 +414,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
@@ -410,5 +410,5 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
* @return void
*/
- abstract protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []);
Expand Down Expand Up @@ -12017,7 +12016,7 @@ index 48e8c3fb54..a71c3ea476 100644
+ public function setDenormalizer(DenormalizerInterface $denormalizer): void;
}
diff --git a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php
index 4edb70096d..8c844785db 100644
index e4d0ed9123..8a39d97f36 100644
--- a/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php
+++ b/src/Symfony/Component/Serializer/Normalizer/DenormalizerInterface.php
@@ -47,5 +47,5 @@ interface DenormalizerInterface
Expand All @@ -12027,18 +12026,18 @@ index 4edb70096d..8c844785db 100644
+ public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed;

/**
@@ -59,5 +59,5 @@ interface DenormalizerInterface
@@ -58,5 +58,5 @@ interface DenormalizerInterface
* @return bool
*/
- public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */);
+ public function supportsDenormalization(mixed $data, string $type, string $format = null /* , array $context = [] */): bool;
- public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []);
+ public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool;

/**
diff --git a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
index 063d34ea59..fb10337d35 100644
index 3d11567a7b..22e873b151 100644
--- a/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
+++ b/src/Symfony/Component/Serializer/Normalizer/GetSetMethodNormalizer.php
@@ -147,5 +147,5 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
@@ -131,5 +131,5 @@ class GetSetMethodNormalizer extends AbstractObjectNormalizer
* @return void
*/
- protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])
Expand Down Expand Up @@ -12067,7 +12066,7 @@ index 40a4fa0e8c..a1e2749aae 100644
{
$this->normalizer = $normalizer;
diff --git a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php
index 40779de316..105cf99b06 100644
index 01979d6fcf..e918540c83 100644
--- a/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php
+++ b/src/Symfony/Component/Serializer/Normalizer/NormalizerInterface.php
@@ -39,5 +39,5 @@ interface NormalizerInterface
Expand All @@ -12077,29 +12076,29 @@ index 40779de316..105cf99b06 100644
+ public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null;

/**
@@ -50,5 +50,5 @@ interface NormalizerInterface
@@ -49,5 +49,5 @@ interface NormalizerInterface
* @return bool
*/
- public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */);
+ public function supportsNormalization(mixed $data, string $format = null /* , array $context = [] */): bool;
- public function supportsNormalization(mixed $data, string $format = null, array $context = []);
+ public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool;

/**
diff --git a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
index 357c36426e..f4423f47f4 100644
index af530f8d3d..dd672812f1 100644
--- a/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
+++ b/src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
@@ -146,5 +146,5 @@ class ObjectNormalizer extends AbstractObjectNormalizer
@@ -136,5 +136,5 @@ class ObjectNormalizer extends AbstractObjectNormalizer
* @return void
*/
- protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])
+ protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = []): void
{
try {
diff --git a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
index ec12db9bb2..d3b7f036a8 100644
index cfe93bc10b..7f1d8e5e13 100644
--- a/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
+++ b/src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php
@@ -187,5 +187,5 @@ class PropertyNormalizer extends AbstractObjectNormalizer
@@ -171,5 +171,5 @@ class PropertyNormalizer extends AbstractObjectNormalizer
* @return void
*/
- protected function setAttributeValue(object $object, string $attribute, mixed $value, string $format = null, array $context = [])
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,9 @@ Serializer

* Remove denormalization support for `AbstractUid` in `UidNormalizer`, use one of `AbstractUid` child class instead
* Denormalizing to an abstract class in `UidNormalizer` now throws an `\Error`
* Remove `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
* Remove `ContextAwareNormalizerInterface`, use `NormalizerInterface` instead
* Remove `CacheableSupportsMethodInterface`, use `NormalizerInterface` and `DenormalizerInterface` instead
* First argument of `ClassMetadata::setSerializedName()` is now required
* Third argument `array $context = []` of the `NormalizerInterface::supportsNormalization()` is now required
* Fourth argument `array $context = []` of the `DenormalizerInterface::supportsDenormalization()` is now required
6 changes: 6 additions & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ CHANGELOG

* Remove denormalization support for `AbstractUid` in `UidNormalizer`, use one of `AbstractUid` child class instead
* Denormalizing to an abstract class in `UidNormalizer` now throws an `\Error`
* Remove `ContextAwareDenormalizerInterface`, use `DenormalizerInterface` instead
* Remove `ContextAwareNormalizerInterface`, use `NormalizerInterface` instead
* Remove `CacheableSupportsMethodInterface`, use `NormalizerInterface` and `DenormalizerInterface` instead
* First argument of `ClassMetadata::setSerializedName()` is now required
* Third argument `array $context = []` of the `NormalizerInterface::supportsNormalization()` is now required
* Fourth argument `array $context = []` of the `DenormalizerInterface::supportsDenormalization()` is now required

6.3
---
Expand Down
21 changes: 1 addition & 20 deletions src/Symfony/Component/Serializer/Debug/TraceableNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Component\Serializer\Debug;

use Symfony\Component\Serializer\DataCollector\SerializerDataCollector;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
Expand All @@ -27,24 +26,16 @@
*
* @internal
*/
class TraceableNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, NormalizerAwareInterface, DenormalizerAwareInterface, CacheableSupportsMethodInterface
class TraceableNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, NormalizerAwareInterface, DenormalizerAwareInterface
{
public function __construct(
private NormalizerInterface|DenormalizerInterface $normalizer,
private SerializerDataCollector $dataCollector,
) {
if (!method_exists($normalizer, 'getSupportedTypes')) {
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "NormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($normalizer));
}
}

public function getSupportedTypes(?string $format): array
{
// @deprecated remove condition in 7.0
if (!method_exists($this->normalizer, 'getSupportedTypes')) {
return ['*' => $this->normalizer instanceof CacheableSupportsMethodInterface && $this->normalizer->hasCacheableSupportsMethod()];
}

return $this->normalizer->getSupportedTypes($format);
}

Expand Down Expand Up @@ -127,16 +118,6 @@ public function setDenormalizer(DenormalizerInterface $denormalizer): void
$this->normalizer->setDenormalizer($denormalizer);
}

/**
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
*/
public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return $this->normalizer instanceof CacheableSupportsMethodInterface && $this->normalizer->hasCacheableSupportsMethod();
}

/**
* Proxies all method calls to the original normalizer.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\Serializer\DataCollector\SerializerDataCollector;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\SerializerInterface;
Expand All @@ -34,9 +33,6 @@ public function __construct(
private SerializerInterface&NormalizerInterface&DenormalizerInterface&EncoderInterface&DecoderInterface $serializer,
private SerializerDataCollector $dataCollector,
) {
if (!method_exists($serializer, 'getSupportedTypes')) {
trigger_deprecation('symfony/serializer', '6.3', 'Not implementing the "NormalizerInterface::getSupportedTypes()" in "%s" is deprecated.', get_debug_type($serializer));
}
}

public function serialize(mixed $data, string $format, array $context = []): string
Expand Down Expand Up @@ -131,11 +127,6 @@ public function decode(string $data, string $format, array $context = []): mixed

public function getSupportedTypes(?string $format): array
{
// @deprecated remove condition in 7.0
if (!method_exists($this->serializer, 'getSupportedTypes')) {
return ['*' => $this->serializer instanceof CacheableSupportsMethodInterface && $this->serializer->hasCacheableSupportsMethod()];
}

return $this->serializer->getSupportedTypes($format);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,8 @@ public function getMaxDepth(): ?int
return $this->maxDepth;
}

public function setSerializedName(string $serializedName = null): void
public function setSerializedName(?string $serializedName): void
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/serializer', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}

$this->serializedName = $serializedName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,8 @@ public function getClassDiscriminatorMapping(): ?ClassDiscriminatorMapping
return $this->classDiscriminatorMapping;
}

public function setClassDiscriminatorMapping(ClassDiscriminatorMapping $mapping = null): void
public function setClassDiscriminatorMapping(?ClassDiscriminatorMapping $mapping): void
{
if (1 > \func_num_args()) {
trigger_deprecation('symfony/serializer', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
}
$this->classDiscriminatorMapping = $mapping;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface, CacheableSupportsMethodInterface
abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
{
use ObjectToPopulateTrait;
use SerializerAwareTrait;
Expand Down Expand Up @@ -156,16 +156,6 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
}
}

/**
* @deprecated since Symfony 6.3, use "getSupportedTypes()" instead
*/
public function hasCacheableSupportsMethod(): bool
{
trigger_deprecation('symfony/serializer', '6.3', 'The "%s()" method is deprecated, use "getSupportedTypes()" instead.', __METHOD__);

return false;
}

/**
* Detects if the configured circular reference limit is reached.
*
Expand Down
Loading