mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
56 lines
1.5 KiB
PHP
56 lines
1.5 KiB
PHP
<?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;
|
|
}
|
|
|
|
} |