Skip to content

Commit 25c9474

Browse files
cleanup of parameters. Added comments.
1 parent 15c4a63 commit 25c9474

File tree

3 files changed

+48
-28
lines changed

3 files changed

+48
-28
lines changed

Bolt.php

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,22 @@ private function packProtocolVersions(): string
191191
* @param string $name
192192
* @param string $user
193193
* @param string $password
194-
* @param array $extra
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>
195198
* @return bool
196199
* @throws Exception
197200
*/
198-
public function init(string $name, string $user, string $password, array $extra = []): bool
201+
public function init(string $name, string $user, string $password, array $routing = null): bool
199202
{
200203
if (!$this->handshake())
201204
return false;
202205

203206
if (self::$debug)
204207
echo 'INIT';
205208

206-
return $this->protocol->init($name, Bolt::$scheme, $user, $password, $extra);
209+
return $this->protocol->init($name, Bolt::$scheme, $user, $password, $routing);
207210
}
208211

209212
/**
@@ -213,20 +216,28 @@ public function init(string $name, string $user, string $password, array $extra
213216
* @param string $name
214217
* @param string $user
215218
* @param string $password
216-
* @param array $extra
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>
217223
* @return bool
218224
* @throws Exception
219225
*/
220-
public function hello(string $name, string $user, string $password, array $extra = []): bool
226+
public function hello(string $name, string $user, string $password, array $routing = null): bool
221227
{
222-
return $this->init($name, $user, $password, $extra);
228+
return $this->init($name, $user, $password, $routing);
223229
}
224230

225231
/**
226232
* Send RUN message
227233
* @param string $statement
228234
* @param array $parameters
229-
* @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>
230241
* @return mixed Return false on error
231242
*/
232243
public function run(string $statement, array $parameters = [], array $extra = [])
@@ -239,56 +250,65 @@ public function run(string $statement, array $parameters = [], array $extra = []
239250
/**
240251
* Send PULL_ALL message
241252
* @version <4
242-
* @param array $extra
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 ``.
243255
* @return mixed Array of records or false on error. Last array element is success message.
244256
*/
245-
public function pullAll(array $extra = [])
257+
public function pullAll(int $n = -1, int $qid = -1)
246258
{
247259
if (self::$debug)
248260
echo 'PULL';
249-
return $this->protocol->pullAll($extra);
261+
return $this->protocol->pullAll(['n' => $n, 'qid' => $qid]);
250262
}
251263

252264
/**
253265
* Send PULL message
254266
* @version >=4
255267
* @internal PULL_ALL alias
256-
* @param array $extra
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 ``.
257270
* @return mixed Array of records or false on error. Last array element is success message.
258271
*/
259-
public function pull(array $extra = [])
272+
public function pull(int $n = -1, int $qid = -1)
260273
{
261-
return $this->pullAll($extra);
274+
return $this->pullAll($n, $qid);
262275
}
263276

264277
/**
265278
* Send DISCARD_ALL message
266279
* @version <4
267-
* @param array $extra
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 ``.
268282
* @return bool
269283
*/
270-
public function discardAll(array $extra = [])
284+
public function discardAll(int $n = -1, int $qid = -1)
271285
{
272286
if (self::$debug)
273287
echo 'DISCARD';
274-
return $this->protocol->discardAll($extra);
288+
return $this->protocol->discardAll(['n' => $n, 'qid' => $qid]);
275289
}
276290

277291
/**
278292
* Send DISCARD message
279293
* @version >=4
280294
* @internal DISCARD_ALL alias
281-
* @param array $extra
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 ``.
282297
* @return bool
283298
*/
284-
public function discard(array $extra = []): bool
299+
public function discard(int $n = -1, int $qid = -1): bool
285300
{
286-
return $this->discardAll($extra);
301+
return $this->discardAll($n, $qid);
287302
}
288303

289304
/**
290305
* Send BEGIN message
291-
* @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>
292312
* @return bool
293313
*/
294314
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 & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ public function pullAll(...$args)
2323

2424
public function pull(...$args)
2525
{
26-
// The n specifies how many records to fetch. n=-1 will fetch all records.
27-
$args[0]['n'] = $args[0]['n'] ?? -1;
28-
2926
try {
30-
$msg = $this->packer->pack(0x3F, (object)$args[0]);
27+
$msg = $this->packer->pack(0x3F, $args[0]);
3128
} catch (Exception $ex) {
3229
Bolt::error($ex->getMessage());
3330
return false;
@@ -57,11 +54,8 @@ public function discardAll(...$args): bool
5754

5855
public function discard(...$args): bool
5956
{
60-
// The n specifies how many records to fetch. n=-1 will fetch all records.
61-
$args[0]['n'] = $args[0]['n'] ?? -1;
62-
6357
try {
64-
$msg = $this->packer->pack(0x2F, (object)$args[0]);
58+
$msg = $this->packer->pack(0x2F, $args[0]);
6559
} catch (Exception $ex) {
6660
Bolt::error($ex->getMessage());
6761
return false;

0 commit comments

Comments
 (0)