Add getSupportedTypes method for (de)normalizerInterface implementations

This commit is contained in:
Julie Lenaerts 2025-05-26 11:21:59 +02:00
parent 9fcc1634f5
commit a5049ddefb
34 changed files with 277 additions and 2 deletions

View File

@ -86,6 +86,8 @@ class StoredObjectDenormalizer implements DenormalizerInterface
public function getSupportedTypes(?string $format): array
{
// TODO: Implement getSupportedTypes() method.
return [
StoredObject::class => true,
];
}
}

View File

@ -117,6 +117,13 @@ class RequestPdfSignMessageSerializerTest extends TestCase
{
return $data instanceof PDFSignatureZone;
}
public function getSupportedTypes(?string $format): array
{
return [
PDFSignatureZone::class => true,
];
}
};
$denormalizer = new class () implements DenormalizerInterface {
public function denormalize($data, string $type, ?string $format = null, array $context = []): mixed
@ -128,6 +135,13 @@ class RequestPdfSignMessageSerializerTest extends TestCase
{
return PDFSignatureZone::class === $type;
}
public function getSupportedTypes(?string $format): array
{
return [
PDFSignatureZone::class => true,
];
}
};
$serializer = new Serializer([$normalizer, $denormalizer]);

View File

@ -16,7 +16,6 @@ use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Templating\Entity\AddressRender;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
@ -137,4 +136,21 @@ class AddressNormalizer implements \Symfony\Component\Serializer\Normalizer\Norm
return false;
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format) {
return [
Address::class => true,
];
}
if ('docgen' === $format) {
return [
Address::class => false,
];
}
return [];
}
}

View File

@ -69,4 +69,15 @@ class CenterNormalizer implements DenormalizerInterface, NormalizerInterface
{
return $data instanceof Center && 'json' === $format;
}
public function getSupportedTypes(?string $format): array
{
if ('json' !== $format && null !== $format) {
return [];
}
return [
Center::class => true,
];
}
}

View File

@ -45,4 +45,11 @@ class CollectionNormalizer implements NormalizerAwareInterface, NormalizerInterf
{
return $data instanceof Collection;
}
public function getSupportedTypes(?string $format): array
{
return [
Collection::class => true,
];
}
}

View File

@ -82,4 +82,9 @@ class CommentEmbeddableDocGenNormalizer implements \Symfony\Component\Serializer
return false;
}
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [CommentEmbeddable::class => true] : [];
}
}

View File

@ -121,4 +121,25 @@ class DateNormalizer implements \Symfony\Component\Serializer\Normalizer\Normali
return false;
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format) {
return [
\DateTimeInterface::class => true,
\DateTime::class => true,
\DateTimeImmutable::class => true,
];
}
if ('docgen' === $format) {
return [
\DateTimeInterface::class => true,
\DateTime::class => true,
\DateTimeImmutable::class => true,
];
}
return [];
}
}

View File

@ -69,4 +69,11 @@ class DiscriminatedObjectDenormalizer implements \Symfony\Component\Serializer\N
return false;
}
public function getSupportedTypes(?string $format): array
{
return [
self::TYPE => true,
];
}
}

View File

@ -65,4 +65,11 @@ class DoctrineExistingEntityNormalizer implements DenormalizerInterface
// we do not have any class discriminator. Check that the id is the only one key
return 1 === \count($data);
}
public function getSupportedTypes(?string $format): array
{
return [
'object' => false,
];
}
}

View File

@ -79,4 +79,9 @@ class EntityWorkflowStepNormalizer implements NormalizerAwareInterface, Normaliz
{
return $data instanceof EntityWorkflowStep && 'json' === $format;
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [EntityWorkflowStep::class => true] : [];
}
}

View File

@ -37,4 +37,11 @@ class GenderDocGenNormalizer implements \Symfony\Component\Serializer\Normalizer
'type' => 'chill_main_gender',
];
}
public function getSupportedTypes(?string $format): array
{
return [
Gender::class => true,
];
}
}

View File

@ -55,4 +55,9 @@ class NotificationNormalizer implements NormalizerAwareInterface, NormalizerInte
{
return $data instanceof Notification && 'json' === $format;
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [Notification::class => true] : [];
}
}

View File

@ -78,4 +78,15 @@ class PhonenumberNormalizer implements \Symfony\Component\Serializer\Normalizer\
return false;
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
PhoneNumber::class => true,
];
}
return [];
}
}

View File

@ -34,4 +34,11 @@ class PointNormalizer implements DenormalizerInterface
{
return Point::class === $type;
}
public function getSupportedTypes(?string $format): array
{
return [
Point::class => true,
];
}
}

View File

@ -34,4 +34,15 @@ class UserGroupDenormalizer implements DenormalizerInterface
&& 2 === count(array_keys($data))
;
}
public function getSupportedTypes(?string $format): array
{
if ('json' !== $format) {
return [];
}
return [
UserGroup::class => false,
];
}
}

View File

@ -122,4 +122,15 @@ class UserNormalizer implements \Symfony\Component\Serializer\Normalizer\Normali
return false;
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
User::class => true,
];
}
return [];
}
}

View File

@ -136,6 +136,11 @@ final class UserNormalizerTest extends TestCase
{
return true;
}
public function getSupportedTypes(?string $format): array
{
return ['*' => true];
}
});
$this->assertEquals($expected, $normalizer->normalize($user, $format, $context));

View File

@ -183,4 +183,9 @@ class AccompanyingPeriodDocGenNormalizer implements \Symfony\Component\Serialize
return false;
}
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [AccompanyingPeriod::class => true] : [];
}
}

View File

@ -45,4 +45,11 @@ class AccompanyingPeriodParticipationNormalizer implements NormalizerAwareInterf
return $data instanceof AccompanyingPeriodParticipation;
}
public function getSupportedTypes(?string $format): array
{
return [
AccompanyingPeriodParticipation::class => true,
];
}
}

View File

@ -95,4 +95,11 @@ class AccompanyingPeriodResourceNormalizer implements DenormalizerAwareInterface
{
return Resource::class === $type;
}
public function getSupportedTypes(?string $format): array
{
return [
Resource::class => true,
];
}
}

View File

@ -112,4 +112,11 @@ class AccompanyingPeriodWorkDenormalizer implements \Symfony\Component\Serialize
$work->addAccompanyingPeriodWorkEvaluation($evaluation);
}
}
public function getSupportedTypes(?string $format): array
{
return [
AccompanyingPeriodWork::class => true,
];
}
}

View File

@ -103,4 +103,11 @@ class AccompanyingPeriodWorkEvaluationDenormalizer implements \Symfony\Component
$evaluation->addDocument($document);
}
}
public function getSupportedTypes(?string $format): array
{
return [
AccompanyingPeriodWorkEvaluation::class => true,
];
}
}

View File

@ -56,4 +56,11 @@ class AccompanyingPeriodWorkEvaluationDocumentNormalizer implements \Symfony\Com
|| spl_object_hash($data) !== $context[self::SKIP]
);
}
public function getSupportedTypes(?string $format): array
{
return [
AccompanyingPeriodWorkEvaluationDocument::class => true,
];
}
}

View File

@ -70,4 +70,9 @@ class AccompanyingPeriodWorkEvaluationNormalizer implements \Symfony\Component\S
&& $data instanceof AccompanyingPeriodWorkEvaluation
&& !\array_key_exists(self::IGNORE_EVALUATION, $context);
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [AccompanyingPeriodWorkEvaluation::class => true] : [];
}
}

View File

@ -137,4 +137,12 @@ class AccompanyingPeriodWorkNormalizer implements \Symfony\Component\Serializer\
default => false,
};
}
public function getSupportedTypes(?string $format): array
{
return match ($format) {
'json', 'docgen' => [AccompanyingPeriodWork::class => true],
default => [],
};
}
}

View File

@ -36,4 +36,11 @@ class GenderDocGenNormalizer implements \Symfony\Component\Serializer\Normalizer
'genderTranslation' => $gender->getGenderTranslation(),
];
}
public function getSupportedTypes(?string $format): array
{
return [
Gender::class => true,
];
}
}

View File

@ -181,4 +181,11 @@ class MembersEditorNormalizer implements DenormalizerAwareInterface, Denormalize
throw new Exception\UnexpectedValueException("The schema does not have any key 'destination'");
}
}
public function getSupportedTypes(?string $format): array
{
return [
MembersEditor::class => true,
];
}
}

View File

@ -247,4 +247,9 @@ class PersonDocGenNormalizer implements
return $data;
}
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [Person::class => true] : [];
}
}

View File

@ -241,4 +241,9 @@ class PersonJsonNormalizer implements DenormalizerAwareInterface, NormalizerAwar
)
->toArray();
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [Person::class => true] : [];
}
}

View File

@ -83,4 +83,9 @@ class RelationshipDocGenNormalizer implements \Symfony\Component\Serializer\Norm
return $data instanceof Relationship || (null === $data
&& Relationship::class === ($context['docgen:expects'] ?? null));
}
public function getSupportedTypes(?string $format): array
{
return 'docgen' === $format ? [Relationship::class => true] : [];
}
}

View File

@ -75,4 +75,15 @@ class SocialActionNormalizer implements NormalizerAwareInterface, NormalizerInte
return false;
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
SocialAction::class => true,
];
}
return [];
}
}

View File

@ -48,6 +48,9 @@ class SocialIssueNormalizer implements \Symfony\Component\Serializer\Normalizer\
'title' => $socialIssue->getTitle(),
'text' => $this->render->renderString($socialIssue, []),
];
default:
return [];
}
}
@ -69,4 +72,15 @@ class SocialIssueNormalizer implements \Symfony\Component\Serializer\Normalizer\
return false;
}
public function getSupportedTypes(?string $format): array
{
if ('json' === $format || 'docgen' === $format) {
return [
SocialIssue::class => true,
];
}
return [];
}
}

View File

@ -58,4 +58,9 @@ class WorkflowNormalizer implements \Symfony\Component\Serializer\Normalizer\Nor
&& $data instanceof EntityWorkflow
&& !\array_key_exists(self::IGNORE_ENTITY_WORKFLOW, $context);
}
public function getSupportedTypes(?string $format): array
{
return 'json' === $format ? [EntityWorkflow::class => true] : [];
}
}

View File

@ -68,4 +68,15 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
{
return $data instanceof ThirdParty && 'json' === $format;
}
public function getSupportedTypes(?string $format): array
{
if ('json' !== $format) {
return [];
}
return [
ThirdParty::class => true,
];
}
}