- home: map 9/12 gallery items to real filenames (Wohnzimmer-1 -> wohnzimmer2.png, Badezimmer-1 -> Bad.jpg, etc.); remove 3 items whose source images are missing - home: hero-bg.jpg -> Außenansicht-2.webp (file exists) - home: floorplan image -> /bilder/grundrisse/<name>.png (subdir + correct name) - layout: og:image fallback Aussenansicht-2.webp (ASCII) -> Außenansicht-2.png (UTF-8) - layout: hero-bg.jpg fallback -> Außenansicht-2.png (UTF-8) - Controller::render(): add $forceLocale param for legal pages - ImpressumController / DatenschutzController: force 'de' (TMG §5 / GDPR) so <html lang=de> is emitted regardless of cookie
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Core\I18n;
|
|
use App\Core\Locale;
|
|
use App\Core\View;
|
|
|
|
/**
|
|
* Base controller — injects i18n globals (locale, t() helper, locale switcher)
|
|
* into every render() call so views can use `$t('key')` and `$locale` directly.
|
|
*/
|
|
abstract class Controller
|
|
{
|
|
protected View $view;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->view = new View();
|
|
}
|
|
|
|
/**
|
|
* Render a view inside a layout.
|
|
*
|
|
* @param array<string,mixed> $data
|
|
* @param string|null $forceLocale If set, overrides the locale resolved from
|
|
* cookie/Accept-Language for this render. Used by legal pages (Impressum,
|
|
* Datenschutz) that must be served in German only by German law.
|
|
*/
|
|
protected function render(string $view, array $data = [], string $layout = 'main', ?string $forceLocale = null): void
|
|
{
|
|
$locale = $forceLocale ?? LocaleController::current();
|
|
$i18n = static fn (string $key, array $params = []): string => I18n::t($key, $params, $locale);
|
|
|
|
$globals = [
|
|
'locale' => $locale,
|
|
't' => $i18n,
|
|
'locale_switcher' => static function (string $currentPath) use ($locale): string {
|
|
$switcher = new LocaleSwitcher($locale, $currentPath);
|
|
return $switcher->render();
|
|
},
|
|
];
|
|
|
|
$merged = array_merge($globals, $data);
|
|
|
|
foreach ($merged as $key => $value) {
|
|
$this->view->assign($key, $value);
|
|
}
|
|
$this->view->render($view, $layout);
|
|
}
|
|
}
|