Apply strict_types and extensive type declarations throughout the API and models, improving type safety and error handling. Key changes: add declare(strict_types=1) to many files; convert properties, method parameters and return values to typed signatures (PDO, arrays, ints, strings, bools, nullables); switch exception handling to Throwable in index and Router; improve Router, controllers and model method signatures and nullability handling; refine file/image serving security checks and headers in ImageController; strengthen Database typing and initialization methods; return explicit types from BaseModel CRUD helpers and counting; update Media/Cast/Adult/Game/Console/Settings controllers and models to use typed methods, better validation, and clearer update/create return types. Also add AGENTS.md (agent skills index), update README with Swagger/OpenAPI usage instructions, and add /.windsurf to .gitignore. These changes aim to harden runtime correctness, make intended contracts explicit, and prepare the codebase for easier maintenance and static analysis.
40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
error_log("API Request: " . $_SERVER['REQUEST_METHOD'] . " " . $_SERVER['REQUEST_URI']);
|
|
require_once __DIR__ . '/config.php';
|
|
require_once __DIR__ . '/database.php';
|
|
require_once __DIR__ . '/Router.php';
|
|
|
|
// JSON-Response-Header
|
|
header('Content-Type: application/json');
|
|
|
|
// Request-Method und Pfad ermitteln
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
$requestUri = $_SERVER['REQUEST_URI'];
|
|
$path = parse_url($requestUri, PHP_URL_PATH);
|
|
|
|
// Base-Path entfernen
|
|
$basePath = API_BASE;
|
|
if (strpos($path, $basePath) === 0) {
|
|
$path = substr($path, strlen($basePath));
|
|
}
|
|
|
|
// Pfad in Segmente aufteilen
|
|
$pathSegments = array_filter(explode('/', trim($path, '/')));
|
|
|
|
// Datenbankverbindung und Router
|
|
$db = new Database();
|
|
$pdo = $db->getConnection();
|
|
$router = new Router($pdo);
|
|
|
|
// Routing
|
|
try {
|
|
$response = $router->route($method, $pathSegments);
|
|
echo json_encode($response);
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|