Skip to content

Commit 25ca8e5

Browse files
bug #50524 Fix Doctrine deprecations (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- Fix Doctrine deprecations | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #50481 | License | MIT | Doc PR | - Commits ------- 6a3a4d7fb7 Fix Doctrine deprecations
2 parents 9746096 + 81772c1 commit 25ca8e5

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

Mapping/ClassMetadata.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,17 @@ public function mergeConstraints(self $source)
356356
$constraint->addImplicitGroupName($this->getDefaultGroup());
357357
}
358358

359-
$this->addPropertyMetadata($member);
360-
361359
if ($member instanceof MemberMetadata && !$member->isPrivate($this->name)) {
362360
$property = $member->getPropertyName();
361+
$this->members[$property] = [$member];
363362

364-
if ($member instanceof PropertyMetadata && !isset($this->properties[$property])) {
363+
if ($member instanceof PropertyMetadata) {
365364
$this->properties[$property] = $member;
366-
} elseif ($member instanceof GetterMetadata && !isset($this->getters[$property])) {
365+
} elseif ($member instanceof GetterMetadata) {
367366
$this->getters[$property] = $member;
368367
}
368+
} else {
369+
$this->addPropertyMetadata($member);
369370
}
370371
}
371372
}

Mapping/Loader/AnnotationLoader.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,51 @@ public function loadClassMetadata(ClassMetadata $metadata)
9595
*/
9696
private function getAnnotations(object $reflection): iterable
9797
{
98+
$dedup = [];
99+
98100
if (\PHP_VERSION_ID >= 80000) {
99101
foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) {
102+
$dedup[] = $attribute->newInstance();
100103
yield $attribute->newInstance();
101104
}
102105
foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) {
106+
$dedup[] = $attribute->newInstance();
103107
yield $attribute->newInstance();
104108
}
105109
foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
110+
$dedup[] = $attribute->newInstance();
106111
yield $attribute->newInstance();
107112
}
108113
}
109114
if (!$this->reader) {
110115
return;
111116
}
112117

118+
$annotations = [];
119+
113120
if ($reflection instanceof \ReflectionClass) {
114-
yield from $this->reader->getClassAnnotations($reflection);
121+
$annotations = $this->reader->getClassAnnotations($reflection);
115122
}
116123
if ($reflection instanceof \ReflectionMethod) {
117-
yield from $this->reader->getMethodAnnotations($reflection);
124+
$annotations = $this->reader->getMethodAnnotations($reflection);
118125
}
119126
if ($reflection instanceof \ReflectionProperty) {
120-
yield from $this->reader->getPropertyAnnotations($reflection);
127+
$annotations = $this->reader->getPropertyAnnotations($reflection);
128+
}
129+
130+
foreach ($dedup as $annotation) {
131+
if ($annotation instanceof Constraint) {
132+
$annotation->groups; // trigger initialization of the "groups" property
133+
}
134+
}
135+
136+
foreach ($annotations as $annotation) {
137+
if ($annotation instanceof Constraint) {
138+
$annotation->groups; // trigger initialization of the "groups" property
139+
}
140+
if (!\in_array($annotation, $dedup, false)) {
141+
yield $annotation;
142+
}
121143
}
122144
}
123145
}

0 commit comments

Comments
 (0)