Repository URL to install this package:
|
Version:
6.2.6 ▾
|
<?php
namespace DigitalAscetic\NotificationsBundle\Serializer\Normalizer;
use DigitalAscetic\NotificationsBundle\Entity\Receiver;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class ReceiverNormalizer implements NormalizerInterface
{
public function __construct(private ObjectNormalizer $normalizer)
{
}
public function normalize(mixed $object, string $format = null, array $context = [])
{
/** @var Receiver $receiver */
$receiver = $object;
$data = $this->normalizer->normalize($object, $format, $context);
if (array_key_exists('contactData', $data) && !empty($receiver->getContactData())) {
$data['contactData'] = json_encode($receiver->getContactData());
}
return $data;
}
public function supportsNormalization(mixed $data, string $format = null)
{
return $data instanceof Receiver;
}
}