src/Offer/Serializer/Normalizer/OfferNormalizer.php line 87
<?phpdeclare(strict_types=1);/*** Copyright (c) 2021 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 2021 TECLA Consulting Group oü*/namespace App\Offer\Serializer\Normalizer;use App\Contact\Security\ContactContextInterface;use App\Core\Serializer\Normalizer\AttributeAwareNormalizerTrait;use App\Core\Util\DecimalNumberEncoderInterface;use App\Offer\Model\OfferInterface;use App\Offer\Util\OfferHistoryGeneratorInterface;use App\Offer\Util\OfferNumberEncoderInterface;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;use Symfony\Component\Serializer\Normalizer\NormalizerInterface;final class OfferNormalizer implements ContextAwareNormalizerInterface, CacheableSupportsMethodInterface{use AttributeAwareNormalizerTrait;private NormalizerInterface $normalizer;private UrlGeneratorInterface $urlGenerator;private ContactContextInterface $context;private DecimalNumberEncoderInterface $decimalEncoder;private OfferNumberEncoderInterface $numberEncoder;private OfferHistoryGeneratorInterface $historyGenerator;public function __construct(NormalizerInterface $normalizer,UrlGeneratorInterface $urlGenerator,ContactContextInterface $context,DecimalNumberEncoderInterface $decimalEncoder,OfferNumberEncoderInterface $numberEncoder,OfferHistoryGeneratorInterface $historyGenerator) {$this->normalizer = $normalizer;$this->urlGenerator = $urlGenerator;$this->context = $context;$this->decimalEncoder = $decimalEncoder;$this->numberEncoder = $numberEncoder;$this->historyGenerator = $historyGenerator;}public function normalize($object, string $format = null, array $context = []): float|int|bool|\ArrayObject|array|string|null{$data = $this->normalizer->normalize($object, $format, $context);if (true === $this->shouldSerializeAttribute($data, OfferInterface::ATTR_NUMBER, $context)) {$this->normalizeNumber($object, $data);}if (true === $this->shouldSerializeAttribute($data, OfferInterface::ATTR_GROSS_TOTAL, $context)) {$this->normalizeGrossTotal($object, $data);}if (true === $this->shouldSerializeAttribute($data, OfferInterface::ATTR_HISTORY, $context)) {$this->normalizeHistory($object, $data);}if (true === $this->shouldSerializeAttribute($data, OfferInterface::ATTR__LINKS, $context)) {$this->normalize_Links($object, $data);}return $data;}public function supportsNormalization($data, string $format = null, array $context = []): bool{return $data instanceof OfferInterface;}public function hasCacheableSupportsMethod(): bool{return __CLASS__ === static::class;}private function normalizeNumber(OfferInterface $offer, array &$data): void{$data[OfferInterface::ATTR_NUMBER] = $this->numberEncoder->encode($offer->getNumber());}private function normalizeGrossTotal(OfferInterface $offer, array &$data): void{$data[OfferInterface::ATTR_GROSS_TOTAL] = $this->decimalEncoder->decode($offer->getItemsGrossTotal());}private function normalizeHistory(OfferInterface $offer, array &$data): void{$history = $this->historyGenerator->generate($offer);$data[OfferInterface::ATTR_HISTORY] = $this->normalizer->normalize($history);}private function normalize_Links(OfferInterface $offer, array &$data): void{if ($offer->getSupplier() === $this->context->getCurrent()) {$httpViewUrl = $this->urlGenerator->generate('app_offer_http_offer_outgoing_view', ['id' => $offer->getId(),]);$httpExportUrl = $this->urlGenerator->generate('app_offer_http_offer_outgoing_export', ['id' => $offer->getId(),]);} else {$httpViewUrl = $this->urlGenerator->generate('app_offer_http_offer_incoming_view', ['id' => $offer->getId(),]);$httpExportUrl = $this->urlGenerator->generate('app_offer_http_offer_incoming_export', ['id' => $offer->getId(),]);}$data[OfferInterface::ATTR__LINKS] = ['http' => ['view' => $httpViewUrl,'export' => $httpExportUrl,],];}}