mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-30 05:24:28 +02:00
Explicitly mark our normalizers as cachabel or not
This commit is contained in:
parent
b38f49a90e
commit
a1f4b35749
4 changed files with 39 additions and 12 deletions
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue