66use GuzzleHttp \Client ;
77use GuzzleHttp \Exception \GuzzleException ;
88use GuzzleHttp \Exception \RequestException ;
9+ use Neo4j \QueryAPI \Objects \QueryArguments ;
910use Neo4j \QueryAPI \Objects \ResultCounters ;
11+ use Neo4j \QueryAPI \Objects \ProfiledQueryPlan ;
1012use Neo4j \QueryAPI \Results \ResultRow ;
1113use Neo4j \QueryAPI \Results \ResultSet ;
1214use Neo4j \QueryAPI \Exception \Neo4jException ;
@@ -25,14 +27,13 @@ public function __construct(Client $client)
2527
2628 public static function login (string $ address , string $ username , string $ password ): self
2729 {
28-
2930 $ client = new Client ([
3031 'base_uri ' => rtrim ($ address , '/ ' ),
3132 'timeout ' => 10.0 ,
3233 'headers ' => [
3334 'Authorization ' => 'Basic ' . base64_encode ("$ username: $ password " ),
3435 'Content-Type ' => 'application/vnd.neo4j.query ' ,
35- 'Accept ' => 'application/vnd.neo4j.query ' ,
36+ 'Accept ' => 'application/vnd.neo4j.query ' ,
3637 ],
3738 ]);
3839
@@ -62,6 +63,7 @@ public function run(string $cypher, array $parameters = [], string $database = '
6263 $ data = json_decode ($ response ->getBody ()->getContents (), true );
6364 $ ogm = new OGM ();
6465
66+ // Extract result rows
6567 $ keys = $ data ['data ' ]['fields ' ];
6668 $ values = $ data ['data ' ]['values ' ];
6769 $ rows = array_map (function ($ resultRow ) use ($ ogm , $ keys ) {
@@ -73,22 +75,64 @@ public function run(string $cypher, array $parameters = [], string $database = '
7375 return new ResultRow ($ data );
7476 }, $ values );
7577
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+ );
92136 } catch (RequestExceptionInterface $ e ) {
93137 $ response = $ e ->getResponse ();
94138 if ($ response !== null ) {
@@ -110,8 +154,6 @@ public function beginTransaction(string $database = 'neo4j'): Transaction
110154 $ responseData = json_decode ($ response ->getBody (), true );
111155 $ transactionId = $ responseData ['transaction ' ]['id ' ];
112156
113-
114-
115157 return new Transaction ($ this ->client , $ clusterAffinity , $ transactionId );
116158 }
117159}
0 commit comments