Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2dc900c

Browse files
committed
Save missing arguments in MissingConstructorArgumentsException
1 parent 9a2b25d commit 2dc900c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/Serializer/Exception/MissingConstructorArgumentsException.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@
1616
*/
1717
class MissingConstructorArgumentsException extends RuntimeException
1818
{
19+
private array $missingArguments;
20+
21+
public function __construct(string $message, int $code = 0, \Throwable $previous = null, array $missingArguments = [])
22+
{
23+
$this->missingArguments = $missingArguments;
24+
25+
parent::__construct($message, $code, $previous);
26+
}
27+
28+
/**
29+
* @return string[]
30+
*/
31+
public function getMissingConstructorArguments(): array
32+
{
33+
return $this->missingArguments;
34+
}
1935
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
399399
} elseif ($constructorParameter->hasType() && $constructorParameter->getType()->allowsNull()) {
400400
$params[] = null;
401401
} else {
402-
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires parameter "%s" to be present.', $class, $constructorParameter->name));
402+
throw new MissingConstructorArgumentsException(sprintf('Cannot create an instance of "%s" from serialized data because its constructor requires parameter "%s" to be present.', $class, $constructorParameter->name), 0, null, [$constructorParameter->name]);
403403
}
404404
}
405405

0 commit comments

Comments
 (0)