<?php
declare(strict_types=1); namespace App\Http\Controllers; use App\Application\SettingsService; use App\Exceptions\HttpException; class SettingsController { private SettingsService $service; private string $inputStream; public function __construct(SettingsService $service, string $inputStream = 'php://input') { $this->service = $service; $this->inputStream = $inputStream; } public function index(): array { return [ 'status' => 200, 'body' => $this->service->getSettings() ]; } public function update(): array { $raw = file_get_contents($this->inputStream); if ($raw === false || trim($raw) === '') { throw new HttpException(400, 'Empty request body'); } $data = json_decode($raw, true); if (json_last_error() !== JSON_ERROR_NONE || !is_array($data)) { throw new HttpException(400, 'Invalid JSON format'); } $settings = $this->service->updateSettings($data); return [ 'status' => 200, 'body' => $settings ]; } } 