Remove serializer.yaml configuration, update PersonJsonNormalizer and PersonJsonDenormalizer for improved logic handling, adjust type hints in closures, and rename id to definition_id in PersonIdentifierWorkerNormalizer.

This commit is contained in:
2025-09-16 12:43:39 +02:00
parent 8d29fb260a
commit 3227bfcd3a
5 changed files with 7 additions and 18 deletions

View File

@@ -96,7 +96,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
// We can get rid of this file when the service 'chill.person.repository.person' is no more used.
// We should use the PersonRepository service instead of a custom service name.
$loader->load('services/repository.yaml');
$loader->load('services/serializer.yaml');
$loader->load('services/security.yaml');
$loader->load('services/doctrineEventListener.yaml');
$loader->load('services/accompanyingPeriodConsistency.yaml');

View File

@@ -24,7 +24,7 @@ final readonly class PersonIdentifierWorkerNormalizer implements NormalizerInter
return [
'type' => 'person_identifier_worker',
'id' => $object->getDefinition()->getId(),
'definition_id' => $object->getDefinition()->getId(),
'engine' => $object->getDefinition()->getEngine(),
'label' => $object->getDefinition()->getLabel(),
'isActive' => $object->getDefinition()->isActive(),

View File

@@ -62,7 +62,7 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize
$person->setMobilenumber($this->denormalizer->denormalize($data['mobilenumber'], PhoneNumber::class, $format, $context));
}
if (\array_key_exists('gender', $data)) {
if (\array_key_exists('gender', $data) && null !== $data['gender']) {
$gender = $this->denormalizer->denormalize($data['gender'], Gender::class, $format, []);
$person->setGender($gender);
}
@@ -93,7 +93,7 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize
$altNameKey = $altNameData['key'];
$altNameValue = $altNameData['value'];
$altName = $person->getAltNames()->findFirst(fn (PersonAltName $personAltName) => $personAltName->getKey() === $altNameKey);
$altName = $person->getAltNames()->findFirst(fn (int $key, PersonAltName $personAltName) => $personAltName->getKey() === $altNameKey);
if (null === $altName) {
$altName = new PersonAltName();
$person->addAltName($altName);
@@ -117,7 +117,7 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize
$worker = $this->personIdentifierManager->buildWorkerByPersonIdentifierDefinition($definitionId);
$personIdentifier = $person->getIdentifiers()->findFirst(fn (PersonIdentifier $personIdentifier) => $personIdentifier->getId() === $definitionId);
$personIdentifier = $person->getIdentifiers()->findFirst(fn (int $key, PersonIdentifier $personIdentifier) => $personIdentifier->getId() === $definitionId);
if (null === $personIdentifier) {
$personIdentifier = new PersonIdentifier($worker->getDefinition());
$person->addIdentifier($personIdentifier);
@@ -132,7 +132,7 @@ final class PersonJsonDenormalizer implements DenormalizerInterface, Denormalize
$person->setEmail($data['email']);
}
if (\array_key_exists('civility', $data)) {
if (\array_key_exists('civility', $data) && null !== $data['civility']) {
$civility = $this->denormalizer->denormalize($data['civility'], Civility::class, $format, []);
$person->setCivility($civility);
}

View File

@@ -21,11 +21,12 @@ use Doctrine\Common\Collections\Collection;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Serialize a Person entity.
*/
class PersonJsonNormalizer implements NormalizerAwareInterface
class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterface
{
use NormalizerAwareTrait;

View File

@@ -1,11 +0,0 @@
---
services:
# note: normalizers are loaded from ../services.yaml
Chill\PersonBundle\Serializer\Normalizer\:
autowire: true
autoconfigure: true
resource: '../../Serializer/Normalizer'
tags:
- { name: 'serializer.normalizer', priority: 64 }