Files
mystuff_backend/api/controllers/SettingsController.php
Lars Behrends 66f69bc90d 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.
2026-04-12 00:46:30 +02:00

62 lines
1.8 KiB
PHP

<?php
require_once __DIR__ . '/../models/Settings.php';
require_once __DIR__ . '/../services/ApiLogger.php';
class SettingsController {
private $settings;
private $logger;
public function __construct($pdo) {
$this->settings = new Settings($pdo);
$this->logger = ApiLogger::getInstance();
}
public function handleRequest($method, $segments) {
$path = '/' . implode('/', $segments);
$this->logger->logRequest($method, $path);
switch ($method) {
case 'GET':
return $this->get();
case 'PUT':
return $this->update();
default:
http_response_code(405);
return ['success' => false, 'error' => 'Method not allowed'];
}
}
private function get() {
$settings = $this->settings->getSettings();
if (!$settings) {
http_response_code(404);
return ['success' => false, 'error' => 'Settings not found'];
}
return ['success' => true, 'data' => $settings];
}
private function update() {
$data = json_decode(file_get_contents('php://input'), true);
if (!$data) {
http_response_code(400);
return ['success' => false, 'error' => 'Invalid JSON'];
}
$settings = $this->settings->updateSettings($data);
if (!$settings) {
http_response_code(500);
return ['success' => false, 'error' => 'Failed to update settings'];
}
$this->logger->logRequest('PUT', '/api/settings', [], $data);
$this->logger->logResponse('PUT', '/api/settings', 200, $settings);
return ['success' => true, 'data' => $settings];
}
}