Skip to content

Commit be6c1a4

Browse files
committed
deleted JobHandler, created base methods that can be shared by edge and document handler. fixed documentation errors
1 parent e2957a6 commit be6c1a4

File tree

6 files changed

+72
-276
lines changed

6 files changed

+72
-276
lines changed

lib/triagens/ArangoDb/CollectionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ public function any($collectionId)
11201120
* @param int $count - the number of documents to return at most. Specifiying count is optional.
11211121
*
11221122
* @return array - array of documents in the collection
1123-
* @since 1.2
1123+
* @since 1.4
11241124
*/
11251125
public function first($collectionId, $count = null)
11261126
{
@@ -1165,7 +1165,7 @@ public function first($collectionId, $count = null)
11651165
* @param int $count - the number of documents to return at most. Specifiying count is optional.
11661166
*
11671167
* @return array - array of documents in the collection
1168-
* @since 1.2
1168+
* @since 1.4
11691169
*/
11701170
public function last($collectionId, $count = null)
11711171
{

lib/triagens/ArangoDb/DocumentHandler.php

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,16 @@ public function get($collectionId, $documentId, array $options = array())
9393
*/
9494
public function getById($collectionId, $documentId, array $options = array())
9595
{
96-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
96+
$data = $this->getDocument(Urls::URL_DOCUMENT, $collectionId, $documentId, $options);
97+
$options['_isNew'] = false;
98+
99+
return $this->createFromArrayWithContext($data, $options);
100+
}
101+
102+
103+
protected function getDocument($url, $collectionId, $documentId, array $options = array())
104+
{
105+
$url = UrlHelper::buildUrl($url, array($collectionId, $documentId));
97106
$headerElements = array();
98107
if (array_key_exists("ifMatch", $options) && array_key_exists("revision", $options)) {
99108
if ($options["ifMatch"] === true) {
@@ -109,11 +118,7 @@ public function getById($collectionId, $documentId, array $options = array())
109118
throw new ClientException('Document has not changed.');
110119
}
111120

112-
$data = $response->getJson();
113-
114-
$options['_isNew'] = false;
115-
116-
return $this->createFromArrayWithContext($data, $options);
121+
return $response->getJson();
117122
}
118123

119124

@@ -125,16 +130,21 @@ public function getById($collectionId, $documentId, array $options = array())
125130
*
126131
* @throws Exception
127132
*
128-
* @param mixed $collectionId - collection id as a string or number
129-
* @param mixed $documentId - document identifier
130-
* @param ifMatch' - boolean if given revision should match or not</li>
131-
* @param revision' - The document is returned if it matches/not matches revision.</li>
133+
* @param mixed $collectionId - collection id as a string or number.
134+
* @param mixed $documentId - document identifier.
135+
* @param ifMatch - boolean if given revision should match or not.
136+
* @param revision - The document is returned if it matches/not matches revision.
132137
*
133138
* @return array - an array containing the complete header including the key httpCode.
134139
*/
135140
public function getHead($collectionId, $documentId, $revision = null, $ifMatch = null)
136141
{
137-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
142+
return $this->head(Urls::URL_DOCUMENT, $collectionId, $documentId, $revision, $ifMatch);
143+
}
144+
145+
146+
protected function head($url, $collectionId, $documentId, $revision = null, $ifMatch = null) {
147+
$url = UrlHelper::buildUrl($url, array($collectionId, $documentId));
138148
$headerElements = array();
139149
if ($revision != null && $ifMatch !== null) {
140150
if ($ifMatch) {
@@ -427,29 +437,36 @@ public function update(Document $document, $options = array())
427437
* @return bool - always true, will throw if there is an error
428438
*/
429439
public function updateById($collectionId, $documentId, Document $document, $options = array())
440+
{
441+
return $this->patch(Urls::URL_DOCUMENT, $collectionId, $documentId, $document, $options);
442+
}
443+
444+
445+
446+
protected function patch($url, $collectionId, $documentId, Document $document, $options = array())
430447
{
431448
// This preserves compatibility for the old policy parameter.
432449
$params = array();
433450
$params = $this->validateAndIncludeOldSingleParameterInParams(
434-
$options,
435-
$params,
436-
ConnectionOptions::OPTION_UPDATE_POLICY
451+
$options,
452+
$params,
453+
ConnectionOptions::OPTION_UPDATE_POLICY
437454
);
438455
$params = $this->includeOptionsInParams(
439-
$options,
440-
$params,
441-
array(
442-
'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
443-
'keepNull' => true,
444-
)
456+
$options,
457+
$params,
458+
array(
459+
'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
460+
'keepNull' => true,
461+
)
445462
);
446463

447464
$revision = $document->getRevision();
448465
if (!is_null($revision)) {
449466
$params[ConnectionOptions::OPTION_REVISION] = $revision;
450467
}
451468

452-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
469+
$url = UrlHelper::buildUrl($url, array($collectionId, $documentId));
453470
$url = UrlHelper::appendParamsUrl($url, $params);
454471
$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($document->getAll()));
455472
$json = $result->getJson();
@@ -515,18 +532,23 @@ public function replace(Document $document, $options = array())
515532
* @return bool - always true, will throw if there is an error
516533
*/
517534
public function replaceById($collectionId, $documentId, Document $document, $options = array())
535+
{
536+
return $this->put(Urls::URL_DOCUMENT, $collectionId, $documentId, $document, $options);
537+
}
538+
539+
protected function put($url, $collectionId, $documentId, Document $document, $options = array())
518540
{
519541
// This preserves compatibility for the old policy parameter.
520542
$params = array();
521543
$params = $this->validateAndIncludeOldSingleParameterInParams(
522-
$options,
523-
$params,
524-
ConnectionOptions::OPTION_REPLACE_POLICY
544+
$options,
545+
$params,
546+
ConnectionOptions::OPTION_REPLACE_POLICY
525547
);
526548
$params = $this->includeOptionsInParams(
527-
$options,
528-
$params,
529-
array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC)
549+
$options,
550+
$params,
551+
array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC)
530552
);
531553

532554
$revision = $document->getRevision();
@@ -535,7 +557,7 @@ public function replaceById($collectionId, $documentId, Document $document, $opt
535557
}
536558

537559
$data = $document->getAll();
538-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
560+
$url = UrlHelper::buildUrl($url, array($collectionId, $documentId));
539561
$url = UrlHelper::appendParamsUrl($url, $params);
540562
$result = $this->getConnection()->put($url, $this->json_encode_wrapper($data));
541563
$json = $result->getJson();
@@ -544,7 +566,6 @@ public function replaceById($collectionId, $documentId, Document $document, $opt
544566
return true;
545567
}
546568

547-
548569
/**
549570
* Delete a document from a collection, identified by the document itself
550571
*
@@ -636,25 +657,31 @@ public function deleteById($collectionId, $documentId, $revision = null, $option
636657
* @return bool - always true, will throw if there is an error
637658
*/
638659
public function removeById($collectionId, $documentId, $revision = null, $options = array())
660+
{
661+
return $this->erase(Urls::URL_DOCUMENT, $collectionId, $documentId, $revision, $options);
662+
}
663+
664+
665+
protected function erase($url, $collectionId, $documentId, $revision = null, $options = array())
639666
{
640667
// This preserves compatibility for the old policy parameter.
641668
$params = array();
642669
$params = $this->validateAndIncludeOldSingleParameterInParams(
643-
$options,
644-
$params,
645-
ConnectionOptions::OPTION_DELETE_POLICY
670+
$options,
671+
$params,
672+
ConnectionOptions::OPTION_DELETE_POLICY
646673
);
647674
$params = $this->includeOptionsInParams(
648-
$options,
649-
$params,
650-
array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC)
675+
$options,
676+
$params,
677+
array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC)
651678
);
652679

653680
if (!is_null($revision)) {
654681
$params[ConnectionOptions::OPTION_REVISION] = $revision;
655682
}
656683

657-
$url = UrlHelper::buildUrl(Urls::URL_DOCUMENT, array($collectionId, $documentId));
684+
$url = UrlHelper::buildUrl($url, array($collectionId, $documentId));
658685
$url = UrlHelper::appendParamsUrl($url, $params);
659686
$this->getConnection()->delete($url);
660687

lib/triagens/ArangoDb/EdgeHandler.php

Lines changed: 6 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -269,25 +269,9 @@ public function outEdges($collectionId, $vertexHandle)
269269
*/
270270
public function getById($collectionId, $edgeId, array $options = array())
271271
{
272-
$url = UrlHelper::buildUrl(Urls::URL_EDGE, array($collectionId, $edgeId));
273-
$headerElements = array();
274-
if (array_key_exists("ifMatch", $options) && array_key_exists("revision", $options)) {
275-
if ($options["ifMatch"] === true) {
276-
$headerElements["If-Match"] = '"' . $options["revision"] .'"';
277-
} else {
278-
$headerElements["If-None-Match"] = '"' . $options["revision"]. '"';
279-
}
280-
}
281-
282-
$response = $this->getConnection()->get($url, $headerElements);
283-
284-
if ($response->getHttpCode() === 304) {
285-
throw new ClientException('Edge has not changed.');
286-
}
287-
288-
$data = $response->getJson();
289-
272+
$data = $this->getDocument(Urls::URL_EDGE, $collectionId, $edgeId, $options);
290273
$options['_isNew'] = false;
274+
291275
return $this->createFromArrayWithContext($data, $options);
292276
}
293277

@@ -309,20 +293,7 @@ public function getById($collectionId, $edgeId, array $options = array())
309293
*/
310294
public function getHead($collectionId, $edgeId, $revision = null, $ifMatch = null)
311295
{
312-
$url = UrlHelper::buildUrl(Urls::URL_EDGE, array($collectionId, $edgeId));
313-
$headerElements = array();
314-
if ($revision != null && $ifMatch !== null) {
315-
if ($ifMatch) {
316-
$headerElements["If-Match"] = '"' . $revision .'"';
317-
} else {
318-
$headerElements["If-None-Match"] = '"' . $revision . '"';
319-
}
320-
}
321-
322-
$response = $this->getConnection()->head($url, $headerElements);
323-
$headers = $response->getHeaders();
324-
$headers["httpCode"] = $response->getHttpCode();
325-
return $headers;
296+
return $this->head(Urls::URL_EDGE, $collectionId, $edgeId, $revision, $ifMatch);
326297
}
327298

328299
/**
@@ -343,28 +314,7 @@ public function getHead($collectionId, $edgeId, $revision = null, $ifMatch = nu
343314
*/
344315
public function removeById($collectionId, $edgeId, $revision = null, $options = array())
345316
{
346-
// This preserves compatibility for the old policy parameter.
347-
$params = array();
348-
$params = $this->validateAndIncludeOldSingleParameterInParams(
349-
$options,
350-
$params,
351-
ConnectionOptions::OPTION_DELETE_POLICY
352-
);
353-
$params = $this->includeOptionsInParams(
354-
$options,
355-
$params,
356-
array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC)
357-
);
358-
359-
if (!is_null($revision)) {
360-
$params[ConnectionOptions::OPTION_REVISION] = $revision;
361-
}
362-
363-
$url = UrlHelper::buildUrl(Urls::URL_EDGE, array($collectionId, $edgeId));
364-
$url = UrlHelper::appendParamsUrl($url, $params);
365-
$this->getConnection()->delete($url);
366-
367-
return true;
317+
return $this->erase(Urls::URL_EDGE, $collectionId, $edgeId, $revision, $options);
368318
}
369319

370320
/**
@@ -393,32 +343,7 @@ public function removeById($collectionId, $edgeId, $revision = null, $options =
393343
*/
394344
public function replaceById($collectionId, $edgeId, Edge $edge, $options = array())
395345
{
396-
// This preserves compatibility for the old policy parameter.
397-
$params = array();
398-
$params = $this->validateAndIncludeOldSingleParameterInParams(
399-
$options,
400-
$params,
401-
ConnectionOptions::OPTION_REPLACE_POLICY
402-
);
403-
$params = $this->includeOptionsInParams(
404-
$options,
405-
$params,
406-
array('waitForSync' => ConnectionOptions::OPTION_WAIT_SYNC)
407-
);
408-
409-
$revision = $edge->getRevision();
410-
if (!is_null($revision)) {
411-
$params[ConnectionOptions::OPTION_REVISION] = $revision;
412-
}
413-
414-
$data = $edge->getAll();
415-
$url = UrlHelper::buildUrl(Urls::URL_EDGE, array($collectionId, $edgeId));
416-
$url = UrlHelper::appendParamsUrl($url, $params);
417-
$result = $this->getConnection()->put($url, $this->json_encode_wrapper($data));
418-
$json = $result->getJson();
419-
$edge->setRevision($json[Edge::ENTRY_REV]);
420-
421-
return true;
346+
return $this->put(Urls::URL_EDGE, $collectionId, $edgeId, $edge, $options);
422347
}
423348

424349

@@ -450,34 +375,7 @@ public function replaceById($collectionId, $edgeId, Edge $edge, $options = array
450375
*/
451376
public function updateById($collectionId, $edgeId, Edge $edge, $options = array())
452377
{
453-
// This preserves compatibility for the old policy parameter.
454-
$params = array();
455-
$params = $this->validateAndIncludeOldSingleParameterInParams(
456-
$options,
457-
$params,
458-
ConnectionOptions::OPTION_UPDATE_POLICY
459-
);
460-
$params = $this->includeOptionsInParams(
461-
$options,
462-
$params,
463-
array(
464-
'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
465-
'keepNull' => true,
466-
)
467-
);
468-
469-
$revision = $edge->getRevision();
470-
if (!is_null($revision)) {
471-
$params[ConnectionOptions::OPTION_REVISION] = $revision;
472-
}
473-
474-
$url = UrlHelper::buildUrl(Urls::URL_EDGE, array($collectionId, $edgeId));
475-
$url = UrlHelper::appendParamsUrl($url, $params);
476-
$result = $this->getConnection()->patch($url, $this->json_encode_wrapper($edge->getAll()));
477-
$json = $result->getJson();
478-
$edge->setRevision($json[Edge::ENTRY_REV]);
479-
480-
return true;
378+
return $this->patch(Urls::URL_EDGE, $collectionId, $edgeId, $edge, $options);
481379
}
482380

483381
}

0 commit comments

Comments
 (0)