@@ -29,7 +29,7 @@ public static function login(string $address, string $username, string $password
2929 'base_uri ' => rtrim ($ address , '/ ' ),
3030 'timeout ' => 10.0 ,
3131 'headers ' => [
32- 'Authorization ' => '' ,
32+ 'Authorization ' => 'Basic ' . base64_encode ( " $ username : $ password " ) ,
3333 'Content-Type ' => 'application/vnd.neo4j.query ' ,
3434 'Accept ' =>'application/vnd.neo4j.query ' ,
3535 ],
@@ -45,17 +45,18 @@ public static function login(string $address, string $username, string $password
4545 public function run (string $ cypher , array $ parameters , string $ database = 'neo4j ' ): ResultSet
4646 {
4747 try {
48-
48+ // Prepare the payload for the request
4949 $ payload = [
5050 'statement ' => $ cypher ,
5151 'parameters ' => empty ($ parameters ) ? new stdClass () : $ parameters ,
5252 ];
5353
54+ // Execute the request to the Neo4j server
5455 $ response = $ this ->client ->post ('/db/ ' . $ database . '/query/v2 ' , [
5556 'json ' => $ payload ,
5657 ]);
5758
58-
59+ // Decode the response body
5960 $ data = json_decode ($ response ->getBody ()->getContents (), true );
6061 $ ogm = new OGM ();
6162
@@ -70,7 +71,7 @@ public function run(string $cypher, array $parameters, string $database = 'neo4j
7071 return new ResultRow ($ data );
7172 }, $ values );
7273
73- return new ResultSet ($ ogm , $ rows );
74+ return new ResultSet ($ rows );
7475 } catch (RequestExceptionInterface $ e ) {
7576 $ response = $ e ->getResponse ();
7677 if ($ response !== null ) {
@@ -84,4 +85,16 @@ public function run(string $cypher, array $parameters, string $database = 'neo4j
8485 }
8586 }
8687
88+ public function beginTransaction (string $ database = 'neo4j ' ): Transaction
89+ {
90+ $ response = $ this ->client ->post ("/db/neo4j/query/v2/tx " );
91+
92+ $ clusterAffinity = $ response ->getHeaderLine ('neo4j-cluster-affinity ' );
93+ $ responseData = json_decode ($ response ->getBody (), true );
94+ $ transactionId = $ responseData ['transaction ' ]['id ' ];
95+
96+
97+
98+ return new Transaction ($ this ->client , $ clusterAffinity , $ transactionId );
99+ }
87100}
0 commit comments