mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
Set requestor for accompanying period
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user