1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Basster\LazyResponseBundle\Response\Handler; |
||
5 | |||
6 | use Basster\LazyResponseBundle\Response\JsonSerializeResponse; |
||
7 | use Basster\LazyResponseBundle\Response\LazyResponseInterface; |
||
8 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
9 | use Symfony\Component\HttpFoundation\Response; |
||
10 | use Symfony\Component\Serializer\SerializerInterface; |
||
11 | |||
12 | /** |
||
13 | * Class JsonSerializeResponseHandler. |
||
14 | */ |
||
15 | final class JsonSerializeResponseHandler extends AbstractLazyResponseHandler |
||
16 | { |
||
17 | /** |
||
18 | * @var \Symfony\Component\Serializer\SerializerInterface |
||
19 | */ |
||
20 | private $serializer; |
||
21 | |||
22 | 4 | public function __construct(SerializerInterface $serializer) |
|
23 | { |
||
24 | 4 | $this->serializer = $serializer; |
|
25 | 4 | } |
|
26 | |||
27 | /** |
||
28 | * @param JsonSerializeResponse $controllerResult |
||
29 | * |
||
30 | * @psalm-suppress MoreSpecificImplementedParamType |
||
31 | */ |
||
32 | 3 | protected function generateResponse(LazyResponseInterface $controllerResult): Response |
|
33 | { |
||
34 | 3 | return new JsonResponse( |
|
35 | 3 | $this->serializer->serialize($controllerResult->getData(), 'json'), |
|
36 | 3 | $controllerResult->getStatus(), |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
37 | 3 | $controllerResult->getHeaders(), |
|
38 | ); |
||
39 | } |
||
40 | |||
41 | 3 | protected function isSupported(LazyResponseInterface $controllerResult): bool |
|
42 | { |
||
43 | 3 | return $controllerResult instanceof JsonSerializeResponse; |
|
44 | } |
||
45 | } |
||
46 |