6
6
use GuzzleHttp \Client ;
7
7
use GuzzleHttp \Exception \GuzzleException ;
8
8
use GuzzleHttp \Exception \RequestException ;
9
+ use Neo4j \QueryAPI \Objects \QueryArguments ;
9
10
use Neo4j \QueryAPI \Objects \ResultCounters ;
11
+ use Neo4j \QueryAPI \Objects \ProfiledQueryPlan ;
10
12
use Neo4j \QueryAPI \Results \ResultRow ;
11
13
use Neo4j \QueryAPI \Results \ResultSet ;
12
14
use Neo4j \QueryAPI \Exception \Neo4jException ;
@@ -25,14 +27,13 @@ public function __construct(Client $client)
25
27
26
28
public static function login (string $ address , string $ username , string $ password ): self
27
29
{
28
-
29
30
$ client = new Client ([
30
31
'base_uri ' => rtrim ($ address , '/ ' ),
31
32
'timeout ' => 10.0 ,
32
33
'headers ' => [
33
34
'Authorization ' => 'Basic ' . base64_encode ("$ username: $ password " ),
34
35
'Content-Type ' => 'application/vnd.neo4j.query ' ,
35
- 'Accept ' => 'application/vnd.neo4j.query ' ,
36
+ 'Accept ' => 'application/vnd.neo4j.query ' ,
36
37
],
37
38
]);
38
39
@@ -62,6 +63,7 @@ public function run(string $cypher, array $parameters = [], string $database = '
62
63
$ data = json_decode ($ response ->getBody ()->getContents (), true );
63
64
$ ogm = new OGM ();
64
65
66
+ // Extract result rows
65
67
$ keys = $ data ['data ' ]['fields ' ];
66
68
$ values = $ data ['data ' ]['values ' ];
67
69
$ rows = array_map (function ($ resultRow ) use ($ ogm , $ keys ) {
@@ -73,22 +75,64 @@ public function run(string $cypher, array $parameters = [], string $database = '
73
75
return new ResultRow ($ data );
74
76
}, $ values );
75
77
76
- return new ResultSet ($ rows , new ResultCounters (
77
- containsUpdates: $ data ['counters ' ]['containsUpdates ' ],
78
- nodesCreated: $ data ['counters ' ]['nodesCreated ' ],
79
- nodesDeleted: $ data ['counters ' ]['nodesDeleted ' ],
80
- propertiesSet: $ data ['counters ' ]['propertiesSet ' ],
81
- relationshipsCreated: $ data ['counters ' ]['relationshipsCreated ' ],
82
- relationshipsDeleted: $ data ['counters ' ]['relationshipsDeleted ' ],
83
- labelsAdded: $ data ['counters ' ]['labelsAdded ' ],
84
- labelsRemoved: $ data ['counters ' ]['labelsRemoved ' ],
85
- indexesAdded: $ data ['counters ' ]['indexesAdded ' ],
86
- indexesRemoved: $ data ['counters ' ]['indexesRemoved ' ],
87
- constraintsAdded: $ data ['counters ' ]['constraintsAdded ' ],
88
- constraintsRemoved: $ data ['counters ' ]['constraintsRemoved ' ],
89
- containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ],
90
- systemUpdates: $ data ['counters ' ]['systemUpdates ' ]
91
- ));
78
+ // Extract profile data, if available
79
+ $ profiledQueryPlan = null ;
80
+ if (isset ($ data ['profiledQueryPlan ' ])) {
81
+ $ profiledQueryPlan = new ProfiledQueryPlan (
82
+ $ data ['profile ' ]['dbHits ' ],
83
+ $ data ['profile ' ]['records ' ],
84
+ $ data ['profile ' ]['hasPageCacheStats ' ],
85
+ $ data ['profile ' ]['pageCacheHits ' ],
86
+ $ data ['profile ' ]['pageCacheMisses ' ],
87
+ $ data ['profile ' ]['pageCacheHitRatio ' ],
88
+ $ data ['profile ' ]['time ' ],
89
+ $ data ['profile ' ]['operatorType ' ],
90
+ $ data ['profile ' ]['arguments ' ]
91
+ );
92
+ }
93
+ $ queryArguments = null ;
94
+ if (isset ($ data ['profiledQueryPlan ' ]['arguments ' ])) {
95
+ $ queryArguments = new QueryArguments (
96
+ $ data ['profile ' ]['globalMemory ' ] ?? 0 ,
97
+ $ data ['profile ' ]['plannerImpl ' ] ?? '' ,
98
+ $ data ['profile ' ]['memory ' ] ?? 0 ,
99
+ $ data ['profile ' ]['stringRepresentation ' ] ?? '' ,
100
+ $ data ['profile ' ]['runtime ' ] ?? '' ,
101
+ $ data ['profile ' ]['runtimeImpl ' ] ?? '' ,
102
+ $ data ['profile ' ]['dbHits ' ] ?? 0 ,
103
+ $ data ['profile ' ]['batchSize ' ] ?? 0 ,
104
+ $ data ['profile ' ]['details ' ] ?? '' ,
105
+ $ data ['profile ' ]['plannerVersion ' ] ?? '' ,
106
+ $ data ['profile ' ]['pipelineInfo ' ] ?? '' ,
107
+ $ data ['profile ' ]['runtimeVersion ' ] ?? '' ,
108
+ $ data ['profile ' ]['id ' ] ?? 0 ,
109
+ $ data ['profile ' ]['estimatedRows ' ] ?? 0.0 ,
110
+ $ data ['profile ' ]['planner ' ] ?? '' ,
111
+ $ data ['profile ' ]['rows ' ] ?? 0
112
+ );
113
+ }
114
+
115
+ // Return a ResultSet containing rows, counters, and the profiled query plan
116
+ return new ResultSet (
117
+ $ rows ,
118
+ new ResultCounters (
119
+ containsUpdates: $ data ['counters ' ]['containsUpdates ' ],
120
+ nodesCreated: $ data ['counters ' ]['nodesCreated ' ],
121
+ nodesDeleted: $ data ['counters ' ]['nodesDeleted ' ],
122
+ propertiesSet: $ data ['counters ' ]['propertiesSet ' ],
123
+ relationshipsCreated: $ data ['counters ' ]['relationshipsCreated ' ],
124
+ relationshipsDeleted: $ data ['counters ' ]['relationshipsDeleted ' ],
125
+ labelsAdded: $ data ['counters ' ]['labelsAdded ' ],
126
+ labelsRemoved: $ data ['counters ' ]['labelsRemoved ' ],
127
+ indexesAdded: $ data ['counters ' ]['indexesAdded ' ],
128
+ indexesRemoved: $ data ['counters ' ]['indexesRemoved ' ],
129
+ constraintsAdded: $ data ['counters ' ]['constraintsAdded ' ],
130
+ constraintsRemoved: $ data ['counters ' ]['constraintsRemoved ' ],
131
+ containsSystemUpdates: $ data ['counters ' ]['containsSystemUpdates ' ],
132
+ systemUpdates: $ data ['counters ' ]['systemUpdates ' ]
133
+ ),
134
+ $ profiledQueryPlan // Pass the profiled query plan here
135
+ );
92
136
} catch (RequestExceptionInterface $ e ) {
93
137
$ response = $ e ->getResponse ();
94
138
if ($ response !== null ) {
@@ -110,8 +154,6 @@ public function beginTransaction(string $database = 'neo4j'): Transaction
110
154
$ responseData = json_decode ($ response ->getBody (), true );
111
155
$ transactionId = $ responseData ['transaction ' ]['id ' ];
112
156
113
-
114
-
115
157
return new Transaction ($ this ->client , $ clusterAffinity , $ transactionId );
116
158
}
117
159
}
0 commit comments