<?php
declare(strict_types = 1);
namespace App\Responder;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
final class TemplateResponder
{
public function __construct(
Environment $twig
) {
$this->twig = $twig;
}
public function __invoke(
string $template,
array $params = [],
$status = Response::HTTP_OK
): Response
{
$response = new Response(
$this->twig->render(
$template,
$params
), $status
);
$response->setSharedMaxAge(3600);
return $response;
}
}