Skip to content

Commit ae7eb19

Browse files
Merge pull request #20 from stefanak-michal/extra_parameters
Extra parameters
2 parents 18d7645 + a6e1bf3 commit ae7eb19

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

Bolt.php

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -191,18 +191,22 @@ private function packProtocolVersions(): string
191191
* @param string $name
192192
* @param string $user
193193
* @param string $password
194+
* @param array $routing routing::Dictionary(address::String)
195+
<pre>null - the server should not carry out routing
196+
[] - the server should carry out routing
197+
['address' => 'ip:port'] - the server should carry out routing according to the given routing context</pre>
194198
* @return bool
195199
* @throws Exception
196200
*/
197-
public function init(string $name, string $user, string $password): bool
201+
public function init(string $name, string $user, string $password, array $routing = null): bool
198202
{
199203
if (!$this->handshake())
200204
return false;
201205

202206
if (self::$debug)
203207
echo 'INIT';
204208

205-
return $this->protocol->init($name, Bolt::$scheme, $user, $password);
209+
return $this->protocol->init($name, Bolt::$scheme, $user, $password, $routing);
206210
}
207211

208212
/**
@@ -212,19 +216,28 @@ public function init(string $name, string $user, string $password): bool
212216
* @param string $name
213217
* @param string $user
214218
* @param string $password
219+
* @param array $routing routing::Dictionary(address::String)
220+
<pre>null - the server should not carry out routing
221+
[] - the server should carry out routing
222+
['address' => 'ip:port'] - the server should carry out routing according to the given routing context</pre>
215223
* @return bool
216224
* @throws Exception
217225
*/
218-
public function hello(string $name, string $user, string $password): bool
226+
public function hello(string $name, string $user, string $password, array $routing = null): bool
219227
{
220-
return $this->init($name, $user, $password);
228+
return $this->init($name, $user, $password, $routing);
221229
}
222230

223231
/**
224232
* Send RUN message
225233
* @param string $statement
226234
* @param array $parameters
227-
* @param array $extra
235+
* @param array $extra extra::Dictionary(bookmarks::List<String>, tx_timeout::Integer, tx_metadata::Dictionary, mode::String, db:String)
236+
<pre>The bookmarks is a list of strings containg some kind of bookmark identification e.g [“neo4j-bookmark-transaction:1”, “neo4j-bookmark-transaction:2”]
237+
The tx_timeout is an integer in that specifies a transaction timeout in ms.
238+
The tx_metadata is a dictionary that can contain some metadata information, mainly used for logging.
239+
The mode specifies what kind of server the RUN message is targeting. For write access use "w" and for read access use "r". Defaults to write access if no mode is sent.
240+
The db specifies the database name for multi-database to select where the transaction takes place. If no db is sent or empty string it implies that it is the default database.</pre>
228241
* @return mixed Return false on error
229242
*/
230243
public function run(string $statement, array $parameters = [], array $extra = [])
@@ -237,52 +250,65 @@ public function run(string $statement, array $parameters = [], array $extra = []
237250
/**
238251
* Send PULL_ALL message
239252
* @version <4
253+
* @param int $n The n specifies how many records to fetch. n=-1 will fetch all records.
254+
* @param int $qid The qid (query identification) specifies the result of which statement the operation should be carried out. (Explicit Transaction only). qid=-1 can be used to denote the last executed statement and if no ``.
240255
* @return mixed Array of records or false on error. Last array element is success message.
241256
*/
242-
public function pullAll()
257+
public function pullAll(int $n = -1, int $qid = -1)
243258
{
244259
if (self::$debug)
245260
echo 'PULL';
246-
return $this->protocol->pullAll();
261+
return $this->protocol->pullAll(['n' => $n, 'qid' => $qid]);
247262
}
248263

249264
/**
250265
* Send PULL message
251266
* @version >=4
252267
* @internal PULL_ALL alias
268+
* @param int $n The n specifies how many records to fetch. n=-1 will fetch all records.
269+
* @param int $qid The qid (query identification) specifies the result of which statement the operation should be carried out. (Explicit Transaction only). qid=-1 can be used to denote the last executed statement and if no ``.
253270
* @return mixed Array of records or false on error. Last array element is success message.
254271
*/
255-
public function pull()
272+
public function pull(int $n = -1, int $qid = -1)
256273
{
257-
return $this->pullAll();
274+
return $this->pullAll($n, $qid);
258275
}
259276

260277
/**
261278
* Send DISCARD_ALL message
262279
* @version <4
280+
* @param int $n The n specifies how many records to throw away. n=-1 will throw away all records.
281+
* @param int $qid The qid (query identification) specifies the result of which statement the operation should be carried out. (Explicit Transaction only). qid=-1 can be used to denote the last executed statement and if no ``.
263282
* @return bool
264283
*/
265-
public function discardAll()
284+
public function discardAll(int $n = -1, int $qid = -1)
266285
{
267286
if (self::$debug)
268287
echo 'DISCARD';
269-
return $this->protocol->discardAll();
288+
return $this->protocol->discardAll(['n' => $n, 'qid' => $qid]);
270289
}
271290

272291
/**
273292
* Send DISCARD message
274293
* @version >=4
275294
* @internal DISCARD_ALL alias
295+
* @param int $n The n specifies how many records to throw away. n=-1 will throw away all records.
296+
* @param int $qid The qid (query identification) specifies the result of which statement the operation should be carried out. (Explicit Transaction only). qid=-1 can be used to denote the last executed statement and if no ``.
276297
* @return bool
277298
*/
278-
public function discard(): bool
299+
public function discard(int $n = -1, int $qid = -1): bool
279300
{
280-
return $this->discardAll();
301+
return $this->discardAll($n, $qid);
281302
}
282303

283304
/**
284305
* Send BEGIN message
285-
* @param array $extra
306+
* @param array $extra extra::Dictionary(bookmarks::List<String>, tx_timeout::Integer, tx_metadata::Dictionary, mode::String, db:String)
307+
<pre>The bookmarks is a list of strings containg some kind of bookmark identification e.g [“neo4j-bookmark-transaction:1”, “neo4j-bookmark-transaction:2”]
308+
The tx_timeout is an integer in that specifies a transaction timeout in ms.
309+
The tx_metadata is a dictionary that can contain some metadata information, mainly used for logging.
310+
The mode specifies what kind of server the RUN message is targeting. For write access use "w" and for read access use "r". Defaults to write access if no mode is sent.
311+
The db specifies the database name for multi-database to select where the transaction takes place. If no db is sent or empty string it implies that it is the default database.</pre>
286312
* @return bool
287313
*/
288314
public function begin(array $extra = []): bool

index.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@
5151
$neo4jVersion = $bolt->pull()[0][0] ?? '';
5252
$t = version_compare($neo4jVersion, '4') == -1;
5353

54+
//test discard
55+
$bolt->run('MATCH (a:Test) RETURN *');
56+
if (!$bolt->discard()) {
57+
throw new Exception('Discard failed');
58+
}
59+
5460
//test delete created node
5561
$bolt->run('MATCH (a:Test) WHERE ID(a) = ' . ($t ? '{a}' : '$a') . ' DELETE a', [
5662
'a' => $created[0][1]

protocol/V4.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ public function pullAll(...$args)
2323

2424
public function pull(...$args)
2525
{
26-
if (empty($args)) {
27-
$args[0]['n'] = -1;
28-
}
29-
3026
try {
31-
$msg = $this->packer->pack(0x3F, (object)($args[0] ?? []));
27+
$msg = $this->packer->pack(0x3F, $args[0]);
3228
} catch (Exception $ex) {
3329
Bolt::error($ex->getMessage());
3430
return false;
@@ -59,7 +55,7 @@ public function discardAll(...$args): bool
5955
public function discard(...$args): bool
6056
{
6157
try {
62-
$msg = $this->packer->pack(0x2F, $args[0] ?? []);
58+
$msg = $this->packer->pack(0x2F, $args[0]);
6359
} catch (Exception $ex) {
6460
Bolt::error($ex->getMessage());
6561
return false;

protocol/V4_1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class V4_1 extends V4
1818

1919
public function hello(...$args): bool
2020
{
21-
if (count($args) < 4) {
21+
if (count($args) != 5) {
2222
Bolt::error('Wrong arguments count');
2323
return false;
2424
}
@@ -29,7 +29,7 @@ public function hello(...$args): bool
2929
'scheme' => $args[1],
3030
'principal' => $args[2],
3131
'credentials' => $args[3],
32-
'routing' => (object)($args[4] ?? [])
32+
'routing' => is_array($args[4]) ? (object)$args[4] : null
3333
]);
3434
} catch (Exception $ex) {
3535
Bolt::error($ex->getMessage());

0 commit comments

Comments
 (0)