Set requestor for accompanying period

This commit is contained in:
2021-05-10 15:59:34 +02:00
parent 3447117742
commit 4f3f16d9b0
10 changed files with 193 additions and 19 deletions

View File

@@ -4,13 +4,18 @@ namespace Chill\ThirdPartyBundle\Repository;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Query;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
/**
* ThirdPartyRepository
*
*/
class ThirdPartyRepository extends \Doctrine\ORM\EntityRepository
class ThirdPartyRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ThirdParty::class);
}
/**
* count amongst parties associated to $centers, with $terms parameters
*

View File

@@ -6,11 +6,24 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Exception\RuntimeException;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterface
class ThirdPartyNormalizer implements NormalizerInterface, DenormalizerInterface, NormalizerAwareInterface
{
private ThirdPartyRepository $repository;
use NormalizerAwareTrait;
public function __construct(ThirdPartyRepository $repository)
{
$this->repository= $repository;
}
public function normalize($thirdParty, string $format = null, array $context = [])
{
/** @var $thirdParty ThirdParty */
@@ -28,4 +41,30 @@ class ThirdPartyNormalizer implements NormalizerInterface, NormalizerAwareInterf
{
return $data instanceof ThirdParty;
}
public function denormalize($data, string $type, string $format = null, array $context = [])
{
$thirdParty = $context[AbstractNormalizer::OBJECT_TO_POPULATE] ?? NULL;
if (NULL === $thirdParty) {
$id = $data['thirdparty_id'] ?? NULL;
if (NULL === $id) {
throw new RuntimeException("mission thirdparty_id into body");
}
$thirdParty = $this->repository->findOneById($id);
if (NULL === $thirdParty) {
throw new UnexpectedValueException("thirdparty not found");
}
}
return $thirdParty;
}
public function supportsDenormalization($data, string $type, string $format = null)
{
return ThirdParty::class === $type;
}
}

View File

@@ -1,2 +1,13 @@
---
services:
Chill\ThirdPartyBundle\Serializer\Normalizer\:
autowire: true
resource: '../Serializer/Normalizer/'
tags:
- { name: 'serializer.normalizer', priority: 64 }
Chill\ThirdPartyBundle\Repository\:
autowire: true
resource: '../Repository/'
tags:
- { name: 'doctrine.repository_service' }

View File

@@ -1,5 +1 @@
services:
Chill\ThirdPartyBundle\Serializer\Normalizer\:
resource: '../../Serializer/Normalizer/'
tags:
- { name: 'serializer.normalizer', priority: 64 }