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