mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
Merge remote-tracking branch 'origin/master' into homepage/rewrite
This commit is contained in:
@@ -45,6 +45,7 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
|
||||
'extra',
|
||||
'validFrom' => DateTimeInterface::class,
|
||||
'validTo' => DateTimeInterface::class,
|
||||
'confidential',
|
||||
];
|
||||
|
||||
private AddressRender $addressRender;
|
||||
@@ -83,6 +84,7 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
|
||||
'buildingName' => $address->getBuildingName(),
|
||||
'distribution' => $address->getDistribution(),
|
||||
'extra' => $address->getExtra(),
|
||||
'confidential' => $address->getConfidential(),
|
||||
'lines' => $this->addressRender->renderLines($address),
|
||||
];
|
||||
|
||||
|
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Serializer\Normalizer;
|
||||
|
||||
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use DateTime;
|
||||
use Symfony\Component\Serializer\Exception\ExceptionInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
|
||||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
|
||||
use function array_key_exists;
|
||||
|
||||
class CommentEmbeddableDocGenNormalizer implements ContextAwareNormalizerInterface, NormalizerAwareInterface
|
||||
{
|
||||
use NormalizerAwareTrait;
|
||||
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommentEmbeddable $object
|
||||
*
|
||||
* @throws ExceptionInterface
|
||||
*/
|
||||
public function normalize($object, ?string $format = null, array $context = []): array
|
||||
{
|
||||
if (null === $object) {
|
||||
return [
|
||||
'comment' => '',
|
||||
'isNull' => true,
|
||||
'date' => $this->normalizer->normalize(null, $format, array_merge($context, [
|
||||
'docgen:expects' => DateTime::class,
|
||||
])),
|
||||
'user' => $this->normalizer->normalize(null, $format, array_merge($context, [
|
||||
'docgen:expects' => User::class,
|
||||
])),
|
||||
];
|
||||
}
|
||||
|
||||
$user = $this->userRepository->find($object->getUserId());
|
||||
|
||||
return [
|
||||
'comment' => (string) $object->getComment(),
|
||||
'isNull' => false,
|
||||
'date' => $this->normalizer->normalize($object->getDate(), $format, array_merge($context, [
|
||||
'docgen:expects' => DateTime::class,
|
||||
])),
|
||||
'user' => $this->normalizer->normalize($user, $format, array_merge($context, [
|
||||
'docgen:expects' => User::class,
|
||||
])),
|
||||
];
|
||||
}
|
||||
|
||||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool
|
||||
{
|
||||
if ('docgen' !== $format) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($data instanceof CommentEmbeddable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
null === $data
|
||||
&& array_key_exists('docgen:expects', $context)
|
||||
&& CommentEmbeddable::class === $context['docgen:expects']) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user