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