GET for relationship fixed: associated relation displayed

This commit is contained in:
2021-10-26 14:49:12 +02:00
parent 18ca01b0dc
commit b7466c7e85
3 changed files with 41 additions and 7 deletions

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Chill\PersonBundle\Serializer\Normalizer;
use Chill\PersonBundle\Entity\Relationships\Relationship;
use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectToPopulateTrait;
class RelationshipNormalizer implements NormalizerInterface, NormalizerAwareInterface
{
use NormalizerAwareTrait;
use ObjectToPopulateTrait;
use DenormalizerAwareTrait;
public function normalize($relationship, ?string $format = null, array $context = [])
{
return [
'type' => 'relationship',
'fromPerson' => $this->normalizer->normalize($relationship->getFromPerson()),
'toPerson' => $this->normalizer->normalize($relationship->getToPerson()),
'relation' => $this->normalizer->normalize($relationship->getRelation()),
'reverse' => $relationship->getReverse()
];
}
public function supportsNormalization($data, ?string $format = null)
{
return $data instanceof Relationship;
}
}