@@ -76,12 +76,12 @@ class GraphHandler extends
76
76
const OPTION_NAME = 'name ' ;
77
77
78
78
/**
79
- * edge defintion parameter
79
+ * edge definition parameter
80
80
*/
81
81
const OPTION_EDGE_DEFINITION = 'edgeDefinition ' ;
82
82
83
83
/**
84
- * edge defintions parameter
84
+ * edge definitions parameter
85
85
*/
86
86
const OPTION_EDGE_DEFINITIONS = 'edgeDefinitions ' ;
87
87
@@ -90,6 +90,11 @@ class GraphHandler extends
90
90
*/
91
91
protected $ cache ;
92
92
93
+ /**
94
+ * @var $_useCache boolean GraphHandler use cache store
95
+ */
96
+ protected $ _useCache = false ;
97
+
93
98
/**
94
99
* Create a graph
95
100
*
@@ -372,41 +377,48 @@ public function getVertexCollections($graph, array $options = [])
372
377
}
373
378
374
379
$ excludeOrphans = false ;
375
- $ _useCache = false ;
380
+ $ _useCache = $ this -> _useCache ;
376
381
377
382
if ((bool ) $ options ){
378
383
if (isset ($ options ['excludeOrphans ' ]) && !is_bool ($ options ['excludeOrphans ' ])){
379
384
$ excludeOrphans = UrlHelper::getBoolString ($ options ['excludeOrphans ' ]);
380
385
}
381
-
382
- if (isset ($ options ['_useCache ' ])){
383
- $ _useCache = $ options ['_useCache ' ];
384
- }
385
386
}
386
387
387
- if ($ _useCache === true ){
388
+ if ($ _useCache === true ){
388
389
if ($ excludeOrphans ===true && !empty ($ this ->cache [$ graph ]['excludeOrphans ' ]['result ' ])){
389
390
return $ this ->cache [$ graph ]['excludeOrphans ' ]['vertexCollections ' ];
390
391
}else if (!empty ($ this ->cache [$ graph ]['vertexCollections ' ])) {
391
392
return $ this ->cache [$ graph ]['vertexCollections ' ];
392
393
}
393
394
}
394
-
395
395
$ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_VERTEX ]);
396
396
397
397
if ($ excludeOrphans ===true ){
398
398
$ url = UrlHelper::appendParamsUrl ($ url , ['excludeOrphans ' => $ excludeOrphans ]);
399
399
}
400
400
401
- try {
401
+ $ connection = $ this ->getConnection ();
402
+ $ batchCaptureMode = $ connection ->isInBatchCaptureMode ();
403
+
404
+ if ($ batchCaptureMode === true ){
405
+ $ this ->getConnection ()->setBatchRequest (false );
406
+ }
407
+
408
+ try {
402
409
$ response = $ this ->getConnection ()->get ($ url );
403
410
} catch (Exception $ e ) {
404
411
throw new ClientException ($ e ->getMessage ());
405
412
}
406
413
414
+ if ($ batchCaptureMode === true ){
415
+ $ this ->getConnection ()->setBatchRequest (true );
416
+ }
417
+
407
418
$ data = $ response ->getJson ();
408
- sort ($ data [self ::OPTION_COLLECTIONS ]);
409
- $ data = $ data [self ::OPTION_COLLECTIONS ];
419
+ $ data = $ data [self ::OPTION_COLLECTIONS ];
420
+
421
+ sort ($ data );
410
422
411
423
if ($ _useCache === true ){
412
424
if ($ excludeOrphans ===true && !empty ($ this ->cache [$ graph ]['excludeOrphans ' ]['vertexCollections ' ])){
@@ -517,37 +529,47 @@ public function deleteEdgeDefinition($graph, $edgeDefinition, $dropCollection =
517
529
* @return []
518
530
* @since 2.2
519
531
*/
520
- public function getEdgeCollections ($ graph, array $ options = [] )
532
+ public function getEdgeCollections ($ graph )
521
533
{
522
534
if ($ graph instanceof Graph) {
523
535
$ graph = $ graph ->getKey ();
524
536
}
525
537
526
- $ _useCache = false ;
527
-
528
- if ((bool ) $ options && isset ($ options ['_useCache ' ])){
529
- $ _useCache = $ options ['_useCache ' ];
530
- }
538
+ $ _useCache = $ this ->_useCache ;
531
539
532
540
if ($ _useCache === true && !empty ($ this ->cache [$ graph ]['edgeCollections ' ])){
533
541
return $ this ->cache [$ graph ]['edgeCollections ' ];
534
542
}
535
543
536
544
$ url = UrlHelper::buildUrl (Urls::URL_GRAPH , [$ graph , Urls::URLPART_EDGE ]);
537
545
538
- try {
539
- $ response = $ this ->getConnection ()->get ($ url );
540
- } catch (Exception $ e ) {
541
- throw new ClientException ($ e ->getMessage ());
542
- }
543
- $ data = $ response ->getJson ();
544
- sort ($ data [self ::OPTION_COLLECTIONS ]);
546
+ $ connection = $ this ->getConnection ();
547
+ $ batchCaptureMode = $ connection ->isInBatchCaptureMode ();
548
+
549
+ if ($ batchCaptureMode === true ){
550
+ $ this ->getConnection ()->setBatchRequest (false );
551
+ }
552
+
553
+ try {
554
+ $ response = $ this ->getConnection ()->get ($ url );
555
+ } catch (Exception $ e ) {
556
+ throw new ClientException ($ e ->getMessage ());
557
+ }
558
+
559
+ if ($ batchCaptureMode === true ){
560
+ $ this ->getConnection ()->setBatchRequest (true );
561
+ }
562
+
563
+ $ data = $ response ->getJson ();
564
+ $ data = $ data [self ::OPTION_COLLECTIONS ];
565
+
566
+ sort ($ data );
545
567
546
568
if ($ _useCache === true && !empty ($ this ->cache [$ graph ]['edgeCollections ' ])){
547
569
$ this ->cache [$ graph ]['edgeCollections ' ] = $ data ;
548
570
}
549
571
550
- return $ data[ self :: OPTION_COLLECTIONS ] ;
572
+ return $ data ;
551
573
}
552
574
553
575
@@ -1020,7 +1042,7 @@ public function saveEdge($graph, $from, $to, $label = null, $document, $collecti
1020
1042
if ($ collection === null ) {
1021
1043
$ edgeCollections = $ this ->getEdgeCollections ($ graph );
1022
1044
$ edgeCollectionsCount = count ($ edgeCollections );
1023
- if ($ edgeCollections !== 1 ) {
1045
+ if ($ edgeCollectionsCount !== 1 ) {
1024
1046
throw new ClientException ('A collection must be provided. ' );
1025
1047
}
1026
1048
else if ($ edgeCollectionsCount === 1 ) {
@@ -1091,7 +1113,7 @@ public function getEdge($graph, $edgeId, array $options = [], $collection = null
1091
1113
if ($ collection === null ) {
1092
1114
$ edgeCollections = $ this ->getEdgeCollections ($ graph );
1093
1115
$ edgeCollectionsCount = count ($ edgeCollections );
1094
- if ($ edgeCollections !== 1 ) {
1116
+ if ($ edgeCollectionsCount !== 1 ) {
1095
1117
throw new ClientException ('A collection must be provided. ' );
1096
1118
}
1097
1119
else if ($ edgeCollectionsCount === 1 ) {
@@ -1182,7 +1204,7 @@ public function replaceEdge($graph, $edgeId, $label, Edge $document, array $opti
1182
1204
if ($ collection === null ) {
1183
1205
$ edgeCollections = $ this ->getEdgeCollections ($ graph );
1184
1206
$ edgeCollectionsCount = count ($ edgeCollections );
1185
- if ($ edgeCollections !== 1 ) {
1207
+ if ($ edgeCollectionsCount !== 1 ) {
1186
1208
throw new ClientException ('A collection must be provided. ' );
1187
1209
}
1188
1210
else if ($ edgeCollectionsCount === 1 ) {
@@ -1287,7 +1309,7 @@ public function updateEdge($graph, $edgeId, $label, Edge $document, array $optio
1287
1309
if ($ collection === null ) {
1288
1310
$ edgeCollections = $ this ->getEdgeCollections ($ graph );
1289
1311
$ edgeCollectionsCount = count ($ edgeCollections );
1290
- if ($ edgeCollections !== 1 ) {
1312
+ if ($ edgeCollectionsCount !== 1 ) {
1291
1313
throw new ClientException ('A collection must be provided. ' );
1292
1314
}
1293
1315
else if ($ edgeCollectionsCount === 1 ) {
@@ -1373,7 +1395,7 @@ public function removeEdge($graph, $edgeId, $revision = null, array $options = [
1373
1395
if ($ collection === null ) {
1374
1396
$ edgeCollections = $ this ->getEdgeCollections ($ graph );
1375
1397
$ edgeCollectionsCount = count ($ edgeCollections );
1376
- if ($ edgeCollections !== 1 ) {
1398
+ if ($ edgeCollectionsCount !== 1 ) {
1377
1399
throw new ClientException ('A collection must be provided. ' );
1378
1400
}
1379
1401
else if ($ edgeCollectionsCount === 1 ) {
@@ -1406,4 +1428,34 @@ public function removeEdge($graph, $edgeId, $revision = null, array $options = [
1406
1428
1407
1429
return true ;
1408
1430
}
1431
+
1432
+ /**
1433
+ * Clears this handler's cache
1434
+ *
1435
+ * @return $this
1436
+ */
1437
+ public function clearCache ()
1438
+ {
1439
+ $ this ->cache = null ;
1440
+ return $ this ;
1441
+ }
1442
+
1443
+ /**
1444
+ * @return boolean
1445
+ */
1446
+ public function isCacheActive ()
1447
+ {
1448
+ return $ this ->_useCache ;
1449
+ }
1450
+
1451
+ /**
1452
+ * @param boolean $useCache
1453
+ *
1454
+ * @return $this
1455
+ */
1456
+ public function useCache ($ useCache )
1457
+ {
1458
+ $ this ->_useCache = $ useCache ;
1459
+ return $ this ;
1460
+ }
1409
1461
}
0 commit comments