View file app\Core\View.php

File size: 477B
<?php

namespace App\Core;

class View
{
    public static function render(string $view, array $data = []): string
    {
        extract($data);
        ob_start();
        $viewPath = __DIR__ . "/../../views/" . str_replace('.', '/', $view) . ".php";
        if (file_exists($viewPath)) {
            require $viewPath;
        } else {
            throw new \Exception("View $view not found at $viewPath");
        }
        return ob_get_clean();
    }
}