mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
Merge remote-tracking branch 'origin/master' into issue230_person
This commit is contained in:
@@ -14,11 +14,11 @@ namespace Chill\PersonBundle\Serializer\Normalizer;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\MainBundle\Templating\Entity\ChillEntityRenderExtension;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Chill\PersonBundle\Repository\PersonRepository;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use LogicException;
|
||||
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
|
||||
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
|
||||
@@ -59,11 +59,11 @@ class PersonJsonNormalizer implements
|
||||
$this->centerResolverManager = $centerResolverManager;
|
||||
}
|
||||
|
||||
public function denormalize($data, string $type, ?string $format = null, array $context = [])
|
||||
public function denormalize($data, $type, $format = null, array $context = [])
|
||||
{
|
||||
$person = $this->extractObjectToPopulate($type, $context);
|
||||
|
||||
if (array_key_exists('id', $data)) {
|
||||
if (array_key_exists('id', $data) && null === $person) {
|
||||
$person = $this->repository->find($data['id']);
|
||||
|
||||
if (null === $person) {
|
||||
@@ -115,18 +115,14 @@ class PersonJsonNormalizer implements
|
||||
case 'birthdate':
|
||||
$object = $this->denormalizer->denormalize($data[$item], DateTime::class, $format, $context);
|
||||
|
||||
if ($object instanceof DateTime) {
|
||||
$person->setBirthdate($object);
|
||||
}
|
||||
$person->setBirthdate($object);
|
||||
|
||||
break;
|
||||
|
||||
case 'deathdate':
|
||||
$object = $this->denormalizer->denormalize($data[$item], DateTime::class, $format, $context);
|
||||
$object = $this->denormalizer->denormalize($data[$item], DateTimeImmutable::class, $format, $context);
|
||||
|
||||
if ($object instanceof DateTime) {
|
||||
$person->setDeathdate($object);
|
||||
}
|
||||
$person->setDeathdate($object);
|
||||
|
||||
break;
|
||||
|
||||
@@ -158,12 +154,14 @@ class PersonJsonNormalizer implements
|
||||
return $person;
|
||||
}
|
||||
|
||||
public function normalize($person, ?string $format = null, array $context = [])
|
||||
/**
|
||||
* @param Person $person
|
||||
* @param null|string $format
|
||||
*/
|
||||
public function normalize($person, $format = null, array $context = [])
|
||||
{
|
||||
/** @var Household $household */
|
||||
$household = $person->getCurrentHousehold();
|
||||
|
||||
/** @var Person $person */
|
||||
return [
|
||||
'type' => 'person',
|
||||
'id' => $person->getId(),
|
||||
@@ -182,12 +180,12 @@ class PersonJsonNormalizer implements
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsDenormalization($data, string $type, ?string $format = null)
|
||||
public function supportsDenormalization($data, $type, $format = null)
|
||||
{
|
||||
return Person::class === $type && 'person' === ($data['type'] ?? null);
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null): bool
|
||||
public function supportsNormalization($data, $format = null): bool
|
||||
{
|
||||
return $data instanceof Person && 'json' === $format;
|
||||
}
|
||||
|
Reference in New Issue
Block a user