@@ -268,6 +268,15 @@ protected function getConstructor(array &$data, $class, array &$context, \Reflec
268268 return $ reflectionClass ->getConstructor ();
269269 }
270270
271+ /**
272+ * @see instantiateComplexObject
273+ * @deprecated Since 3.1, will be removed in 4.0. Use instantiateComplexObject instead.
274+ */
275+ protected function instantiateObject (array &$ data , $ class , array &$ context , \ReflectionClass $ reflectionClass , $ allowedAttributes )
276+ {
277+ return $ this ->instantiateComplexObject ($ data , $ class , $ context , $ reflectionClass , $ allowedAttributes );
278+ }
279+
271280 /**
272281 * Instantiates an object using constructor parameters when needed.
273282 *
@@ -287,7 +296,7 @@ protected function getConstructor(array &$data, $class, array &$context, \Reflec
287296 *
288297 * @throws RuntimeException
289298 */
290- protected function instantiateObject (array &$ data , $ class , array &$ context , \ReflectionClass $ reflectionClass , $ allowedAttributes , $ format = null )
299+ protected function instantiateComplexObject (array &$ data , $ class , array &$ context , \ReflectionClass $ reflectionClass , $ allowedAttributes , $ format = null )
291300 {
292301 if (
293302 isset ($ context [static ::OBJECT_TO_POPULATE ]) &&
@@ -319,33 +328,41 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
319328
320329 $ params = array_merge ($ params , $ data [$ paramName ]);
321330 }
322- } elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) || array_key_exists ($ key , $ data ))) {
331+
332+ continue ;
333+ }
334+
335+ if ($ allowed && !$ ignored && (isset ($ data [$ key ]) || array_key_exists ($ key , $ data ))) {
323336 $ parameterData = $ data [$ key ];
324337 if (null !== $ constructorParameter ->getClass ()) {
325- $ parameterData = $ this ->serializer ->denormalize ($ parameterData , $ constructorParameter ->getClass ()->getName (), null , $ context );
338+ $ parameterData = $ this ->serializer ->deserialize ($ parameterData , $ constructorParameter ->getClass ()->getName (), null , $ context );
326339 }
327340
328341 // Don't run set for a parameter passed to the constructor
329342 $ params [] = $ parameterData ;
330343 unset($ data [$ key ]);
331- } elseif ($ constructorParameter ->isDefaultValueAvailable ()) {
344+
345+ continue ;
346+ }
347+
348+ if ($ constructorParameter ->isDefaultValueAvailable ()) {
332349 $ params [] = $ constructorParameter ->getDefaultValue ();
333- } else {
334- throw new RuntimeException (
335- sprintf (
336- 'Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present. ' ,
337- $ class ,
338- $ constructorParameter ->name
339- )
340- );
341350 }
351+
352+ throw new RuntimeException (
353+ sprintf (
354+ 'Cannot create an instance of %s from serialized data because its constructor requires parameter "%s" to be present. ' ,
355+ $ class ,
356+ $ constructorParameter ->name
357+ )
358+ );
342359 }
343360
344361 if ($ constructor ->isConstructor ()) {
345362 return $ reflectionClass ->newInstanceArgs ($ params );
346- } else {
347- return $ constructor ->invokeArgs (null , $ params );
348363 }
364+
365+ return $ constructor ->invokeArgs (null , $ params );
349366 }
350367
351368 return new $ class ();
0 commit comments