Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b16f3a

Browse filesBrowse files
committed
bug #52867 [Validator] Only trigger deprecation when Validator annotations are used (HypeMC)
This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Only trigger deprecation when Validator annotations are used | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #52828 | License | MIT The deprecations are now triggered only if one of the annotations is from the validator component. Commits ------- 83a8cad [Validator] Only trigger deprecation when Validator annotations are used
2 parents b6ae3aa + 83a8cad commit 4b16f3a
Copy full SHA for 4b16f3a

File tree

2 files changed

+44
-3
lines changed
Filter options

2 files changed

+44
-3
lines changed

‎src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/Loader/AnnotationLoader.php
+17-3Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,13 @@ private function getAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionPr
118118
$annotations = [];
119119

120120
if ($reflection instanceof \ReflectionClass && $annotations = $this->reader->getClassAnnotations($reflection)) {
121-
trigger_deprecation('symfony/validator', '6.4', 'Class "%s" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getName());
121+
$this->triggerDeprecationIfAnnotationIsUsed($annotations, sprintf('Class "%s"', $reflection->getName()));
122122
}
123123
if ($reflection instanceof \ReflectionMethod && $annotations = $this->reader->getMethodAnnotations($reflection)) {
124-
trigger_deprecation('symfony/validator', '6.4', 'Method "%s::%s()" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getDeclaringClass()->getName(), $reflection->getName());
124+
$this->triggerDeprecationIfAnnotationIsUsed($annotations, sprintf('Method "%s::%s()"', $reflection->getDeclaringClass()->getName(), $reflection->getName()));
125125
}
126126
if ($reflection instanceof \ReflectionProperty && $annotations = $this->reader->getPropertyAnnotations($reflection)) {
127-
trigger_deprecation('symfony/validator', '6.4', 'Property "%s::$%s" uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $reflection->getDeclaringClass()->getName(), $reflection->getName());
127+
$this->triggerDeprecationIfAnnotationIsUsed($annotations, sprintf('Property "%s::$%s"', $reflection->getDeclaringClass()->getName(), $reflection->getName()));
128128
}
129129

130130
foreach ($dedup as $annotation) {
@@ -142,4 +142,18 @@ private function getAnnotations(\ReflectionMethod|\ReflectionClass|\ReflectionPr
142142
}
143143
}
144144
}
145+
146+
private function triggerDeprecationIfAnnotationIsUsed(array $annotations, string $messagePrefix): void
147+
{
148+
foreach ($annotations as $annotation) {
149+
if (
150+
$annotation instanceof Constraint
151+
|| $annotation instanceof GroupSequence
152+
|| $annotation instanceof GroupSequenceProvider
153+
) {
154+
trigger_deprecation('symfony/validator', '6.4', sprintf('%s uses Doctrine Annotations to configure validation constraints, which is deprecated. Use PHP attributes instead.', $messagePrefix));
155+
break;
156+
}
157+
}
158+
}
145159
}

‎src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithHybridAnnotationsTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Mapping/Loader/AnnotationLoaderWithHybridAnnotationsTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Doctrine\Common\Annotations\AnnotationReader;
1515
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
16+
use Symfony\Component\Validator\Constraints\NotBlank;
17+
use Symfony\Component\Validator\Mapping\ClassMetadata;
1618
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
1719

1820
/**
@@ -46,6 +48,14 @@ public function testLoadClassMetadataAndMerge()
4648
parent::testLoadClassMetadataAndMerge();
4749
}
4850

51+
public function testLoadClassMetadataWithOtherAnnotations()
52+
{
53+
$loader = $this->createAnnotationLoader();
54+
$metadata = new ClassMetadata(EntityWithOtherAnnotations::class);
55+
56+
$this->assertTrue($loader->loadClassMetadata($metadata));
57+
}
58+
4959
protected function createAnnotationLoader(): AnnotationLoader
5060
{
5161
return new AnnotationLoader(new AnnotationReader());
@@ -56,3 +66,20 @@ protected function getFixtureNamespace(): string
5666
return 'Symfony\Component\Validator\Tests\Fixtures\Attribute';
5767
}
5868
}
69+
70+
/**
71+
* @Annotation
72+
* @Target({"PROPERTY"})
73+
*/
74+
class SomeAnnotation
75+
{
76+
}
77+
78+
class EntityWithOtherAnnotations
79+
{
80+
/**
81+
* @SomeAnnotation
82+
*/
83+
#[NotBlank]
84+
public ?string $name = null;
85+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.