← Back
Editing: ReportExporterNormalizer.php
<?php namespace App\Report; use App\Entity\Report; use App\Enum\ReportType; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Contracts\Translation\TranslatorInterface; final class ReportExporterNormalizer implements NormalizerInterface { public function __construct( #[Autowire(service: ObjectNormalizer::class)] private readonly NormalizerInterface $normalizer, private readonly TranslatorInterface $translator ) { } public function normalize(mixed $object, ?string $format = null, array $context = []) { $normalizedData = $this->normalizer->normalize($object, $format, $context); if (ReportType::WRECK->value !== $normalizedData['type']) { unset( $normalizedData['status'], $normalizedData['carColor'], $normalizedData['carBrand'], $normalizedData['carType'], $normalizedData['isRegistrationUnavailable'], $normalizedData['insuranceNumber'] ); } $normalizedData['type'] = $this->translator->trans($normalizedData['type']); return $normalizedData; } public function supportsNormalization(mixed $data, ?string $format = null): bool { return $data instanceof Report && 'csv' === $format; } }
Save File
Cancel