url = $url; $this->serviceKey = $serviceKey; } /** * حفظ بيانات الإضافة في Supabase. */ public function saveAddon(array $addonData): array { $url = $this->url . '/rest/v1/addons'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($addonData)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'apikey: ' . $this->serviceKey, 'Authorization: Bearer ' . $this->serviceKey, 'Content-Type: application/json', 'Prefer: return=representation' ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode >= 400) { $errorData = json_decode($response, true); $errorMessage = $errorData['message'] ?? $errorData['error'] ?? $response; throw new Exception("فشل حفظ البيانات في Supabase: " . $errorMessage); } $data = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception("فشل في تحليل استجابة Supabase: " . json_last_error_msg()); } return $data; } }