Skip to content

Commit 8aec7b6

Browse files
committed
mention that data is json array in supportsTransformation (input)
1 parent 473dca5 commit 8aec7b6

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/dto.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ final class BookInputDataTransformer implements DataTransformerInterface
7878
*/
7979
public function supportsTransformation($data, string $to, array $context = []): bool
8080
{
81-
return Book::class === $to && $data instanceof BookInput;
81+
// in the case of an input, the value given here is an array (the JSON decoded).
82+
// if it's a book we transformed the data already
83+
if ($data instanceof Book) {
84+
return false;
85+
}
86+
87+
return Book::class === $to && null !== ($context['input']['class'] ?? null);
8288
}
8389
}
8490
```
@@ -205,7 +211,11 @@ final class BookInputDataTransformer implements DataTransformerInterface
205211
*/
206212
public function supportsTransformation($data, string $to, array $context = []): bool
207213
{
208-
return Book::class === $to && $data instanceof BookInput;
214+
if ($data instanceof Book) {
215+
return false;
216+
}
217+
218+
return Book::class === $to && null !== ($context['input']['class'] ?? null);
209219
}
210220
}
211221
```

0 commit comments

Comments
 (0)