src/Contact/Serializer/Normalizer/ContactDtoNormalizer.php line 39
<?phpdeclare(strict_types=1);/*** Copyright (c) 2023 TECLA Consulting Group oü.* All rights reserved.** This unpublished material is proprietary to TECLA Consulting Group oü.* All rights reserved. The methods and* techniques described herein are considered trade secrets* and/or confidential. Reproduction or distribution, in whole* or in part, is forbidden except by express written permission* of TECLA Consulting Group oü.** @author Matúš Sýkorjak <matus@tecla.no>* @copyright 2023 TECLA Consulting Group oü*/namespace App\Contact\Serializer\Normalizer;use App\Contact\Dto\ContactDto;use App\Contact\Model\ContactInterface;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;use Symfony\Component\Serializer\Normalizer\NormalizerInterface;final class ContactDtoNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface{private NormalizerInterface $normalizer;private UrlGeneratorInterface $urlGenerator;public function __construct(NormalizerInterface $normalizer, UrlGeneratorInterface $urlGenerator){$this->normalizer = $normalizer;$this->urlGenerator = $urlGenerator;}public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null{$data = $this->normalizer->normalize($object, $format, $context);$data['_links'] = $this->getLinks($object);/** @var $object ContactDto */if (ContactInterface::TYPE_COMPANY === $object->getType()) {$data['fullName'] = $object->getName();}if (ContactInterface::TYPE_PERSON === $object->getType()) {$data['fullName'] = $object->getLastName() . ', ' . $object->getFirstName();}return $data;}public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool{return $data instanceof ContactDto;}public function hasCacheableSupportsMethod(): bool{return __CLASS__ === self::class;}private function getLinks(ContactDto $contactDto): array{return ['ajax' => ['invoiceFormInfo' => ['href' => $this->urlGenerator->generate('app.invoice.ajax.invoice_draft.customer.info', ['contactId' => $contactDto->getId(),]),],],'http' => ['view' => ['href' => $this->urlGenerator->generate('app.contact.http.contact.view', ['contactId' => $contactDto->getId(),]),],],];}}