@@ -361,7 +361,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
361
361
$ params = array_merge ($ params , $ data [$ paramName ]);
362
362
}
363
363
} elseif ($ allowed && !$ ignored && (isset ($ data [$ key ]) || array_key_exists ($ key , $ data ))) {
364
- $ params [] = $ this ->createConstructorArgument ($ data , $ key , $ constructorParameter , $ context , $ format );
364
+ $ params [] = $ this ->createConstructorArgument ($ data [$ key ], $ key , $ constructorParameter , $ context , $ format );
365
+
366
+ // Don't run set for a parameter passed to the constructor
367
+ unset($ data [$ key ]);
365
368
} elseif (isset ($ context [static ::DEFAULT_CONSTRUCTOR_ARGUMENTS ][$ class ][$ key ])) {
366
369
$ params [] = $ context [static ::DEFAULT_CONSTRUCTOR_ARGUMENTS ][$ class ][$ key ];
367
370
} elseif ($ constructorParameter ->isDefaultValueAvailable ()) {
@@ -388,7 +391,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
388
391
}
389
392
390
393
/**
391
- * @param array $data
394
+ * @param mixed $parameterData
392
395
* @param string $key
393
396
* @param \ReflectionParameter $constructorParameter
394
397
* @param array $context
@@ -400,13 +403,9 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
400
403
* @throws RuntimeException
401
404
* @throws MissingConstructorArgumentsException
402
405
*/
403
- protected function createConstructorArgument (array & $ data , string $ key , \ReflectionParameter $ constructorParameter , array &$ context , string $ format = null )
406
+ protected function createConstructorArgument ($ parameterData , string $ key , \ReflectionParameter $ constructorParameter , array &$ context , string $ format = null )
404
407
{
405
- $ parameterData = $ data [$ key ];
406
408
if (null === $ parameterData && $ constructorParameter ->allowsNull ()) {
407
- // Don't run set for a parameter passed to the constructor
408
- unset($ data [$ key ]);
409
-
410
409
return null ;
411
410
}
412
411
try {
@@ -415,19 +414,18 @@ protected function createConstructorArgument(array &$data, string $key, \Reflect
415
414
throw new LogicException (sprintf ('Cannot create an instance of %s from serialized data because the serializer inject in "%s" is not a denormalizer ' , $ constructorParameter ->getClass (), static ::class));
416
415
}
417
416
$ parameterClass = $ constructorParameter ->getClass ()->getName ();
418
- $ parameterData = $ this ->serializer ->denormalize ($ parameterData , $ parameterClass , $ format , $ this ->createChildContext ($ context , $ constructorParameter ->name ));
417
+
418
+ return $ this ->serializer ->denormalize ($ parameterData , $ parameterClass , $ format , $ this ->createChildContext ($ context , $ constructorParameter ->name ));
419
419
}
420
420
} catch (\ReflectionException $ e ) {
421
421
throw new RuntimeException (sprintf ('Could not determine the class of the parameter "%s". ' , $ key ), 0 , $ e );
422
422
} catch (MissingConstructorArgumentsException $ e ) {
423
423
if (!$ constructorParameter ->getType ()->allowsNull ()) {
424
424
throw $ e ;
425
425
}
426
- $ parameterData = null ;
427
- }
428
426
429
- // Don't run set for a parameter passed to the constructor
430
- unset( $ data [ $ key ]);
427
+ return null ;
428
+ }
431
429
432
430
return $ parameterData ;
433
431
}
0 commit comments