type variable added and file renamed in transformer

This commit is contained in:
Julie Lenaerts 2022-01-21 15:01:12 +01:00
parent 420f81ea24
commit 6d07168529

View File

@ -25,13 +25,16 @@ class UserToJsonTransformer implements DataTransformerInterface
private bool $multiple; private bool $multiple;
private string $type;
private SerializerInterface $serializer; private SerializerInterface $serializer;
public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple) public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, bool $multiple, string $type)
{ {
$this->denormalizer = $denormalizer; $this->denormalizer = $denormalizer;
$this->serializer = $serializer; $this->serializer = $serializer;
$this->multiple = $multiple; $this->multiple = $multiple;
$this->type = $type;
} }
public function reverseTransform($value) public function reverseTransform($value)
@ -78,7 +81,7 @@ class UserToJsonTransformer implements DataTransformerInterface
return return
$this->denormalizer->denormalize( $this->denormalizer->denormalize(
['type' => $item['type'], 'id' => $item['id']], ['type' => $this->type, 'id' => $item['id']],
User::class, User::class,
'json', 'json',
[AbstractNormalizer::GROUPS => ['read']], [AbstractNormalizer::GROUPS => ['read']],