<?php

declare(strict_types=1);

class Controller
{
    protected function view(string $view, array $data = [], string $layout = 'public'): void
    {
        extract($data);

        $viewFile = __DIR__ . '/../views/' . $view . '.php';
        $layoutFile = __DIR__ . '/../views/layouts/' . $layout . '.php';

        if (!file_exists($viewFile)) {
            throw new RuntimeException('View não encontrada: ' . $view);
        }

        require $layoutFile;
    }

    protected function redirect(string $path): void
    {
        header('Location: ' . base_url($path));
        exit;
    }
}
