refactor: Umstellung auf Mini-MVC-Architektur (Issue #46)
All checks were successful
Deploy Feature Branch to Test / deploy (push) Successful in 24s
All checks were successful
Deploy Feature Branch to Test / deploy (push) Successful in 24s
- Front Controller Pattern mit public/index.php als Einstiegspunkt - Eigenes Routing (App\Core\Router) ohne externes Framework - Controller: HomeController, ImpressumController, DatenschutzController - Views mit gemeinsamem Layout (app/views/layouts/main.php) - PSR-4 Autoloading - Statische Assets nach public/ verschoben - Alte Dateien (index.php, impressum.html, datenschutz.html) geloescht - 301-Redirects fuer alte URLs - PHP 8.5 kompatibel - Apache DocumentRoot auf public/ gesetzt
This commit is contained in:
44
public/index.php
Normal file
44
public/index.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Front Controller – Single Entry Point
|
||||
* All requests are routed through this file.
|
||||
*/
|
||||
|
||||
// Autoloader (PSR-4 style, simple)
|
||||
spl_autoload_register(function (string $class): void {
|
||||
$prefix = 'App\\';
|
||||
$baseDir = __DIR__ . '/../app/';
|
||||
|
||||
$len = strlen($prefix);
|
||||
if (strncmp($prefix, $class, $len) !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$relativeClass = substr($class, $len);
|
||||
// Lowercase directory names, keep class name case
|
||||
$parts = explode('\\', $relativeClass);
|
||||
$className = array_pop($parts);
|
||||
$parts = array_map('strtolower', $parts);
|
||||
$parts[] = $className;
|
||||
$file = $baseDir . implode('/', $parts) . '.php';
|
||||
|
||||
if (file_exists($file)) {
|
||||
require $file;
|
||||
}
|
||||
});
|
||||
|
||||
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');
|
||||
|
||||
// Dispatch
|
||||
$uri = $_SERVER['REQUEST_URI'] ?? '/';
|
||||
$router->dispatch($uri);
|
||||
Reference in New Issue
Block a user