Goal-Calibration/app/View/ViewController.php

37 lines
940 B
PHP

<?php
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);
$response->getBody()->write($html);
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;
}
}