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\RedirectResponse; |
||
8 | use Symfony\Component\HttpFoundation\RedirectResponse as SymfonyRedirectResponse; |
||
9 | use Symfony\Component\HttpFoundation\Response; |
||
10 | use Symfony\Component\Routing\RouterInterface; |
||
11 | |||
12 | /** |
||
13 | * Class RedirectResponseHandler. |
||
14 | */ |
||
15 | final class RedirectResponseHandler extends AbstractLazyResponseHandler |
||
16 | { |
||
17 | /** |
||
18 | * @var \Symfony\Component\Routing\RouterInterface |
||
19 | */ |
||
20 | private $router; |
||
21 | |||
22 | 4 | public function __construct(RouterInterface $router) |
|
23 | { |
||
24 | 4 | $this->router = $router; |
|
25 | 4 | } |
|
26 | |||
27 | 3 | protected function isSupported(LazyResponseInterface $controllerResult): bool |
|
28 | { |
||
29 | 3 | return $controllerResult instanceof RedirectResponse; |
|
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param RedirectResponse $controllerResult |
||
34 | * |
||
35 | * @psalm-suppress MoreSpecificImplementedParamType |
||
36 | */ |
||
37 | 3 | protected function generateResponse(LazyResponseInterface $controllerResult): Response |
|
38 | { |
||
39 | 3 | return new SymfonyRedirectResponse( |
|
40 | 3 | $this->router->generate( |
|
41 | 3 | $controllerResult->getRouteName(), |
|
42 | 3 | $controllerResult->getRouteParams() |
|
43 | ), |
||
44 | 3 | $controllerResult->getStatusCode(), |
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
45 | 3 | $controllerResult->getHeaders() |
|
46 | ); |
||
47 | } |
||
48 | } |
||
49 |