8000 [Serializer] Remove abstract uid denormalization code by fancyweb · Pull Request #50558 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Remove abstract uid denormalization code #50558

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
Jun 5, 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
6 changes: 5 additions & 1 deletion UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ Symfony 6.4 and Symfony 7.0 will be released simultaneously at the end of Novemb
release process, both versions will have the same features, but Symfony 7.0 won't include any deprecated features.
To upgrade, make sure to resolve all deprecation notices.

This file will be updated on the branch 7.0 for each deprecated feature that is removed.
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`
6 changes: 6 additions & 0 deletions src/Symfony/Component/Seri 8000 alizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

7.0
---

* 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`

6.3
---

Expand Down
19 changes: 0 additions & 19 deletions src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Symfony\Component\Serializer\Exception\LogicException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Component\Uid\AbstractUid;
use Symfony\Component\Uid\Uuid;

final class UidNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
{
Expand Down Expand Up @@ -70,32 +69,14 @@ public function supportsNormalization(mixed $data, string $format = null, array
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
{
try {
if (AbstractUid::class === $type) {
trigger_deprecation('symfony/serializer', '6.1', 'Denormalizing to an abstract class in "%s" is deprecated.', __CLASS__);

return Uuid::fromString($data);
}

return $type::fromString($data);
} catch (\InvalidArgumentException|\TypeError) {
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The data is not a valid "%s" string representation.', $type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
} catch (\Error $e) { // @deprecated remove this catch block in 7.0
if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) {
return $this->denormalize($data, AbstractUid::class, $format, $context);
}

throw $e;
}
}

public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
{
if (AbstractUid::class === $type) {
trigger_deprecation('symfony/serializer', '6.1', 'Supporting denormalization for the "%s" type in "%s" is deprecated, use one of "%s" child class instead.', AbstractUid::class, __CLASS__, AbstractUid::class);

return true;
}

return is_subclass_of($type, AbstractUid::class, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,9 @@ public function testSupportsDenormalizationForNonUid()
$this->assertFalse($this->normalizer->supportsDenormalization('foo', \stdClass::class));
}

/**
* @group legacy
*/
public function testSupportOurAbstractUid()
{
$this->expectDeprecation('Since symfony/serializer 6.1: Supporting denormalization for the "Symfony\Component\Uid\AbstractUid" type in "Symfony\Component\Serializer\Normalizer\UidNormalizer" is deprecated, use one of "Symfony\Component\Uid\AbstractUid" child class instead.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the ExpectDeprecationTrait can be removed when expectDeprecation is not called.


$this->assertTrue($this->normalizer->supportsDenormalization('1ea6ecef-eb9a-66fe-b62b-957b45f17e43', AbstractUid::class));
$this->assertFalse($this->normalizer->supportsDenormalization('1ea6ecef-eb9a-66fe-b62b-957b45f17e43', AbstractUid::class));
}

public function testSupportCustomAbstractUid()
Expand All @@ -169,22 +164,18 @@ public function testDenormalize($uuidString, $class)
$this->assertEquals($class::fromString($uuidString), $this->normalizer->denormalize($uuidString, $class));
}

/**
* @group legacy
*/
public function testDenormalizeOurAbstractUid()
{
$this->expectDeprecation('Since symfony/serializer 6.1: Denormalizing to an abstract class in "Symfony\Component\Serializer\Normalizer\UidNormalizer" is deprecated.');
$this->expectException(\Error::class);
$this->expectExceptionMessage('Cannot call abstract method Symfony\Component\Uid\AbstractUid::fromString()');

$this->assertEquals(Uuid::fromString($uuidString = '1ea6ecef-eb9a-66fe-b62b-957b45f17e43'), $this->normalizer->denormalize($uuidString, AbstractUid::class));
}

/**
* @group legacy
*/
public function testDenormalizeCustomAbstractUid()
{
$this->expectDeprecation('Since symfony/serializer 6.1: Denormalizing to an abstract class in "Symfony\Component\Serializer\Normalizer\UidNormalizer" is deprecated.');
$this->expectException(\Error::class);
$this->expectExceptionMessage('Cannot instantiate abstract class Symfony\Component\Serializer\Tests\Normalizer\TestAbstractCustomUid');

$this->assertEquals(Uuid::fromString($uuidString = '1ea6ecef-eb9a-66fe-b62b-957b45f17e43'), $this->normalizer->denormalize($uuidString, TestAbstractCustomUid::class));
}
Expand Down
0