black-sheep-bluff/app/Core/Controller.php
2026-09-18 06:46:56 +02:00

34 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
/**
* Basis für Seiten-Controller. Rendert eine View – optional im gemeinsamen
* Layout (Startseite/Regeln/Legal) oder als eigenständiges Dokument
* (Spiel/Login/Profil/Admin, die eigene Nav + noindex mitbringen).
*/
abstract class Controller
{
/** @param array<string,mixed> $meta */
protected function view(string $page, array $meta = [], bool $layout = true): void
{
$viewFile = BSB_BASE . '/app/Views/pages/' . $page . '.php';
if (!is_file($viewFile)) {
http_response_code(500);
echo 'View fehlt: ' . htmlspecialchars($page, ENT_QUOTES);
return;
}
if (!$layout) {
require $viewFile;
return;
}
// Variablen für app/Views/layout.php
$title = (string) ($meta['title'] ?? 'Black Sheep Bluff');
$description = (string) ($meta['description'] ?? '');
$cssFiles = (array) ($meta['css'] ?? []);
$jsFiles = (array) ($meta['js'] ?? []);
$bodyClass = (string) ($meta['bodyClass'] ?? '');
require BSB_BASE . '/app/Views/layout.php';
}
}