12
12
namespace Symfony \Component \Serializer \Normalizer ;
13
13
14
14
use Symfony \Component \PropertyAccess \Exception \InvalidArgumentException ;
15
+ use Symfony \Component \PropertyInfo \PropertyTypeExtractorInterface ;
16
+ use Symfony \Component \PropertyInfo \Type ;
15
17
use Symfony \Component \Serializer \Exception \CircularReferenceException ;
18
+ use Symfony \Component \Serializer \Exception \ExtraAttributesException ;
16
19
use Symfony \Component \Serializer \Exception \LogicException ;
17
20
use Symfony \Component \Serializer \Exception \UnexpectedValueException ;
18
- use Symfony \Component \PropertyInfo \PropertyTypeExtractorInterface ;
19
- use Symfony \Component \PropertyInfo \Type ;
20
21
use Symfony \Component \Serializer \Mapping \Factory \ClassMetadataFactoryInterface ;
21
22
use Symfony \Component \Serializer \NameConverter \NameConverterInterface ;
22
23
@@ -171,8 +172,10 @@ public function denormalize($data, $class, $format = null, array $context = arra
171
172
if (!isset ($ context ['cache_key ' ])) {
172
173
$ context ['cache_key ' ] = $ this ->getCacheKey ($ format , $ context );
173
174
}
175
+
174
176
$ allowedAttributes = $ this ->getAllowedAttributes ($ class , $ context , true );
175
177
$ normalizedData = $ this ->prepareForDenormalization ($ data );
178
+ $ extraAttributes = array ();
176
179
177
180
$ reflectionClass = new \ReflectionClass ($ class );
178
181
$ object = $ this ->instantiateObject ($ normalizedData , $ class , $ context , $ reflectionClass , $ allowedAttributes , $ format );
@@ -183,6 +186,10 @@ public function denormalize($data, $class, $format = null, array $context = arra
183
186
}
184
187
185
188
if (($ allowedAttributes !== false && !in_array ($ attribute , $ allowedAttributes )) || !$ this ->isAllowedAttribute ($ class , $ attribute , $ format , $ context )) {
189
+ if (isset ($ context ['allow_extra_attributes ' ]) && !$ context ['allow_extra_attributes ' ]) {
190
+ $ extraAttributes [] = $ attribute ;
191
+ }
192
+
186
193
continue ;
187
194
}
188
195
@@ -194,6 +201,10 @@ public function denormalize($data, $class, $format = null, array $context = arra
194
201
}
195
202
}
196
203
204
+ if (!empty ($ extraAttributes )) {
205
+ throw new ExtraAttributesException (sprintf ('Extra attributes are not allowed ("%s" are unknown). ' , implode ('", " ' , $ extraAttributes )));
206
+ }
207
+
197
208
return $ object ;
198
209
}
199
210
0 commit comments