@@ -268,6 +268,15 @@ protected function getConstructor(array &$data, $class, array &$context, \Reflec
268
268
return $ reflectionClass ->getConstructor ();
269
269
}
270
270
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
+
271
280
/**
272
281
* Instantiates an object using constructor parameters when needed.
273
282
*
@@ -287,7 +296,7 @@ protected function getConstructor(array &$data, $class, array &$context, \Reflec
287
296
*
288
297
* @throws RuntimeException
289
298
*/
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 )
291
300
{
292
301
if (
293
302
isset ($ context [static ::OBJECT_TO_POPULATE ]) &&
@@ -319,33 +328,41 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
319
328
320
329
$ params = array_merge ($ params , $ data [$ paramName ]);
321
330
}
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 ))) {
323
336
$ parameterData = $ data [$ key ];
324
337
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 );
326
339
}
327
340
328
341
// Don't run set for a parameter passed to the constructor
329
342
$ params [] = $ parameterData ;
330
343
unset($ data [$ key ]);
331
- } elseif ($ constructorParameter ->isDefaultValueAvailable ()) {
344
+
345
+ continue ;
346
+ }
347
+
348
+ if ($ constructorParameter ->isDefaultValueAvailable ()) {
332
349
$ 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
- );
341
350
}
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
+ );
342
359
}
343
360
344
361
if ($ constructor ->isConstructor ()) {
345
362
return $ reflectionClass ->newInstanceArgs ($ params );
346
- } else {
347
- return $ constructor ->invokeArgs (null , $ params );
348
363
}
364
+
365
+ return $ constructor ->invokeArgs (null , $ params );
349
366
}
350
367
351
368
return new $ class ();
0 commit comments