Skip to content

Commit 292febe

Browse files
committed
2.2 intitial checkin
1 parent e7b713e commit 292febe

14 files changed

+4785
-390
lines changed

docs/classes/triagens.ArangoDb.EdgeDefinition.html

Lines changed: 989 additions & 0 deletions
Large diffs are not rendered by default.

lib/triagens/ArangoDb/Connection.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,8 @@ public function parseResponse(HttpResponse $response)
294294
// check if we can find details in the response body
295295
$details = json_decode($body, true);
296296
if (is_array($details)) {
297-
298-
// yes, we got details
299-
$exception = new ServerException($response->getResult(), $httpCode);
297+
// yes, we got details
298+
$exception = new ServerException($details["errorMessage"], $details["code"]);
300299
$exception->setDetails($details);
301300
throw $exception;
302301
}
@@ -631,13 +630,11 @@ public function json_encode_wrapper($data, $options = null)
631630
if ($this->_options[ConnectionOptions::OPTION_CHECK_UTF8_CONFORM] === true) {
632631
self::check_encoding($data);
633632
}
634-
635633
if (empty($data)) {
636-
$response = json_encode($data, $options | JSON_FORCE_OBJECT);
634+
$response = json_encode($data, $options | JSON_FORCE_OBJECT);
637635
} else {
638636
$response = json_encode($data, $options);
639637
}
640-
641638
return $response;
642639
}
643640

lib/triagens/ArangoDb/Cursor.php

Lines changed: 158 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ class Cursor implements
111111
* "flat" option entry (will treat the results as a simple array, not documents)
112112
*/
113113
const ENTRY_FLAT = '_flat';
114+
115+
/**
116+
* "objectType" option entry.
117+
*/
118+
const ENTRY_TYPE = 'objectType';
114119

115120
/**
116121
* Initialise the cursor with the first results and some metadata
@@ -300,8 +305,8 @@ public function valid()
300305
* @return void
301306
*/
302307
private function add(array $data)
303-
{
304-
foreach ($this->sanitize($data) as $row) {
308+
{
309+
foreach ($this->sanitize($data) as $row) {
305310

306311
if ((isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT]) || !is_array($row)) {
307312
$this->addFlatFromArray($row);
@@ -317,8 +322,34 @@ private function add(array $data)
317322
break;
318323
case 'vertex' :
319324
$this->addVerticesFromArray($row);
320-
321325
break;
326+
case 'path' :
327+
$this->addPathsFromArray($row);
328+
329+
break;
330+
case 'shortestPath' :
331+
$this->addShortestPathFromArray($row);
332+
333+
break;
334+
335+
case 'distanceTo' :
336+
$this->addDistanceToFromArray($row);
337+
338+
break;
339+
340+
case 'commonNeighbors' :
341+
$this->addCommonNeighborsFromArray($row);
342+
343+
break;
344+
345+
case 'commonProperties' :
346+
$this->addCommonPropertiesFromArray($row);
347+
348+
break;
349+
case 'figure' :
350+
$this->addFigureFromArray($row);
351+
352+
break;
322353
default :
323354
$this->addDocumentsFromArray($row);
324355

@@ -354,8 +385,130 @@ private function addDocumentsFromArray(array $data)
354385
{
355386
$this->_result[] = Document::createFromArray($data, $this->_options);
356387
}
357-
358-
388+
389+
/**
390+
* Create an array of paths from the input array
391+
*
392+
* @param array $data - array of incoming "paths" arrays
393+
*
394+
* @return void
395+
*/
396+
private function addPathsFromArray(array $data)
397+
{
398+
$entry = array(
399+
"vertices" => array(),
400+
"edges" => array(),
401+
"source" => Document::createFromArray($data["source"], $this->_options),
402+
"destination" => Document::createFromArray($data["destination"], $this->_options),
403+
);
404+
foreach ($data["vertices"] as $v) {
405+
$entry["vertices"][] = Document::createFromArray($v, $this->_options);
406+
}
407+
foreach ($data["edges"] as $v) {
408+
$entry["edges"][] = Edge::createFromArray($v, $this->_options);
409+
}
410+
$this->_result[] = $entry;
411+
}
412+
413+
/**
414+
* Create an array of shortest paths from the input array
415+
*
416+
* @param array $data - array of incoming "paths" arrays
417+
*
418+
* @return void
419+
*/
420+
private function addShortestPathFromArray(array $data)
421+
{
422+
$entry = array(
423+
"paths" => array (),
424+
"source" => $data["startVertex"],
425+
"distance" => $data["distance"],
426+
"destination" => Document::createFromArray($data["vertex"], $this->_options),
427+
);
428+
foreach ($data["paths"] as $p) {
429+
$path = array (
430+
"vertices" => array(),
431+
"edges" => array()
432+
);
433+
foreach ($p["vertices"] as $v) {
434+
$path["vertices"][] = $v;
435+
}
436+
foreach ($p["edges"] as $v) {
437+
$path["edges"][] = Edge::createFromArray($v, $this->_options);
438+
}
439+
$entry["paths"][] = $path;
440+
}
441+
$this->_result[] = $entry;
442+
}
443+
444+
445+
/**
446+
* Create an array of distances from the input array
447+
*
448+
* @param array $data - array of incoming "paths" arrays
449+
*
450+
* @return void
451+
*/
452+
private function addDistanceToFromArray(array $data)
453+
{
454+
$entry = array(
455+
"source" => $data["startVertex"],
456+
"distance" => $data["distance"],
457+
"destination" => Document::createFromArray($data["vertex"], $this->_options),
458+
);
459+
$this->_result[] = $entry;
460+
}
461+
462+
/**
463+
* Create an array of common neighbors from the input array
464+
*
465+
* @param array $data - array of incoming "paths" arrays
466+
*
467+
* @return void
468+
*/
469+
private function addCommonNeighborsFromArray(array $data)
470+
{
471+
$k = array_keys($data)[0];
472+
$this->_result[$k] = array();
473+
474+
foreach ($data[$k] as $neighbor => $neighbors) {
475+
$this->_result[$k][$neighbor] = array();
476+
foreach ($neighbors as $n) {
477+
$this->_result[$k][$neighbor][] = Document::createFromArray($n);
478+
}
479+
}
480+
}
481+
482+
/**
483+
* Create an array of common properties from the input array
484+
*
485+
* @param array $data - array of incoming "paths" arrays
486+
*
487+
* @return void
488+
*/
489+
private function addCommonPropertiesFromArray(array $data)
490+
{
491+
$k = array_keys($data)[0];
492+
$this->_result[$k] = array();
493+
foreach ($data[$k] as $c) {
494+
$id = $c["_id"];
495+
unset($c["_id"]);
496+
$this->_result[$k][$id] = $c;
497+
}
498+
}
499+
500+
/**
501+
* Create an array of figuresfrom the input array
502+
*
503+
* @param array $data - array of incoming "paths" arrays
504+
*
505+
* @return void
506+
*/
507+
private function addFigureFromArray(array $data)
508+
{
509+
$this->_result = $data;
510+
}
511+
359512
/**
360513
* Create an array of Edges from the input array
361514
*

0 commit comments

Comments
 (0)