@@ -29,7 +29,7 @@ public static function login(string $address, string $username, string $password
29
29
'base_uri ' => rtrim ($ address , '/ ' ),
30
30
'timeout ' => 10.0 ,
31
31
'headers ' => [
32
- 'Authorization ' => '' ,
32
+ 'Authorization ' => 'Basic ' . base64_encode ( " $ username : $ password " ) ,
33
33
'Content-Type ' => 'application/vnd.neo4j.query ' ,
34
34
'Accept ' =>'application/vnd.neo4j.query ' ,
35
35
],
@@ -45,17 +45,18 @@ public static function login(string $address, string $username, string $password
45
45
public function run (string $ cypher , array $ parameters , string $ database = 'neo4j ' ): ResultSet
46
46
{
47
47
try {
48
-
48
+ // Prepare the payload for the request
49
49
$ payload = [
50
50
'statement ' => $ cypher ,
51
51
'parameters ' => empty ($ parameters ) ? new stdClass () : $ parameters ,
52
52
];
53
53
54
+ // Execute the request to the Neo4j server
54
55
$ response = $ this ->client ->post ('/db/ ' . $ database . '/query/v2 ' , [
55
56
'json ' => $ payload ,
56
57
]);
57
58
58
-
59
+ // Decode the response body
59
60
$ data = json_decode ($ response ->getBody ()->getContents (), true );
60
61
$ ogm = new OGM ();
61
62
@@ -70,7 +71,7 @@ public function run(string $cypher, array $parameters, string $database = 'neo4j
70
71
return new ResultRow ($ data );
71
72
}, $ values );
72
73
73
- return new ResultSet ($ ogm , $ rows );
74
+ return new ResultSet ($ rows );
74
75
} catch (RequestExceptionInterface $ e ) {
75
76
$ response = $ e ->getResponse ();
76
77
if ($ response !== null ) {
@@ -84,4 +85,16 @@ public function run(string $cypher, array $parameters, string $database = 'neo4j
84
85
}
85
86
}
86
87
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
+ }
87
100
}
0 commit comments