Squashed commit of the following:

commit 977863c2dd56d5c835f2a710cad7f7d3ba42da68
Merge: 5c37b419d 3eb7ffed1
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 14:45:21 2021 +0100

    Merge remote-tracking branch 'origin/master' into docgen/improve-normalizer

commit 5c37b419ddf0b32b9950c33042396bba1860da84
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 14:37:05 2021 +0100

    fix normalization for user and type in null value

commit 4469d46cdb19051fedec86bbb84e2351e6fcb72e
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 13:24:23 2021 +0100

    add civility to person

commit 6cf92fbbde8f4d9f2f4763ec4ee88216257040f7
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 13:19:36 2021 +0100

    fix person normalization: add a isNull on not null person

commit ed6087ff8fd47b80ea5e9526756fe5d032d478e3
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 13:08:46 2021 +0100

    fix stan and cs issues

commit 8429c334c33b3545835cbde034fccaa529c134a7
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 13:08:36 2021 +0100

    fix id type

commit 39ae00d172a9f29320a97abb8518b2ea48d89d9b
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sun Dec 12 12:52:41 2021 +0100

    fix test and fix null or not-null value have same keys

commit 312fcc44c07affa7aa60f6c5fce58f9d1c564cc3
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sat Dec 11 03:27:30 2021 +0100

    improve normalization wip

commit f91a29635827005fc58617dc1c9d210091372be5
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sat Dec 11 01:15:32 2021 +0100

    improve normalization

commit 56060e5e6a2191ef441039fdc91a01fb4653a553
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Sat Dec 11 00:41:09 2021 +0100

    handle changelog with translatable string

commit 9004686a13
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Fri Dec 10 01:10:55 2021 +0100

    improve docgen wip

commit e266fa0e5d
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Thu Dec 9 21:50:56 2021 +0100

    show errors from relatorio driver

commit 75ba56fa09
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Thu Dec 9 21:14:12 2021 +0100

    add verification tool for admin

commit 12d6829b98
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Thu Dec 9 14:17:42 2021 +0100

    fix type with phonenumber helper

commit 7b5e96771f
Merge: 8a9024de1 8a4748dc2
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Thu Dec 9 14:11:14 2021 +0100

    Merge remote-tracking branch 'origin/master' into docgen/improve-normalizer

commit 8a9024de13
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Thu Dec 9 13:51:36 2021 +0100

    add docgen:normalization for relation

commit 24a404964b
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Thu Dec 9 12:44:41 2021 +0100

    docgen normalization for relation

commit 5d24bd4d11
Merge: 70ab23214 455b225f4
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 21:08:30 2021 +0100

    Merge branch 'master' into docgen/improve-normalizer

commit 70ab232149
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 13:58:49 2021 +0100

    improve docgen, trnslations, admin

commit 027c01fc58
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 12:23:24 2021 +0100

    fix css block

commit fdc5127c74
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:57:16 2021 +0100

    fix some error in test (wip)

commit b8d48f04ae
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:47:50 2021 +0100

    fix tests (wip)

commit f1b1771d6b
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:35:00 2021 +0100

    fix tests (wip)

commit 62dabbe1e7
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:14:46 2021 +0100

    fix code style

commit 4101392190
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:13:49 2021 +0100

    fix tests and type hinting

commit 3f1bed0b1c
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:05:41 2021 +0100

    fix tests (wip)

commit 79fbdcdee4
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 11:05:29 2021 +0100

    type hint User class

commit 3d8d79323e
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 10:56:30 2021 +0100

    remove error messages

commit 32178e22fe
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 10:51:30 2021 +0100

    fix tests (wip)

commit 60a8c20896
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 10:29:54 2021 +0100

    update app

commit 9d8011da61
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 10:06:35 2021 +0100

    fix loading origin

commit 789eeadb40
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 09:52:51 2021 +0100

    fix loading fixtures for doc generator template

commit f206fdb08c
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 09:52:35 2021 +0100

    fix code style

commit 9d5409d8d9
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 09:52:06 2021 +0100

    fix casting

commit e297d82533
Author: Julien Fastré <julien.fastre@champs-libres.coop>
Date:   Wed Dec 8 09:26:13 2021 +0100

    fixes on tests [WIP]
This commit is contained in:
2021-12-12 14:46:37 +01:00
parent 3eb7ffed1a
commit 839fb4a211
55 changed files with 1401 additions and 305 deletions

View File

@@ -11,55 +11,115 @@ declare(strict_types=1);
namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\DocGeneratorBundle\Serializer\Helper\NormalizeNullValueHelper;
use Chill\MainBundle\Entity\Address;
use DateTimeInterface;
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;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface
class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
{
use NormalizerAwareTrait;
private const NULL_POSTCODE_COUNTRY = [
'id', 'name', 'code',
];
private const NULL_VALUE = [
'address_id',
'text',
'street',
'streetNumber',
'postcode',
'country',
'floor',
'corridor',
'steps',
'flat',
'buildingName',
'distribution',
'extra',
'validFrom' => DateTimeInterface::class,
'validTo' => DateTimeInterface::class,
];
/**
* @param Address $address
*/
public function normalize($address, ?string $format = null, array $context = [])
{
return [
'address_id' => $address->getId(),
'text' => $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet(),
'street' => $address->getStreet(),
'streetNumber' => $address->getStreetNumber(),
'postcode' => [
'id' => $address->getPostCode()->getId(),
'name' => $address->getPostCode()->getName(),
'code' => $address->getPostCode()->getCode(),
],
'country' => [
'id' => $address->getPostCode()->getCountry()->getId(),
'name' => $address->getPostCode()->getCountry()->getName(),
'code' => $address->getPostCode()->getCountry()->getCountryCode(),
],
'floor' => $address->getFloor(),
'corridor' => $address->getCorridor(),
'steps' => $address->getSteps(),
'flat' => $address->getFlat(),
'buildingName' => $address->getBuildingName(),
'distribution' => $address->getDistribution(),
'extra' => $address->getExtra(),
'validFrom' => $address->getValidFrom(),
'validTo' => $address->getValidTo(),
'addressReference' => $this->normalizer->normalize(
$address->getAddressReference(),
$format,
[AbstractNormalizer::GROUPS => ['read']]
),
];
if ($address instanceof Address) {
$data = [
'address_id' => $address->getId(),
'text' => $address->isNoAddress() ? '' : $address->getStreetNumber() . ', ' . $address->getStreet(),
'street' => $address->getStreet(),
'streetNumber' => $address->getStreetNumber(),
'postcode' => [
'id' => $address->getPostCode()->getId(),
'name' => $address->getPostCode()->getName(),
'code' => $address->getPostCode()->getCode(),
],
'country' => [
'id' => $address->getPostCode()->getCountry()->getId(),
'name' => $address->getPostCode()->getCountry()->getName(),
'code' => $address->getPostCode()->getCountry()->getCountryCode(),
],
'floor' => $address->getFloor(),
'corridor' => $address->getCorridor(),
'steps' => $address->getSteps(),
'flat' => $address->getFlat(),
'buildingName' => $address->getBuildingName(),
'distribution' => $address->getDistribution(),
'extra' => $address->getExtra(),
];
if ('json' === $format) {
$data['addressReference'] = $this->normalizer->normalize(
$address->getAddressReference(),
$format,
[AbstractNormalizer::GROUPS => ['read']]
);
$data['validFrom'] = $address->getValidFrom();
$data['validTo'] = $address->getValidTo();
} elseif ('docgen' === $format) {
$dateContext = array_merge($context, ['docgen:expects' => DateTimeInterface::class]);
$data['validFrom'] = $this->normalizer->normalize($address->getValidFrom(), $format, $dateContext);
$data['validTo'] = $this->normalizer->normalize($address->getValidTo(), $format, $dateContext);
}
return $data;
}
if (null === $address) {
$helper = new NormalizeNullValueHelper($this->normalizer);
return array_merge(
$helper->normalize(self::NULL_VALUE, $format, $context),
[
'postcode' => $helper->normalize(self::NULL_POSTCODE_COUNTRY, $format, $context),
'country' => $helper->normalize(self::NULL_POSTCODE_COUNTRY, $format, $context),
]
);
}
throw new UnexpectedValueException();
}
public function supportsNormalization($data, ?string $format = null)
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
{
return $data instanceof Address;
if ('json' === $format) {
return $data instanceof Address;
}
if ('docgen' === $format) {
return
$data instanceof Address
|| (null === $data && Address::class === ($context['docgen:expects'] ?? null));
}
return false;
}
}

View File

@@ -11,16 +11,28 @@ declare(strict_types=1);
namespace Chill\MainBundle\Serializer\Normalizer;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Templating\Entity\UserRender;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class UserNormalizer implements NormalizerAwareInterface, NormalizerInterface
class UserNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
{
use NormalizerAwareTrait;
public const NULL_USER = [
'type' => 'user',
'id' => '',
'username' => '',
'text' => '',
'label' => '',
'email' => '',
];
private UserRender $userRender;
public function __construct(UserRender $userRender)
@@ -31,20 +43,50 @@ class UserNormalizer implements NormalizerAwareInterface, NormalizerInterface
public function normalize($user, ?string $format = null, array $context = [])
{
/** @var User $user */
$userJobContext = array_merge(
$context,
['docgen:expects' => UserJob::class, 'groups' => 'docgen:read']
);
$scopeContext = array_merge(
$context,
['docgen:expects' => Scope::class, 'groups' => 'docgen:read']
);
$centerContext = array_merge(
$context,
['docgen:expects' => Center::class, 'groups' => 'docgen:read']
);
if (null === $user && 'docgen' === $format) {
return array_merge(self::NULL_USER, [
'user_job' => $this->normalizer->normalize(null, $format, $userJobContext),
'main_center' => $this->normalizer->normalize(null, $format, $centerContext),
'main_scope' => $this->normalizer->normalize(null, $format, $scopeContext),
]);
}
return [
'type' => 'user',
'id' => $user->getId(),
'username' => $user->getUsername(),
'text' => $this->userRender->renderString($user, []),
'label' => $user->getLabel(),
'user_job' => $this->normalizer->normalize($user->getUserJob(), $format, $context),
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $context),
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $context),
'email' => (string) $user->getEmail(),
'user_job' => $this->normalizer->normalize($user->getUserJob(), $format, $userJobContext),
'main_center' => $this->normalizer->normalize($user->getMainCenter(), $format, $centerContext),
'main_scope' => $this->normalizer->normalize($user->getMainScope(), $format, $scopeContext),
];
}
public function supportsNormalization($data, ?string $format = null): bool
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
{
return $data instanceof User && ('json' === $format || 'docgen' === $format);
if ($data instanceof User && ('json' === $format || 'docgen' === $format)) {
return true;
}
if (null === $data && 'docgen' === $format && User::class === ($context['docgen:expects'] ?? null)) {
return true;
}
return false;
}
}