Skip to content

Commit e8fe851

Browse files
committed
minor #52344 [Serializer] throw better exception in TranslatableNormalizer, add to changelog (xabbuh)
This PR was merged into the 6.4 branch. Discussion ---------- [Serializer] throw better exception in TranslatableNormalizer, add to changelog | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | follows #50212 Commits ------- d8a03d1 throw better exception in TranslatableNormalizer, add to changelog
2 parents fd3435a + d8a03d1 commit e8fe851

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/Symfony/Component/Serializer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
6.4
55
---
66

7+
* Add `TranslatableNormalizer`
78
* Allow `Context` attribute to target classes
89
* Deprecate Doctrine annotations support in favor of native attributes
910
* Allow the `Groups` attribute/annotation on classes

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Serializer\Normalizer;
1313

1414
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
15+
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1516
use Symfony\Contracts\Translation\TranslatableInterface;
1617
use Symfony\Contracts\Translation\TranslatorInterface;
1718

@@ -36,7 +37,7 @@ public function __construct(
3637
public function normalize(mixed $object, string $format = null, array $context = []): string
3738
{
3839
if (!$object instanceof TranslatableInterface) {
39-
throw new InvalidArgumentException(sprintf('The object must implement the "%s".', TranslatableInterface::class));
40+
throw NotNormalizableValueException::createForUnexpectedDataType(sprintf('The object must implement the "%s".', TranslatableInterface::class), $object, [TranslatableInterface::class]);
4041
}
4142

4243
return $object->trans($this->translator, $context[self::NORMALIZATION_LOCALE_KEY] ?? $this->defaultContext[self::NORMALIZATION_LOCALE_KEY]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy