src/Responder/TemplateResponder.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types 1);
  3. namespace App\Responder;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Twig\Environment;
  6. final class TemplateResponder
  7. {
  8.     public function __construct(
  9.          Environment $twig
  10.     ) {
  11.         $this->twig $twig;
  12.     }
  13.     public function __invoke(
  14.         string $template,
  15.         array $params = [],
  16.         $status Response::HTTP_OK
  17.     ): Response
  18.     {
  19.         $response = new Response(
  20.             $this->twig->render(
  21.                 $template,
  22.                 $params
  23.             ),  $status
  24.         );
  25.         $response->setSharedMaxAge(3600);
  26.         return $response;
  27.     }
  28. }