@@ -58,23 +58,12 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
58
58
$ attributesMetadata = $ classMetadata ->getAttributesMetadata ();
59
59
60
60
foreach ($ this ->loadAttributes ($ reflectionClass ) as $ annotation ) {
61
- if ($ annotation instanceof DiscriminatorMap) {
62
- $ classMetadata ->setClassDiscriminatorMapping (new ClassDiscriminatorMapping (
63
- $ annotation ->getTypeProperty (),
64
- $ annotation ->getMapping ()
65
- ));
66
- continue ;
67
- }
68
-
69
- if ($ annotation instanceof Groups) {
70
- $ classGroups = $ annotation ->getGroups ();
71
-
72
- continue ;
73
- }
74
-
75
- if ($ annotation instanceof Context) {
76
- $ classContextAnnotation = $ annotation ;
77
- }
61
+ match (true ) {
62
+ $ annotation instanceof DiscriminatorMap => $ classMetadata ->setClassDiscriminatorMapping (new ClassDiscriminatorMapping ($ annotation ->getTypeProperty (), $ annotation ->getMapping ())),
63
+ $ annotation instanceof Groups => $ classGroups = $ annotation ->getGroups (),
64
+ $ annotation instanceof Context => $ classContextAnnotation = $ annotation ,
65
+ default => null ,
66
+ };
78
67
}
79
68
80
69
foreach ($ reflectionClass ->getProperties () as $ property ) {
@@ -83,33 +72,35 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata): bool
83
72
$ classMetadata ->addAttributeMetadata ($ attributesMetadata [$ property ->name ]);
84
73
}
85
74
75
+ $ attributeMetadata = $ attributesMetadata [$ property ->name ];
86
76
if ($ property ->getDeclaringClass ()->name === $ className ) {
87
77
if ($ classContextAnnotation ) {
88
- $ this ->setAttributeContextsForGroups ($ classContextAnnotation , $ attributesMetadata [ $ property -> name ] );
78
+ $ this ->setAttributeContextsForGroups ($ classContextAnnotation , $ attributeMetadata );
89
79
}
90
80
91
81
foreach ($ classGroups as $ group ) {
92
- $ attributesMetadata [ $ property -> name ] ->addGroup ($ group );
82
+ $ attributeMetadata ->addGroup ($ group );
93
83
}
94
84
95
85
foreach ($ this ->loadAttributes ($ property ) as $ annotation ) {
86
+ $ loaded = true ;
87
+
96
88
if ($ annotation instanceof Groups) {
97
89
foreach ($ annotation ->getGroups () as $ group ) {
98
- $ attributesMetadata [ $ property -> name ] ->addGroup ($ group );
90
+ $ attributeMetadata ->addGroup ($ group );
99
91
}
100
- } elseif ($ annotation instanceof MaxDepth) {
101
- $ attributesMetadata [$ property ->name ]->setMaxDepth ($ annotation ->getMaxDepth ());
102
- } elseif ($ annotation instanceof SerializedName) {
103
- $ attributesMetadata [$ property ->name ]->setSerializedName ($ annotation ->getSerializedName ());
104
- } elseif ($ annotation instanceof SerializedPath) {
105
- $ attributesMetadata [$ property ->name ]->setSerializedPath ($ annotation ->getSerializedPath ());
106
- } elseif ($ annotation instanceof Ignore) {
107
- $ attributesMetadata [$ property ->name ]->setIgnore (true );
108
- } elseif ($ annotation instanceof Context) {
109
- $ this ->setAttributeContextsForGroups ($ annotation , $ attributesMetadata [$ property ->name ]);
92
+
93
+ continue ;
110
94
}
111
95
112
- $ loaded = true ;
96
+ match (true ) {
97
+ $ annotation instanceof MaxDepth => $ attributeMetadata ->setMaxDepth ($ annotation ->getMaxDepth ()),
98
+ $ annotation instanceof SerializedName => $ attributeMetadata ->setSerializedName ($ annotation ->getSerializedName ()),
99
+ $ annotation instanceof SerializedPath => $ attributeMetadata ->setSerializedPath ($ annotation ->getSerializedPath ()),
100
+ $ annotation instanceof Ignore => $ attributeMetadata ->setIgnore (true ),
101
+ $ annotation instanceof Context => $ this ->setAttributeContextsForGroups ($ annotation , $ attributeMetadata ),
102
+ default => null ,
103
+ };
113
104
}
114
105
}
115
106
}
@@ -206,17 +197,17 @@ private function loadAttributes(\ReflectionMethod|\ReflectionClass|\ReflectionPr
206
197
207
198
private function setAttributeContextsForGroups (Context $ annotation , AttributeMetadataInterface $ attributeMetadata ): void
208
199
{
209
- if ( $ annotation ->getContext ()) {
210
- $ attributeMetadata -> setNormalizationContextForGroups ( $ annotation ->getContext (), $ annotation -> getGroups () );
211
- $ attributeMetadata -> setDenormalizationContextForGroups ( $ annotation ->getContext (), $ annotation -> getGroups () );
212
- }
200
+ $ context = $ annotation ->getContext ();
201
+ $ groups = $ annotation ->getGroups ();
202
+ $ normalizationContext = $ annotation ->getNormalizationContext ( );
203
+ $ denormalizationContext = $ annotation -> getDenormalizationContext ();
213
204
214
- if ($ annotation -> getNormalizationContext () ) {
215
- $ attributeMetadata ->setNormalizationContextForGroups ($ annotation -> getNormalizationContext () , $ annotation -> getGroups () );
205
+ if ($ normalizationContext || $ context ) {
206
+ $ attributeMetadata ->setNormalizationContextForGroups ($ normalizationContext ?: $ context , $ groups );
216
207
}
217
208
218
- if ($ annotation -> getDenormalizationContext () ) {
219
- $ attributeMetadata ->setDenormalizationContextForGroups ($ annotation -> getDenormalizationContext () , $ annotation -> getGroups () );
209
+ if ($ denormalizationContext || $ context ) {
210
+ $ attributeMetadata ->setDenormalizationContextForGroups ($ denormalizationContext ?: $ context , $ groups );
220
211
}
221
212
}
222
213
0 commit comments