@@ -95,29 +95,51 @@ public function loadClassMetadata(ClassMetadata $metadata)
95
95
*/
96
96
private function getAnnotations (object $ reflection ): iterable
97
97
{
98
+ $ dedup = [];
99
+
98
100
if (\PHP_VERSION_ID >= 80000 ) {
99
101
foreach ($ reflection ->getAttributes (GroupSequence::class) as $ attribute ) {
102
+ $ dedup [] = $ attribute ->newInstance ();
100
103
yield $ attribute ->newInstance ();
101
104
}
102
105
foreach ($ reflection ->getAttributes (GroupSequenceProvider::class) as $ attribute ) {
106
+ $ dedup [] = $ attribute ->newInstance ();
103
107
yield $ attribute ->newInstance ();
104
108
}
105
109
foreach ($ reflection ->getAttributes (Constraint::class, \ReflectionAttribute::IS_INSTANCEOF ) as $ attribute ) {
110
+ $ dedup [] = $ attribute ->newInstance ();
106
111
yield $ attribute ->newInstance ();
107
112
}
108
113
}
109
114
if (!$ this ->reader ) {
110
115
return ;
111
116
}
112
117
118
+ $ annotations = [];
119
+
113
120
if ($ reflection instanceof \ReflectionClass) {
114
- yield from $ this ->reader ->getClassAnnotations ($ reflection );
121
+ $ annotations = $ this ->reader ->getClassAnnotations ($ reflection );
115
122
}
116
123
if ($ reflection instanceof \ReflectionMethod) {
117
- yield from $ this ->reader ->getMethodAnnotations ($ reflection );
124
+ $ annotations = $ this ->reader ->getMethodAnnotations ($ reflection );
118
125
}
119
126
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
+ }
121
143
}
122
144
}
123
145
}
0 commit comments