Skip to content

Commit

Permalink
[Serializer] Remove Doctrine annotations support
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Jul 24, 2023
1 parent 5958047 commit 67013e2
Show file tree
Hide file tree
Showing 33 changed files with 57 additions and 1,082 deletions.
2 changes: 2 additions & 0 deletions UPGRADE-7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ Serializer

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

Translation
-----------
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Serializer/Annotation/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @Context().
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "METHOD"})
*
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @DiscriminatorMap().
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"CLASS"})
*
* @author Samuel Roze <samuel.roze@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_CLASS)]
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Serializer/Annotation/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @Groups().
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "METHOD"})
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
Expand Down
5 changes: 0 additions & 5 deletions src/Symfony/Component/Serializer/Annotation/Ignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
namespace Symfony\Component\Serializer\Annotation;

/**
* Annotation class for @Ignore().
*
* @Annotation
* @Target({"PROPERTY", "METHOD"})
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
Expand Down
6 changes: 0 additions & 6 deletions src/Symfony/Component/Serializer/Annotation/MaxDepth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @MaxDepth().
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "METHOD"})
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @SerializedName().
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "METHOD"})
*
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
use Symfony\Component\Serializer\Exception\InvalidArgumentException;

/**
* Annotation class for @SerializedPath().
*
* @Annotation
* @NamedArgumentConstructor
* @Target({"PROPERTY", "METHOD"})
*
* @author Tobias Bönner <tobi@boenner.family>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ CHANGELOG
* Remove `CacheableSupportsMethodInterface`, use `NormalizerInterface` and `DenormalizerInterface` instead
* Require explicit argument when calling `AttributeMetadata::setSerializedName()` and `ClassMetadata::setClassDiscriminatorMapping()`
* Add argument `$context` to `NormalizerInterface::supportsNormalization()` and `DenormalizerInterface::supportsDenormalization()`
* Remove Doctrine annotations support in favor of native attributes
* Remove the annotation reader parameter from the constructor of `AnnotationLoader`

6.4
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Serializer\Mapping\Loader;

use Doctrine\Common\Annotations\Reader;
use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
Expand Down Expand Up @@ -43,14 +42,6 @@ class AnnotationLoader implements LoaderInterface
Context::class,
];

public function __construct(
private readonly ?Reader $reader = null,
) {
if ($reader) {
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__);
}
}

public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
{
$reflectionClass = $classMetadata->getReflectionClass();
Expand Down Expand Up @@ -187,20 +178,6 @@ public function loadAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionPr
}
}
}

if (null === $this->reader) {
return;
}

if ($reflector instanceof \ReflectionClass) {
yield from $this->getClassAnnotations($reflector);
}
if ($reflector instanceof \ReflectionMethod) {
yield from $this->getMethodAnnotations($reflector);
}
if ($reflector instanceof \ReflectionProperty) {
yield from $this->getPropertyAnnotations($reflector);
}
}

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

return false;
}

/**
* @return object[]
*/
private function getClassAnnotations(\ReflectionClass $reflector): array
{
if ($annotations = array_filter(
$this->reader->getClassAnnotations($reflector),
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
)) {
trigger_deprecation('symfony/serializer', '6.4', 'Class "%s" uses Doctrine Annotations to configure serialization, which is deprecated. Use PHP attributes instead.', $reflector->getName());
}

return $annotations;
}

/**
* @return object[]
*/
private function getMethodAnnotations(\ReflectionMethod $reflector): array
{
if ($annotations = array_filter(
$this->reader->getMethodAnnotations($reflector),
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
)) {
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());
}

return $annotations;
}

/**
* @return object[]
*/
private function getPropertyAnnotations(\ReflectionProperty $reflector): array
{
if ($annotations = array_filter(
$this->reader->getPropertyAnnotations($reflector),
fn (object $annotation): bool => $this->isKnownAttribute($annotation::class),
)) {
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());
}

return $annotations;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 67013e2

Please sign in to comment.