HttpOperations
đ§ initCurl
Initialize cURL with common options
function initCurl(string $url, string $method, array $headers = []): void {
$this->ch = curl_init();
$finalHeaders = array_merge($this->defaultHeaders, $headers);
// Ensure we have the username and password
if (empty($this->username) || empty($this->password)) {
error_log("Warning: Missing authentication credentials for CalDAV request");
}
// Set up the cURL options
$options = [
CURLOPT_URL => $url,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_RETURNTRANSFER => true,
// ... (truncated)
âī¸ Parameters
- $url (string)
- $method (string)
- $headers (array)
âŠī¸ Returns
(void)
đ§ executeRequest
Execute cURL request and handle response
function executeRequest(): array {
$response = curl_exec($this->ch);
$httpCode = curl_getinfo($this->ch, CURLINFO_HTTP_CODE);
$this->lastCurlInfo = curl_getinfo($this->ch);
if ($response === false) {
$error = curl_error($this->ch);
curl_close($this->ch);
throw new \Exception("cURL error: " . $error);
}
curl_close($this->ch);
// ... (truncated)
âŠī¸ Returns
(array)
đ§ sendPutRequest
Send a PUT request
function sendPutRequest(string $url, string $data, array $headers = []): array {
$this->initCurl($url, 'PUT', array_merge($headers, [
'Content-Type: text/calendar; charset=utf-8',
'Content-Length: ' . strlen($data)
]));
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $data);
return $this->executeRequest();
}
âī¸ Parameters
- $url (string)
- $data (string)
- $headers (array)
âŠī¸ Returns
(array)
đ§ sendDeleteRequest
Send a DELETE request
function sendDeleteRequest(string $url, array $headers = []): array {
$this->initCurl($url, 'DELETE', $headers);
return $this->executeRequest();
}
âī¸ Parameters
- $url (string)
- $headers (array)
âŠī¸ Returns
(array)
đ§ buildUrl
Build CalDAV URL
function buildUrl(string $username, string $calendarId, ?string $eventId = null): string {
$url = rtrim($this->baseUrl, '/') . '/calendars/' . urlencode($username) . '/' . urlencode($calendarId);
if ($eventId) {
$url .= '/' . urlencode($eventId) . '.ics';
}
return $url;
}
âī¸ Parameters
- $username (string)
- $calendarId (string)
- $eventId (string|null)
âŠī¸ Returns
(string)
đ§ setVerbose
Set verbose mode for debugging
function setVerbose(bool $verbose): void {
$this->verbose = $verbose;
}
âī¸ Parameters
âŠī¸ Returns
(void)
Set default headers for all requests
function setDefaultHeaders(array $headers): void {
$this->defaultHeaders = $headers;
}
âī¸ Parameters
âŠī¸ Returns
(void)