for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace App\Serializer\Normalizer;
use App\Entity\Comment;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* CommentNormalizer.
*/
class CommentNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
{
use NormalizerAwareTrait;
* {@inheritdoc}
public function normalize($object, $format = null, array $context = []): array
/* @var Comment $object */
return [
'id' => $object->getId(),
'createdAt' => $this->normalizer->normalize($object->getCreatedAt()),
'updatedAt' => $this->normalizer->normalize($object->getCreatedAt()),
'body' => $object->getBody(),
'author' => $this->normalizer->normalize($object->getAuthor()),
];
}
public function supportsNormalization($data, $format = null): bool
return $data instanceof Comment;
public function hasCacheableSupportsMethod(): bool
return true;