31 lines
683 B
PHP
31 lines
683 B
PHP
<?php
|
|
|
|
namespace App\Core;
|
|
|
|
final class View
|
|
{
|
|
public function __construct(
|
|
private readonly string $rootPath,
|
|
private readonly array $shared = []
|
|
) {
|
|
}
|
|
|
|
public function render(string $template, array $data = []): void
|
|
{
|
|
$templateFile = $this->rootPath . '/resources/views/' . $template . '.php';
|
|
|
|
if (!is_file($templateFile)) {
|
|
http_response_code(500);
|
|
echo 'View not found: ' . htmlspecialchars($template, ENT_QUOTES, 'UTF-8');
|
|
return;
|
|
}
|
|
|
|
$shared = $this->shared;
|
|
|
|
extract($shared, EXTR_SKIP);
|
|
extract($data, EXTR_SKIP);
|
|
|
|
require $templateFile;
|
|
}
|
|
}
|