src/Offer/Serializer/Normalizer/OfferEmailDraftNormalizer.php line 42

  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2021 TECLA Consulting Group oü.
  5.  * All rights reserved.
  6.  *
  7.  * This unpublished material is proprietary to TECLA Consulting Group oü.
  8.  * All rights reserved. The methods and
  9.  * techniques described herein are considered trade secrets
  10.  * and/or confidential. Reproduction or distribution, in whole
  11.  * or in part, is forbidden except by express written permission
  12.  * of TECLA Consulting Group oü.
  13.  *
  14.  * @author    Matúš Sýkorjak <matus@tecla.no>
  15.  * @copyright 2021 TECLA Consulting Group oü
  16.  */
  17. namespace App\Offer\Serializer\Normalizer;
  18. use App\Core\Serializer\Normalizer\AttributeAwareNormalizerTrait;
  19. use App\Offer\Model\OfferEmailDraftInterface;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
  22. use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
  23. use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
  24. final class OfferEmailDraftNormalizer implements ContextAwareNormalizerInterfaceCacheableSupportsMethodInterface
  25. {
  26.     use AttributeAwareNormalizerTrait;
  27.     private NormalizerInterface $normalizer;
  28.     private UrlGeneratorInterface $urlGenerator;
  29.     public function __construct(NormalizerInterface $normalizerUrlGeneratorInterface $urlGenerator)
  30.     {
  31.         $this->normalizer $normalizer;
  32.         $this->urlGenerator $urlGenerator;
  33.     }
  34.     public function normalize($objectstring $format null, array $context = []): float|int|bool|\ArrayObject|array|string|null
  35.     {
  36.         $data $this->normalizer->normalize($object$format$context);
  37.         if (true === $this->shouldSerializeAttribute($dataOfferEmailDraftInterface::ATTR__LINKS$context)) {
  38.             $this->normalize_Links($object$data);
  39.         }
  40.         return $data;
  41.     }
  42.     public function supportsNormalization($datastring $format null, array $context = []): bool
  43.     {
  44.         return $data instanceof OfferEmailDraftInterface;
  45.     }
  46.     public function hasCacheableSupportsMethod(): bool
  47.     {
  48.         return __CLASS__ === static::class;
  49.     }
  50.     private function normalize_Links(OfferEmailDraftInterface $emailDraft, array &$data): void
  51.     {
  52.         $data[OfferEmailDraftInterface::ATTR__LINKS] = [
  53.             'ajax' => [
  54.                 'createAttachment' => $this->urlGenerator->generate('app.offer.ajax.offer_email_draft_attachment.create', [
  55.                     'id' => $emailDraft->getId(),
  56.                 ]),
  57.             ],
  58.         ];
  59.     }
  60. }