8000 [Serializer] Remove Doctrine annotations support · symfony/symfony@67013e2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67013e2

Browse files
committed
[Serializer] Remove Doctrine annotations support
1 parent 5958047 commit 67013e2

33 files changed

+57
-1082
lines changed

UPGRADE-7.0.md

+2
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ Serializer
290290

291291
* Require explicit argument when calling `AttributeMetadata::setSerializedName()` and `ClassMetadata::setClassDiscriminatorMapping()`
292292
* Add argument `$context` to `NormalizerInterface::supportsNormalization()` and `DenormalizerInterface::supportsDenormalization()`
293+
* Remove Doctrine annotations support in favor of native attributes
294+
* Remove the annotation reader parameter from the constructor of `AnnotationLoader`
293295

294296
Translation
295297
-----------

src/Symfony/Component/Serializer/Annotation/Context.php

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1515

1616
/**
17-
* Annotation class for @Context().
18-
*
19-
* @Annotation
20-
* @NamedArgumentConstructor
21-
* @Target({"PROPERTY", "METHOD"})
22-
*
2317
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
2418
*/
2519
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]

src/Symfony/Component/Serializer/Annotation/DiscriminatorMap.php

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1515

1616
/**
17-
* Annotation class for @DiscriminatorMap().
18-
*
19-
* @Annotation
20-
* @NamedArgumentConstructor
21-
* @Target({"CLASS"})
22-
*
2317
* @author Samuel Roze <samuel.roze@gmail.com>
2418
*/
2519
#[\Attribute(\Attribute::TARGET_CLASS)]

src/Symfony/Component/Serializer/Annotation/Groups.php

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1515

1616
/**
17-
* Annotation class for @Groups().
18-
*
19-
* @Annotation
20-
* @NamedArgumentConstructor
21-
* @Target({"PROPERTY", "METHOD"})
22-
*
2317
* @author Kévin Dunglas <dunglas@gmail.com>
2418
*/
2519
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]

src/Symfony/Component/Serializer/Annotation/Ignore.php

-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
namespace Symfony\Component\Serializer\Annotation;
1313

1414
/**
15-
* Annotation class for @Ignore().
16-
*
17-
* @Annotation
18-
* @Target({"PROPERTY", "METHOD"})
19-
*
2015
* @author Kévin Dunglas <dunglas@gmail.com>
2116
*/
2217
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]

src/Symfony/Component/Serializer/Annotation/MaxDepth.php

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1515

1616
/**
17-
* Annotation class for @MaxDepth().
18-
*
19-
* @Annotation
20-
* @NamedArgumentConstructor
21-
* @Target({"PROPERTY", "METHOD"})
22-
*
2317
* @author Kévin Dunglas <dunglas@gmail.com>
2418
*/
2519
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]

src/Symfony/Component/Serializer/Annotation/SerializedName.php

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@
1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1515

1616
/**
17-
* Annotation class for @SerializedName().
18-
*
19-
* @Annotation
20-
* @NamedArgumentConstructor
21-
* @Target({"PROPERTY", "METHOD"})
22-
*
2317
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
2418
*/
2519
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]

src/Symfony/Component/Serializer/Annotation/SerializedPath.php

-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1717

1818
/**
19-
* Annotation class for @SerializedPath().
20-
*
21-
* @Annotation
22-
* @NamedArgumentConstructor
23-
* @Target({"PROPERTY", "METHOD"})
24-
*
2519
* @author Tobias Bönner <tobi@boenner.family>
2620
*/
2721
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]

src/Symfony/Component/Serializer/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ CHANGELOG
1212
* Remove `CacheableSupportsMethodInterface`, use `NormalizerInterface` and `DenormalizerInterface` instead
1313
* Require explicit argument when calling `AttributeMetadata::setSerializedName()` and `ClassMetadata::setClassDiscriminatorMapping()`
1414
* Add argument `$context` to `NormalizerInterface::supportsNormalization()` and `DenormalizerInterface::supportsDenormalization()`
15+
* Remove Doctrine annotations support in favor of native attributes
16+
* Remove the annotation reader parameter from the constructor of `AnnotationLoader`
1517

1618
6.4
1719
---

src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

-68
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Serializer\Mapping\Loader;
1313

14-
use Doctrine\Common\Annotations\Reader;
1514
use Symfony\Component\Serializer\Annotation\Context;
1615
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
1716
use Symfony\Component\Serializer\Annotation\Groups;
@@ -43,14 +42,6 @@ class AnnotationLoader implements LoaderInterface
4342
Context::class,
4443
];
4544

46-
public function __construct(
47-
private readonly ?Reader $reader = null,
48-
) {
49-
if ($reader) {
50-
trigger_deprecation('symfony/validator', '6.4', 'Passing a "%s" instance as argument 1 to "%s()" is deprecated, pass null or omit the parameter instead.', get_debug_type($reader), __METHOD__);
51-
}
52-
}
53-
5445
public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
5546
{
5647
$reflectionClass = $classMetadata->getReflectionClass();
@@ -187,20 +178,6 @@ public function loadAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionPr
187178
}
188179
}
189180
}
190-
191-
if (null === $this->reader) {
192-
return;
193-
}
194-
195-
if ($reflector instanceof \ReflectionClass) {
196-
yield from $this->getClassAnnotations($reflector);
197-
}
198-
if ($reflector instanceof \ReflectionMethod) {
199-
yield from $this->getMethodAnnotations($reflector);
200-
}
201-
if ($reflector instanceof \ReflectionProperty) {
202-
yield from $this->getPropertyAnnotations($reflector);
203-
}
204181
}
205182

206183
private function setAttributeContextsForGroups(Context $annotation, AttributeMetadataInterface $attributeMetadata): void
@@ -229,49 +206,4 @@ private function isKnownAttribute(string $attributeName): bool
229206

230207
return false;
231208
}
232-
233-
/**
234-
* @return object[]
235-
*/
236-
private function getClassAnnotations(\ReflectionClass $reflector): array
237-
{
238-
if ($annotations = array_filter(
239-
$this->reader->getClassAnnotations($reflector),
240-
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
241-
)) {
242-
trigger_deprecation('symfony/serializer', '6.4', 'Class "%s" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getName());
243-
}
244-
245-
return $annotations;
246-
}
247-
248-
/**
249-
* @return object[]
250-
*/
251-
10000 private function getMethodAnnotations(\ReflectionMethod $reflector): array
252-
{
253-
if ($annotations = array_filter(
254-
$this->reader->getMethodAnnotations($reflector),
255-
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
256-
)) {
257-
trigger_deprecation('symfony/serializer', '6.4', 'Method "%s::%s()" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getDeclaringClass()->getName(), $reflector->getName());
258-
}
259-
260-
return $annotations;
261-
}
262-
263-
/**
264-
* @return object[]
265-
*/
266-
private function getPropertyAnnotations(\ReflectionProperty $reflector): array
267-
{
268-
if ($annotations = array_filter(
269-
$this->reader->getPropertyAnnotations($reflector),
270-
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
271-
)) {
272-
trigger_deprecation('symfony/serializer', '6.4', 'Property "%s::$%s" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getDeclaringClass()->getName(), $reflector->getName());
273-
}
274-
275-
return $annotations;
276-
}
277209
}

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/AbstractDummy.php

-31
This file was deleted.

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/AbstractDummyFirstChild.php

-39
This file was deleted.

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/AbstractDummySecondChild.php

-39
This file was deleted.

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/AbstractDummyThirdChild.php

-16
This file was deleted.

src/Symfony/Component/Serializer/Tests/Fixtures/Annotations/BadMethodContextDummy.php

-28
This file was deleted.

0 commit comments

Comments
 (0)
0