-
Notifications
You must be signed in to change notification settings - Fork 60
/
CalDAVException.php
93 lines (71 loc) · 2.61 KB
/
CalDAVException.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* CalDAVException
*
* Copyright 2014 Michael Palm <[email protected]>
*
* This class is an extension to the Exception-class, to store and report additional data in the case
* of a problem.
* For debugging purposes, just sorround all of your SimpleCalDAVClient-Code with try { ... } catch (Exception $e) { echo $e->__toString(); }
*
* @package simpleCalDAV
*
*/
class CalDAVException extends Exception {
private $requestHeader;
private $requestBody;
private $responseHeader;
private $responseBody;
public function __construct($message, $client, $code = 0, Exception $previous = null) {
parent::__construct($message, $code, $previous);
$this->requestHeader = $client->GetHttpRequest();
$this->requestBody = $client->GetBody();
$this->responseHeader = $client->GetResponseHeaders();
$this->responseBody = $client->GetResponseBody();
}
public function __toString() {
$string = '';
$dom = new DOMDocument();
$dom->preserveWhiteSpace = FALSE;
$dom->formatOutput = TRUE;
$string .= '<pre>';
$string .= 'Exception: '.$this->getMessage().'<br><br><br><br>';
$string .= 'If you think there is a bug in SimpleCalDAV, please report the following information on github or send it at [email protected].<br><br><br>';
$string .= '<br>For debugging purposes:<br>';
$string .= '<br>last request:<br><br>';
$string .= $this->requestHeader;
if(!empty($this->requestBody)) {
if(!preg_match( '#^Content-type:.*?text/calendar.*?$#', $this->requestHeader, $matches)) {
$dom->loadXML($this->requestBody);
$string .= htmlentities($dom->saveXml());
}
else $string .= htmlentities($this->requestBody).'<br><br>';
}
$string .= '<br>last response:<br><br>';
$string .= $this->responseHeader;
if(!empty($this->responseBody)) {
if(!preg_match( '#^Content-type:.*?text/calendar.*?$#', $this->responseHeader, $matches)) {
$dom->loadXML($this->responseBody);
$string .= htmlentities($dom->saveXml());
}
else $string .= htmlentities($this->responseBody);
}
$string .= '<br><br>';
$string .= 'Trace:<br><br>'.$this->getTraceAsString();
$string .= '</pre>';
return $string;
}
public function getRequestHeader() {
return $this->requestHeader;
}
public function getrequestBody() {
return $this->requestBody;
}
public function getResponseHeader() {
return $this->responseHeader;
}
public function getresponseBody() {
return $this->responseBody;
}
}
?>