notificationHandlerManager = $notificationHandlerManager; $this->entityManager = $entityManager; $this->security = $security; } /** * @param Notification $object * * @return array|ArrayObject|bool|float|int|string|void|null */ public function normalize($object, ?string $format = null, array $context = []) { $entity = $this->entityManager ->getRepository($object->getRelatedEntityClass()) ->find($object->getRelatedEntityId()); return [ 'type' => 'notification', 'id' => $object->getId(), 'addressees' => $this->normalizer->normalize($object->getAddressees(), $format, $context), 'date' => $this->normalizer->normalize($object->getDate(), $format, $context), 'isRead' => $object->isReadBy($this->security->getUser()), 'message' => $object->getMessage(), 'relatedEntityClass' => $object->getRelatedEntityClass(), 'relatedEntityId' => $object->getRelatedEntityId(), 'sender' => $this->normalizer->normalize($object->getSender(), $format, $context), 'title' => $object->getTitle(), 'entity' => null !== $entity ? $this->normalizer->normalize($entity, $format, $context) : null, ]; } public function supportsNormalization($data, ?string $format = null) { return $data instanceof Notification && 'json' === $format; } }