fix serialization - deserialization

This commit is contained in:
Julie Lenaerts 2022-05-02 14:01:07 +02:00
parent c56a125a78
commit c629dd79cb
2 changed files with 12 additions and 8 deletions

View File

@ -27,7 +27,7 @@ class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, Denorma
$this->security = $security;
}
public function denormalize($data, string $type, ?string $format = null, array $context = [])
public function denormalize($data, string $type, ?string $format = null, array $context = []): PrivateCommentEmbeddable
{
if (null === $data) {
return null;
@ -35,22 +35,24 @@ class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, Denorma
$comment = new PrivateCommentEmbeddable();
$comment->setCommentForUser($this->security->getUser(), $data['privateComment']);
$comment->setCommentForUser($this->security->getUser(), $data);
return $comment;
}
public function supportsDenormalization($data, string $type, ?string $format = null)
public function supportsDenormalization($data, string $type, ?string $format = null): bool
{
return $type === CommentEmbeddable::class;
return $type === PrivateCommentEmbeddable::class;
}
public function normalize($comment, $format = null, array $contect = [])
public function normalize($comment, $format = null, array $contect = []): string
{
return $comment->getComment();
return $comment->getCommentForUser($this->security->getUser());
}
public function supportsNormalization($data, ?string $format = null)
public function supportsNormalization($data, ?string $format = null): bool
{
return $data instanceof CommentEmbeddable;
return $data instanceof PrivateCommentEmbeddable;
}
}

View File

@ -13,4 +13,6 @@ services:
Chill\MainBundle\Serializer\Normalizer\PrivateCommentEmbeddableNormalizer:
autowire: true
autoconfigure: true
tags:
- { name: 'serializer.normalizer', priority: 64 }