src/Offer/Serializer/Normalizer/OfferDraftNormalizer.php line 49
<?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\Core\Serializer\Normalizer\AttributeAwareNormalizerTrait;use App\Core\Util\DecimalNumberEncoderInterface;use App\Offer\Model\OfferDraftInterface;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 OfferDraftNormalizer implements ContextAwareNormalizerInterface, CacheableSupportsMethodInterface{use AttributeAwareNormalizerTrait;private NormalizerInterface $normalizer;private UrlGeneratorInterface $urlGenerator;private DecimalNumberEncoderInterface $encoder;public function __construct(NormalizerInterface $normalizer,UrlGeneratorInterface $urlGenerator,DecimalNumberEncoderInterface $encoder) {$this->normalizer = $normalizer;$this->urlGenerator = $urlGenerator;$this->encoder = $encoder;}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, OfferDraftInterface::ATTR_GROSS_TOTAL, $context)) {$this->normalizeGrossTotal($object, $data);}if (true === $this->shouldSerializeAttribute($data, OfferDraftInterface::ATTR__LINKS, $context)) {$this->normalize_Links($object, $data);}return $data;}public function supportsNormalization($data, string $format = null, array $context = []): bool{return $data instanceof OfferDraftInterface;}public function hasCacheableSupportsMethod(): bool{return __CLASS__ === static::class;}private function normalizeGrossTotal(OfferDraftInterface $offerDraft, array &$data): void{$data[OfferDraftInterface::ATTR_GROSS_TOTAL] = $this->encoder->decode($offerDraft->getItemsGrossTotal());}private function normalize_Links(OfferDraftInterface $offerDraft, array &$data): void{$data[OfferDraftInterface::ATTR__LINKS] = ['ajax' => ['remove' => $this->urlGenerator->generate('app_offer_ajax_offer_draft_remove', ['id' => $offerDraft->getId(),]),],'http' => ['edit' => $this->urlGenerator->generate('app_offer_http_offer_draft_edit', ['id' => $offerDraft->getId(),]),'export' => $this->urlGenerator->generate('app_offer_http_offer_draft_export', ['id' => $offerDraft->getId(),]),],];}}