8000 [Serializer] Remove abstract uid denormalization code · symfony/symfony@1112805 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1112805

Browse files
committed
[Serializer] Remove abstract uid denormalization code
1 parent 14431f1 commit 1112805

File tree

4 files changed

+16
-33
lines changed

4 files changed

+16
-33
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 & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,32 +70,14 @@ public function supportsNormalization(mixed $data, string $format = null, array
7070
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): mixed
7171
{
7272
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-
7973
return $type::fromString($data);
8074
} catch (\InvalidArgumentException|\TypeError) {
8175
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;
8876
}
8977
}
9078

9179
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
9280
{
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-
9981
return is_subclass_of($type, AbstractUid::class, true);
10082
}
10183

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)
0