feature #24277 [Serializer] Getter for extra attributes in ExtraAttributesException (mdeboer)
This PR was squashed before being merged into the 3.4 branch (closes #24277).
Discussion
----------
[Serializer] Getter for extra attributes in ExtraAttributesException
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes (failure unrelated)
| Fixed tickets |
| License | MIT
This PR adds a public getter for the extra attributes in `ExtraAttributesException` and makes it easier to create custom exception messages (e.g. JSON formatted).
Commits
-------
cb935e7
[Serializer] Getter for extra attributes in ExtraAttributesException
This commit is contained in:
commit
2e0cb6055f
@ -7,6 +7,7 @@ CHANGELOG
|
||||
* added `AbstractObjectNormalizer::DISABLE_TYPE_ENFORCEMENT` context option
|
||||
to disable throwing an `UnexpectedValueException` on a type mismatch
|
||||
* added support for serializing `DateInterval` objects
|
||||
* added getter for extra attributes in `ExtraAttributesException`
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
@ -18,10 +18,24 @@ namespace Symfony\Component\Serializer\Exception;
|
||||
*/
|
||||
class ExtraAttributesException extends RuntimeException
|
||||
{
|
||||
private $extraAttributes;
|
||||
|
||||
public function __construct(array $extraAttributes, \Exception $previous = null)
|
||||
{
|
||||
$msg = sprintf('Extra attributes are not allowed ("%s" are unknown).', implode('", "', $extraAttributes));
|
||||
|
||||
$this->extraAttributes = $extraAttributes;
|
||||
|
||||
parent::__construct($msg, 0, $previous);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the extra attributes that are not allowed.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getExtraAttributes()
|
||||
{
|
||||
return $this->extraAttributes;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user