Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [Process] remove fixing of legacy bug, when PTS functionality is enabled
  DX: re-apply self_accessor and phpdoc_types_order by PHP CS Fixer
  [HttpClient] Psr18Client: parse HTTP Reason Phrase for Response
  fix test
  Fix wrong yaml parse null test
  [AssetMapper] Fixing merge from multiple PR's
  Bump Symfony version to 5.4.31
  Update VERSION for 5.4.30
  Update CONTRIBUTORS for 5.4.30
  Update CHANGELOG for 5.4.30
  Fix wrong merge
  [AssetMapper] Allowing circular references in JavaScriptImportPathCompiler
  [AssetMapper] Fix file deleting errors & remove nullable MappedAsset on JS import
  [Lock] Fix mongodb extension requirement in tests
  [Yaml] Remove dead code
  [AssetMapper] Fix in-file imports to resolve via filesystem
  throw better exception in TranslatableNormalizer, add to changelog
  Passing null to Inline::parse is not allowed
  Fix passing null to trim()
  • Loading branch information
nicolas-grekas committed Oct 29, 2023
2 parents cbf9eea + ef45660 commit 81c4385
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CHANGELOG
6.4
---

* Add `TranslatableNormalizer`
* Allow `Context` attribute to target classes
* Deprecate Doctrine annotations support in favor of native attributes
* Allow the `Groups` attribute/annotation on classes
Expand Down
3 changes: 2 additions & 1 deletion Normalizer/TranslatableNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Serializer\Normalizer;

use Symfony\Component\Serializer\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

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

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

0 comments on commit 81c4385

Please sign in to comment.