Files
domnitor/core/Controller.php
Hosteroid db094d6d8b Use Twig-only rendering and improve error fallback
Remove legacy PHP view fallbacks and always render Twig templates (Controller, Router). Update ErrorHandler to attempt Twig rendering and provide a safe, escaped minimal HTML fallback on failure instead of requiring PHP views. Also pass whoisData into the domain view. These changes standardize on Twig templates and harden error output.
2026-03-04 11:16:56 +02:00

49 lines
1.0 KiB
PHP

<?php
namespace Core;
abstract class Controller
{
protected function view(string $view, array $data = []): void
{
$twig = TwigService::getInstance();
echo $twig->render("$view.twig", $data);
}
protected function json($data, int $status = 200): void
{
http_response_code($status);
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
protected function redirect(string $path): void
{
header("Location: $path");
exit;
}
/**
* Verify CSRF token and redirect with error if invalid
*
* @param string $redirectUrl URL to redirect to on failure
* @return bool True if valid, redirects on failure
*/
protected function verifyCsrf(string $redirectUrl = '/'): bool
{
return Csrf::verifyOrFail($redirectUrl);
}
/**
* Get CSRF token for forms
*
* @return string The CSRF token
*/
protected function getCsrfToken(): string
{
return Csrf::getToken();
}
}