> * @throws RuntimeException */ function fetch_raids(string $status = 'active'): array { if (!in_array($status, RAID_STATUSES, true)) { $status = 'active'; } $configPath = __DIR__ . '/../config.php'; if (!file_exists($configPath)) { throw new RuntimeException('Konfigurationsdatei fehlt.'); } $config = require $configPath; $apiUrl = $config['raids_api']['url'] ?? ''; $apiKey = $config['raids_api']['key'] ?? ''; if ($apiUrl === '' || $apiKey === '') { throw new RuntimeException('Raid-API ist nicht konfiguriert (config.php: raids_api.url / raids_api.key fehlt).'); } if (!function_exists('curl_init')) { throw new RuntimeException('Die PHP-cURL-Erweiterung ist auf diesem Server nicht aktiviert.'); } $separator = str_contains($apiUrl, '?') ? '&' : '?'; $requestUrl = $apiUrl . $separator . 'status=' . urlencode($status); $ch = curl_init($requestUrl); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['X-API-Key: ' . $apiKey], CURLOPT_TIMEOUT => 10, CURLOPT_SSL_VERIFYPEER => true, ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); if ($response === false) { throw new RuntimeException('Verbindung zur Raid-API fehlgeschlagen: ' . $curlError); } if ($httpCode !== 200) { throw new RuntimeException('Raid-API antwortete mit Statuscode ' . $httpCode . '.'); } $data = json_decode($response, true); if (!is_array($data) || ($data['status'] ?? '') !== 'success' || !isset($data['raids']) || !is_array($data['raids'])) { throw new RuntimeException('Unerwartetes Antwortformat der Raid-API.'); } return $data['raids']; }