view = new View(); } /** * Render a view inside a layout. * * @param array $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); } }