Skip to content

Commit

Permalink
Add missing optional parameters and getSupportedTypes method to seria…
Browse files Browse the repository at this point in the history
…lizers
  • Loading branch information
benr77 committed Aug 28, 2023
1 parent 02edbc8 commit 01312af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/Serializer/Normalizer/MoneyAsDecimalNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ public function normalize($object, string $format = null, array $context = []):
return $this->moneyFormatter->format($object);
}

public function supportsNormalization($data, string $format = null): bool
public function supportsNormalization($data, string $format = null, array $context = []): bool
{
return $data instanceof Money;
}

/**
* @return array<string, bool>
*/
public function getSupportedTypes(?string $format): array
{
return [
Money::class => true,
];
}
}
14 changes: 12 additions & 2 deletions src/Serializer/Normalizer/MoneyNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function normalize($object, string $format = null, array $context = []):
];
}

public function supportsNormalization($data, string $format = null): bool
public function supportsNormalization($data, string $format = null, array $context = []): bool
{
return $data instanceof Money;
}
Expand All @@ -45,12 +45,22 @@ public function denormalize($data, string $type, string $format = null, array $c
return new Money($data['amount'], new Currency($data['currency']));
}

public function supportsDenormalization($data, string $type, string $format = null): bool
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
{
if ($type !== Money::class) {
return false;
}

return true;
}

/**
* @return array<string, bool>
*/
public function getSupportedTypes(?string $format): array
{
return [
Money::class => true,
];
}
}

0 comments on commit 01312af

Please sign in to comment.