Skip to content

Commit 297cc32

Browse files
feature #51080 [Serializer] Remove Doctrine annotations support (derrabus)
This PR was merged into the 7.0 branch. Discussion ---------- [Serializer] Remove Doctrine annotations support | Q | A | ------------- | --- | Branch? | 7.0 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Follows #50983 | License | MIT | Doc PR | symfony/symfony-docs#18589 Commits ------- 67013e2 [Serializer] Remove Doctrine annotations support
2 parents a8feaec + 67013e2 commit 297cc32

33 files changed

+57
-1082
lines changed

UPGRADE-7.0.md

Lines changed: 2 additions & 0 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 0 additions & 6 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 0 additions & 68 deletions
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-
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
}

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