Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Remove Doctrine annotations support #51080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
*/
#[\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 <[email protected]>
*/
#[\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 <[email protected]>
*/
#[\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 <[email protected]>
*/
#[\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 <[email protected]>
*/
#[\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 <[email protected]>
*/
#[\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 <[email protected]>
*/
#[\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.

Loading