1313
1414class 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