Skip to content

Commit 9a2d19f

Browse files
feature #50558 [Serializer] Remove abstract uid denormalization code (fancyweb)
This PR was merged into the 7.0 branch. Discussion ---------- [Serializer] Remove abstract uid denormalization code | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Removes the code that was deprecated in #44721 Commits ------- 79028f9 [Serializer] Remove abstract uid denormalization code
2 parents 58217d2 + 79028f9 commit 9a2d19f

File tree

4 files changed

+16
-34
lines changed

4 files changed

+16
-34
lines changed

UPGRADE-7.0.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ Symfony 6.4 and Symfony 7.0 will be released simultaneously at the end of Novemb
55
release process, both versions will have the same features, but Symfony 7.0 won't include any deprecated features.
66
To upgrade, make sure to resolve all deprecation notices.
77

8-
This file will be updated on the branch 7.0 for each deprecated feature that is removed.
8+
Serializer
9+
----------
10+
11+
* Remove denormalization support for `AbstractUid` in `UidNormalizer`, use one of `AbstractUid` child class instead
12+
* Denormalizing to an abstract class in `UidNormalizer` now throws an `\Error`

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
7.0
5+
---
6+
7+
* Remove denormalization support for `AbstractUid` in `UidNormalizer`, use one of `AbstractUid` child class instead
8+
* Denormalizing to an abstract class in `UidNormalizer` now throws an `\Error`
9+
410
6.3
511
---
612

src/Symfony/Component/Serializer/Normalizer/UidNormalizer.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Serializer\Exception\LogicException;
1616
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1717
use Symfony\Component\Uid\AbstractUid;
18-
use Symfony\Component\Uid\Uuid;
1918

2019
final class UidNormalizer implements NormalizerInterface, DenormalizerInterface, CacheableSupportsMethodInterface
2120
{
@@ -70,32 +69,14 @@ public function supportsNormalization(mixed $data, string $format = null, array
7069
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
7170
{
7271
try {
73-
if (AbstractUid::class === $type) {
74-
trigger_deprecation('symfony/serializer', '6.1', 'Denormalizing to an abstract class in "%s" is deprecated.', __CLASS__);
75-
76-
return Uuid::fromString($data);
77-
}
78-
7972
return $type::fromString($data);
8073
} catch (\InvalidArgumentException|\TypeError) {
8174
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The data is not a valid "%s" string representation.', $type), $data, [Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
82-
} catch (\Error $e) { // @deprecated remove this catch block in 7.0
83-
if (str_starts_with($e->getMessage(), 'Cannot instantiate abstract class')) {
84-
return $this->denormalize($data, AbstractUid::class, $format, $context);
85-
}
86-
87-
throw $e;
8875
}
8976
}
9077

9178
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
9279
{
93-
if (AbstractUid::class === $type) {
94-
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);
95-
96-
return true;
97-
}
98-
9980
return is_subclass_of($type, AbstractUid::class, true);
10081
}
10182

src/Symfony/Component/Serializer/Tests/Normalizer/UidNormalizerTest.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,9 @@ public function testSupportsDenormalizationForNonUid()
146146
$this->assertFalse($this->normalizer->supportsDenormalization('foo', \stdClass::class));
147147
}
148148

149-
/**
150-
* @group legacy
151-
*/
152149
public function testSupportOurAbstractUid()
153150
{
154-
$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.');
155-
156-
$this->assertTrue($this->normalizer->supportsDenormalization('1ea6ecef-eb9a-66fe-b62b-957b45f17e43', AbstractUid::class));
151+
$this->assertFalse($this->normalizer->supportsDenormalization('1ea6ecef-eb9a-66fe-b62b-957b45f17e43', AbstractUid::class));
157152
}
158153

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

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

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

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy