@@ -111,6 +111,11 @@ class Cursor implements
111
111
* "flat" option entry (will treat the results as a simple array, not documents)
112
112
*/
113
113
const ENTRY_FLAT = '_flat ' ;
114
+
115
+ /**
116
+ * "objectType" option entry.
117
+ */
118
+ const ENTRY_TYPE = 'objectType ' ;
114
119
115
120
/**
116
121
* Initialise the cursor with the first results and some metadata
@@ -300,8 +305,8 @@ public function valid()
300
305
* @return void
301
306
*/
302
307
private function add (array $ data )
303
- {
304
- foreach ($ this ->sanitize ($ data ) as $ row ) {
308
+ {
309
+ foreach ($ this ->sanitize ($ data ) as $ row ) {
305
310
306
311
if ((isset ($ this ->_options [self ::ENTRY_FLAT ]) && $ this ->_options [self ::ENTRY_FLAT ]) || !is_array ($ row )) {
307
312
$ this ->addFlatFromArray ($ row );
@@ -317,8 +322,34 @@ private function add(array $data)
317
322
break ;
318
323
case 'vertex ' :
319
324
$ this ->addVerticesFromArray ($ row );
320
-
321
325
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 ;
322
353
default :
323
354
$ this ->addDocumentsFromArray ($ row );
324
355
@@ -354,8 +385,130 @@ private function addDocumentsFromArray(array $data)
354
385
{
355
386
$ this ->_result [] = Document::createFromArray ($ data , $ this ->_options );
356
387
}
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
+
359
512
/**
360
513
* Create an array of Edges from the input array
361
514
*
0 commit comments