Explicitly mark our normalizers as cachabel or not

This commit is contained in:
Jan Böhmer 2023-03-13 00:35:31 +01:00
parent b38f49a90e
commit a1f4b35749
4 changed files with 39 additions and 12 deletions

View file

@ -22,17 +22,19 @@ namespace App\Serializer;
use Brick\Math\BigDecimal;
use Brick\Math\BigNumber;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class BigNumberSerializer implements ContextAwareNormalizerInterface
class BigNumberSerializer implements NormalizerInterface, CacheableSupportsMethodInterface
{
public function supportsNormalization($data, string $format = null, array $context = [])
public function supportsNormalization($data, string $format = null): bool
{
return $data instanceof BigNumber;
}
public function normalize($object, string $format = null, array $context = [])
public function normalize($object, string $format = null, array $context = []): string
{
if (!$object instanceof BigNumber) {
throw new \InvalidArgumentException('This normalizer only supports BigNumber objects!');
@ -40,4 +42,9 @@ class BigNumberSerializer implements ContextAwareNormalizerInterface
return (string) $object;
}
public function hasCacheableSupportsMethod(): bool
{
return true;
}
}