Skip to content

Commit 06b386c

Browse files
author
israel
committed
Update MoneyNormalizer for Symfony 7.0 compatibility
1 parent fe3a749 commit 06b386c

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/ApiPlatform/Serializer/MoneyNormalizer.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class MoneyNormalizer implements NormalizerInterface, DenormalizerInterface
1515
{
16-
public function denormalize($data, string $type, string $format = null, array $context = [])
16+
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): Money
1717
{
1818
if ('' === $data || null === $data) {
1919
throw new NotNormalizableValueException('The data is either an empty string or null, you should pass a string that can be parsed with the passed format or a valid Money value.');
@@ -22,18 +22,18 @@ public function denormalize($data, string $type, string $format = null, array $c
2222
return new Money((int)$data['amount'], new Currency($data['currency']));
2323
}
2424

25-
public function supportsDenormalization($data, string $type, string $format = null): bool
25+
public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool
2626
{
2727
return $type === Money::class && $data !== null;
2828
}
2929

3030
/**
31-
* @param mixed $object
31+
* @param Money $object
3232
* @param string|null $format
3333
* @param array $context
3434
* @return array
3535
*/
36-
public function normalize($object, string $format = null, array $context = [])
36+
public function normalize(mixed $object, string $format = null, array $context = []): array
3737
{
3838
if (!$object instanceof Money) {
3939
throw new InvalidArgumentException('The object must implement the "Money".');
@@ -46,8 +46,15 @@ public function normalize($object, string $format = null, array $context = [])
4646
return array_merge($object->jsonSerialize(), ['formatted' => $formatted, 'symbol' => \Symfony\Component\Intl\Currencies::getSymbol($object->getCurrency()->getCode())]);
4747
}
4848

49-
public function supportsNormalization($data, string $format = null): bool
49+
public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
5050
{
5151
return $data instanceof Money;
5252
}
53+
54+
public function getSupportedTypes(?string $format): array
55+
{
56+
return [
57+
Money::class => true,
58+
];
59+
}
5360
}

0 commit comments

Comments
 (0)