@@ -35,14 +35,27 @@ class DocumentHandler extends Handler {
35
35
36
36
/**
37
37
* Get a single document from a collection
38
- * This will throw if the document cannot be fetched from the server
38
+ * Alias method for getById()
39
39
*
40
40
* @throws Exception
41
41
* @param mixed $collectionId - collection id as a string or number
42
42
* @param mixed $documentId - document identifier
43
43
* @return Document - the document fetched from the server
44
44
*/
45
45
public function get ($ collectionId , $ documentId ) {
46
+ return $ this ->getById ($ collectionId , $ documentId );
47
+ }
48
+
49
+ /**
50
+ * Get a single document from a collection
51
+ * This will throw if the document cannot be fetched from the server
52
+ *
53
+ * @throws Exception
54
+ * @param mixed $collectionId - collection id as a string or number
55
+ * @param mixed $documentId - document identifier
56
+ * @return Document - the document fetched from the server
57
+ */
58
+ public function getById ($ collectionId , $ documentId ) {
46
59
$ url = UrlHelper::buildUrl (Urls::URL_DOCUMENT , $ collectionId , $ documentId );
47
60
$ response = $ this ->getConnection ()->get ($ url );
48
61
@@ -151,20 +164,35 @@ public function add($collectionId, Document $document, $create = NULL) {
151
164
}
152
165
153
166
/**
154
- * Update an existing document in a collection
167
+ * Update an existing document in a collection, identified by the document itself
155
168
* This will update the document on the server
156
169
* This will throw if the document cannot be updated
157
170
*
158
171
* @throws Exception
159
- * @param mixed $collectionId - collection id as string or number
160
172
* @param Document $document - document to be updated
161
173
* @param bool $policy - update policy to be used in case of conflict
162
174
* @return bool - always true, will throw if there is an error
163
175
*/
164
- public function update ($ collectionId , Document $ document , $ policy = NULL ) {
176
+ public function update (Document $ document , $ policy = NULL ) {
165
177
$ collectionId = $ this ->getCollectionId ($ document );
166
178
$ documentId = $ this ->getDocumentId ($ document );
167
179
180
+ return $ this ->updateById ($ collectionId , $ documentId , $ document , $ policy );
181
+ }
182
+
183
+ /**
184
+ * Update an existing document in a collection, identified by collection id and document id
185
+ * This will update the document on the server
186
+ * This will throw if the document cannot be updated
187
+ *
188
+ * @throws Exception
189
+ * @param mixed $collectionId - collection id as string or number
190
+ * @param mixed $documentId - document id as string or number
191
+ * @param Document $document - document to be updated
192
+ * @param bool $policy - update policy to be used in case of conflict
193
+ * @return bool - always true, will throw if there is an error
194
+ */
195
+ public function updateById ($ collectionId , $ documentId , Document $ document , $ policy = NULL ) {
168
196
if ($ policy === NULL ) {
169
197
$ policy = $ this ->getConnection ()->getOption (ConnectionOptions::OPTION_UPDATE_POLICY );
170
198
}
@@ -180,16 +208,28 @@ public function update($collectionId, Document $document, $policy = NULL) {
180
208
}
181
209
182
210
/**
183
- * Delete a document from a collection
211
+ * Delete a document from a collection, identified by the document itself
184
212
*
185
213
* @throws Exception
186
- * @param mixed $collectionId - collection id as string or number
187
- * @param mixed $document - document id OR document to be updated
214
+ * @param Document $document - document to be updated
188
215
* @return bool - always true, will throw if there is an error
189
216
*/
190
- public function delete ($ collectionId , $ document ) {
191
- $ documentId = $ this ->getDocumentId ($ document );
217
+ public function delete (Document $ document ) {
218
+ $ collectionId = $ this ->getCollectionId ($ document );
219
+ $ documentId = $ this ->getDocumentId ($ document );
192
220
221
+ return $ this ->deleteById ($ collectionId , $ documentId );
222
+ }
223
+
224
+ /**
225
+ * Delete a document from a collection, identified by the collection id and document id
226
+ *
227
+ * @throws Exception
228
+ * @param mixed $collectionId - collection id as string or number
229
+ * @param mixed $documentId - document id as string or number
230
+ * @return bool - always true, will throw if there is an error
231
+ */
232
+ public function deleteById ($ collectionId , $ documentId ) {
193
233
$ result = $ this ->getConnection ()->delete (UrlHelper::buildUrl (Urls::URL_DOCUMENT , $ collectionId , $ documentId ));
194
234
195
235
return true ;
0 commit comments