viewsPath = $viewsPath ?? dirname(__DIR__) . '/views'; } public function assign(string $key, mixed $value): void { $this->data[$key] = $value; } public function render(string $view, string $layout = 'main'): void { $viewFile = $this->viewsPath . '/' . $view . '.php'; $layoutFile = $this->viewsPath . '/layouts/' . $layout . '.php'; if (!file_exists($viewFile)) { throw new \RuntimeException("View {$view} nicht gefunden: {$viewFile}"); } if (!file_exists($layoutFile)) { throw new \RuntimeException("Layout {$layout} nicht gefunden: {$layoutFile}"); } // Extract data to variables for the view extract($this->data, EXTR_SKIP); // Capture view content ob_start(); require $viewFile; $content = ob_get_clean(); // Render layout with $content require $layoutFile; } }