1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file DocOpts.php |
5
|
|
|
* @brief This file contains the DocOpts class. |
6
|
|
|
* @details |
7
|
|
|
* @author Filippo F. Fadda |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace EoC\Opt; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @brief To retrieve additional information about document, you can create a DocOpts instance and pass it as parameter |
16
|
|
|
* to the Couch::getDoc() method. |
17
|
|
|
* @nosubgrouping |
18
|
|
|
*/ |
19
|
|
|
class DocOpts extends AbstractOpts { |
20
|
|
|
|
21
|
|
|
private $ignoreClass = FALSE; |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
public function reset() { |
25
|
|
|
$this->ignoreClass = FALSE; |
26
|
|
|
parent::reset(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @brief Includes information about the encoding of each document's attachments. |
32
|
|
|
*/ |
33
|
|
|
public function includeAttEncodingInfo() { |
34
|
|
|
$this->options['att_encoding_info'] = 'true'; |
35
|
|
|
return $this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @brief Includes a metadata structure that holds information about all the document's attachments. |
41
|
|
|
*/ |
42
|
|
|
public function includeAttachments() { |
43
|
|
|
$this->options['attachments'] = 'true'; |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @brief Include just the changed attachments from the specified revision(s). |
50
|
|
|
* @details If you already have a local copy of an earlier revision of a document and its attachments, you may want |
51
|
|
|
* to fetch only the attachments that have changed since a particular revision. You can specify one or more revision IDs. |
52
|
|
|
* In the last case you must use an array of string. The response will include the content of only those attachments |
53
|
|
|
* that changed since the given revision(s). |
54
|
|
|
* @param string|array $revs The revision(s) identifier(s). |
55
|
|
|
*/ |
56
|
|
|
public function includeAttsSince($revs) { |
57
|
|
|
$this->options['atts_since'] = json_encode($revs); |
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @brief Includes information about document's conflicts. |
64
|
|
|
*/ |
65
|
|
|
public function includeConflicts() { |
66
|
|
|
$this->options['conflicts'] = 'true'; |
67
|
|
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @brief Includes information about deleted document's conflicts. |
73
|
|
|
*/ |
74
|
|
|
public function includeDeletedConflicts() { |
75
|
|
|
$this->options['deleted_conflicts'] = 'true'; |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @brief Includes the sequence number of the revision in the database. |
82
|
|
|
*/ |
83
|
|
|
public function includeLocalSeq() { |
84
|
|
|
$this->options['local_seq'] = 'true'; |
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @brief Equals to calling includeRevsInfo(), includeConflicts() and includeDeletedConflicts(). |
91
|
|
|
*/ |
92
|
|
|
public function includeMeta() { |
93
|
|
|
$this->options['meta'] = 'true'; |
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @brief This can be used alternatively to includeRevsInfo() method. This option is used by the replicator to return |
100
|
|
|
* an array of revision IDs more efficiently. The numeric prefixes are removed, with a "start" value indicating the |
101
|
|
|
* prefix for the first (most recent) ID. |
102
|
|
|
* @details CouchDB will return something like this: |
103
|
|
|
@code |
104
|
|
|
{ |
105
|
|
|
"_revisions": { |
106
|
|
|
"start": 3, |
107
|
|
|
"ids": ["fffff", "eeeee", "ddddd"] |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
@endcode |
111
|
|
|
*/ |
112
|
|
|
public function includeRevs() { |
113
|
|
|
$this->options['revs'] = 'true'; |
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @brief Includes information about all the document's revisions. |
120
|
|
|
* @details CouchDB will return something like this: |
121
|
|
|
@code |
122
|
|
|
{ |
123
|
|
|
"_revs_info": [ |
124
|
|
|
{"rev": "3-ffffff", "status": "available"}, |
125
|
|
|
{"rev": "2-eeeeee", "status": "missing"}, |
126
|
|
|
{"rev": "1-dddddd", "status": "deleted"}, |
127
|
|
|
] |
128
|
|
|
} |
129
|
|
|
@endcode |
130
|
|
|
*/ |
131
|
|
|
public function includeRevsInfo() { |
132
|
|
|
$this->options['revs_info'] = 'true'; |
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @brief You can fetch the bodies of multiple revisions at once using this option. Using `$revs = 'all'` you can |
139
|
|
|
* fetch all leaf revisions; alternatively you can specify an array of revisions. The JSON returns an array of objects |
140
|
|
|
* with an "ok" key pointing to the document, or a "missing" key pointing to the rev string. |
141
|
|
|
* @details CouchDB will return something like this: |
142
|
|
|
* [{"missing":"1-fbd8a6da4d669ae4b909fcdb42bb2bfd"},{"ok":{"_id":"test","_rev":"2-5bc3c6319edf62d4c624277fdd0ae191","hello":"foo"}}] |
143
|
|
|
* @param string|array $revs The revision(s) identifier(s). |
144
|
|
|
*/ |
145
|
|
|
public function includeOpenRevs($revs = 'all') { |
146
|
|
|
if (is_array($revs)) |
147
|
|
|
$this->options['open_revs'] = json_encode($revs); |
148
|
|
|
else |
149
|
|
|
$this->options['open_revs'] = 'all'; |
150
|
|
|
|
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @brief The option is supposed to tell the source to send the leafs of an edit branch containing a requested |
157
|
|
|
* revision, i.e. if the document has been updated since the revlist was calculated, the source is free to send the |
158
|
|
|
* new one. |
159
|
|
|
*/ |
160
|
|
|
public function includeLatest() { |
161
|
|
|
$this->options['latest'] = 'true'; |
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @brief Ignores the class name to avoid the creation of an instance of that class. |
168
|
|
|
* @details When `true` ignores the class name, previously saved in the special attribute `class`, to avoid the |
169
|
|
|
* creation of an instance of that particular class. You want use this property when the interpreter can't load class |
170
|
|
|
* due to namespace resolution problem or because the class definition is missing. |
171
|
|
|
*/ |
172
|
|
|
public function ignoreClass() { |
173
|
|
|
$this->ignoreClass = TRUE; |
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @brief Returns `true` if ignoreClass() has been called before. |
180
|
|
|
*/ |
181
|
|
|
public function issetIgnoreClass() { |
182
|
|
|
return $this->ignoreClass; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
} |