implement texts view method

This commit is contained in:
Yisroel Baum 2026-04-12 22:14:30 +03:00
parent 019f3a61e1
commit d4e31baed0
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -2,10 +2,15 @@
namespace App\View;
use App\Text\TextRepository;
use Psr\Http\Message\ResponseInterface as Response;
class ViewController
{
public function __construct(
private TextRepository $textRepository,
) {}
public function admin(Response $response): Response
{
$html = file_get_contents(__DIR__.'/../../views/templates/admin.php', true);
@ -13,4 +18,20 @@ class ViewController
return $response;
}
public function texts(Response $response): Response
{
$texts = $this->textRepository->getAll();
$textsList = '';
foreach ($texts as $text) {
$textsList .= '<li>' . htmlspecialchars($text->getName()) . '</li>';
}
$html = file_get_contents(__DIR__.'/../../views/templates/texts.php', true);
$html = str_replace('{{texts}}', $textsList, $html);
$response->getBody()->write($html);
return $response;
}
}