- App\Controllers\LocaleController: GET /locale?set=xx&return=/path - Sets 1-year cookie (HttpOnly=false for SSR, SameSite=Lax, Secure on HTTPS) - 302 redirect to explicit return URL > Referer > / - Pure buildResponse() helper for unit tests (no headers/exit) - current() helper: resolves locale from $_GET/$_COOKIE/Accept-Language - safeRedirect: rejects absolute URLs, protocol-relative (//evil.com), backslash tricks (\\evil.com), javascript:/data: schemes - 28 PHPUnit tests (LocaleControllerTest), all green - Total project tests now: 92
26 lines
686 B
PHP
Executable File
26 lines
686 B
PHP
Executable File
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
/*
|
||
* Front Controller – Single Entry Point
|
||
* All requests are routed through this file.
|
||
*/
|
||
|
||
// Autoloader (composer PSR-4)
|
||
require_once __DIR__ . '/../vendor/autoload.php';
|
||
|
||
use App\Core\Router;
|
||
|
||
$router = new Router();
|
||
|
||
// Define routes
|
||
$router->addRoute('/', \App\Controllers\HomeController::class, 'index');
|
||
$router->addRoute('/impressum', \App\Controllers\ImpressumController::class, 'index');
|
||
$router->addRoute('/datenschutz', \App\Controllers\DatenschutzController::class, 'index');
|
||
$router->addRoute('/locale', \App\Controllers\LocaleController::class, 'switch');
|
||
|
||
// Dispatch
|
||
$uri = $_SERVER['REQUEST_URI'] ?? '/';
|
||
$router->dispatch($uri);
|