Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit366dd26

Browse files
committed
remove data parameter from createConstructorArgument method
1 parent1dc1f0d commit366dd26

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,10 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
361361
$params =array_merge($params,$data[$paramName]);
362362
}
363363
}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]);
365368
}elseif (isset($context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key])) {
366369
$params[] =$context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
367370
}elseif ($constructorParameter->isDefaultValueAvailable()) {
@@ -388,7 +391,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
388391
}
389392

390393
/**
391-
* @paramarray $data
394+
* @parammixed $parameterData
392395
* @param string $key
393396
* @param \ReflectionParameter $constructorParameter
394397
* @param array $context
@@ -400,13 +403,9 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
400403
* @throws RuntimeException
401404
* @throws MissingConstructorArgumentsException
402405
*/
403-
protectedfunctioncreateConstructorArgument(array &$data,string$key,\ReflectionParameter$constructorParameter,array &$context,string$format =null)
406+
protectedfunctioncreateConstructorArgument($parameterData,string$key,\ReflectionParameter$constructorParameter,array &$context,string$format =null)
404407
{
405-
$parameterData =$data[$key];
406408
if (null ===$parameterData &&$constructorParameter->allowsNull()) {
407-
// Don't run set for a parameter passed to the constructor
408-
unset($data[$key]);
409-
410409
returnnull;
411410
}
412411
try {
@@ -415,19 +414,18 @@ protected function createConstructorArgument(array &$data, string $key, \Reflect
415414
thrownewLogicException(sprintf('Cannot create an instance of %s from serialized data because the serializer inject in "%s" is not a denormalizer',$constructorParameter->getClass(),static::class));
416415
}
417416
$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));
419419
}
420420
}catch (\ReflectionException$e) {
421421
thrownewRuntimeException(sprintf('Could not determine the class of the parameter "%s".',$key),0,$e);
422422
}catch (MissingConstructorArgumentsException$e) {
423423
if (!$constructorParameter->getType()->allowsNull()) {
424424
throw$e;
425425
}
426-
$parameterData =null;
427-
}
428426

429-
// Don't run set for a parameter passed to the constructor
430-
unset($data[$key]);
427+
returnnull;
428+
}
431429

432430
return$parameterData;
433431
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp