Add PHP Media API scaffold and Docker configs
Initial project scaffold for a PHP Media API including routing, controllers, models and services under api/ (Router, Media/Cast/Image/Settings controllers, models, database/bootstrap files and automatic docs service). Adds Docker support (Dockerfile, docker-compose.yml, DOCKER_README.md, php-custom.ini), .htaccess for pretty URLs, API documentation and example payloads (API_EXAMPLES.md, api/README.md, api_examples/*.json), image handling service and logging, plus a comprehensive .gitignore. This commit provides a runnable development environment and example requests to get the API up and tested quickly.
This commit is contained in:
37
api/index.php
Normal file
37
api/index.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
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 (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
Reference in New Issue
Block a user