mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
Serializer made for privateComment
This commit is contained in:
parent
3ed2b36057
commit
27ce146aa0
@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||||
|
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
|
||||||
|
use Symfony\Component\Security\Core\Security;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
|
||||||
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
|
||||||
|
|
||||||
|
class PrivateCommentEmbeddableNormalizer implements NormalizerInterface, DenormalizerInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
private Security $security;
|
||||||
|
|
||||||
|
public function __construct(Security $security)
|
||||||
|
{
|
||||||
|
$this->security = $security;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function denormalize($data, string $type, ?string $format = null, array $context = [])
|
||||||
|
{
|
||||||
|
if (null === $data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$comment = new PrivateCommentEmbeddable();
|
||||||
|
|
||||||
|
$comment->setCommentForUser($this->security->getUser(), $data['privateComment']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsDenormalization($data, string $type, ?string $format = null)
|
||||||
|
{
|
||||||
|
return $type === CommentEmbeddable::class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function normalize($comment, $format = null, array $contect = [])
|
||||||
|
{
|
||||||
|
return $comment->getComment();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function supportsNormalization($data, ?string $format = null)
|
||||||
|
{
|
||||||
|
return $data instanceof CommentEmbeddable;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,4 +10,7 @@ services:
|
|||||||
Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer:
|
Chill\MainBundle\Serializer\Normalizer\DoctrineExistingEntityNormalizer:
|
||||||
tags:
|
tags:
|
||||||
- { name: 'serializer.normalizer', priority: 8 }
|
- { name: 'serializer.normalizer', priority: 8 }
|
||||||
|
Chill\MainBundle\Serializer\Normalizer\PrivateCommentEmbeddableNormalizer:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user