@@ -143,17 +143,18 @@ public function setTimeout(float $timeout): void
143
143
$ this ->factory ->getConnection ()->setTimeout ($ timeout );
144
144
}
145
145
146
+ /**
147
+ * Closes the connection.
148
+ *
149
+ * Any of the preconditioned states are: 'READY', 'STREAMING', 'TX_READY', 'TX_STREAMING', 'FAILED', 'INTERRUPTED'.
150
+ * Sends signal: 'DISCONNECT'
151
+ */
146
152
public function close (): void
147
153
{
148
- $ this ->possibleStates (['READY ' , 'STREAMING ' , 'TX_READY ' , 'TX_STREAMING ' , 'FAILED ' , 'INTERRUPTED ' ], 'GOODBYE ' );
149
-
150
- $ this ->signal ('DISCONNECT ' );
151
-
152
154
$ this ->consumeResults ();
153
155
154
156
$ this ->protocol ()->goodbye ();
155
157
156
- $ this ->boltProtocol = null ;
157
158
$ this ->serverState = 'DEFUNCT ' ;
158
159
$ this ->subscribedResults = [];
159
160
}
@@ -170,12 +171,14 @@ private function consumeResults(): void
170
171
$ this ->subscribedResults = [];
171
172
}
172
173
174
+ /**
175
+ * Resets the connection.
176
+ *
177
+ * Any of the preconditioned states are: 'READY', 'STREAMING', 'TX_READY', 'TX_STREAMING', 'FAILED', 'INTERRUPTED'.
178
+ * Sends signal: 'INTERRUPT'
179
+ */
173
180
public function reset (): void
174
181
{
175
- $ this ->possibleStates (['READY ' , 'STREAMING ' , 'TX_READY ' , 'TX_STREAMING ' , 'FAILED ' , 'INTERRUPTED ' ], 'RESET ' );
176
-
177
- $ this ->signal ('INTERRUPT ' );
178
-
179
182
$ this ->consumeResults ();
180
183
181
184
try {
@@ -191,16 +194,15 @@ public function reset(): void
191
194
}
192
195
193
196
/**
194
- * @param string|null $database the database to connect to
195
- * @param float|null $timeout timeout in seconds
197
+ * Begins a transaction.
198
+ *
199
+ * Any of the preconditioned states are: 'READY', 'INTERRUPTED'.
196
200
*/
197
201
public function begin (?string $ database , ?float $ timeout ): void
198
202
{
199
- $ this ->possibleStates (['READY ' , 'INTERRUPTED ' ], 'BEGIN ' );
200
-
201
203
$ this ->consumeResults ();
202
204
203
- $ extra = $ this ->buildExtra ($ database , $ timeout );
205
+ $ extra = $ this ->buildRunExtra ($ database , $ timeout );
204
206
try {
205
207
$ this ->protocol ()->begin ($ extra );
206
208
} catch (IgnoredException $ e ) {
@@ -215,15 +217,14 @@ public function begin(?string $database, ?float $timeout): void
215
217
}
216
218
217
219
/**
218
- * @param string|null $database the database to connect to
219
- * @param float|null $timeout timeout in seconds
220
+ * Discards a result.
221
+ *
222
+ * Any of the preconditioned states are: 'STREAMING', 'TX_STREAMING', 'FAILED', 'INTERRUPTED'.
220
223
*/
221
224
public function discard (?int $ qid ): void
222
225
{
223
- $ this ->possibleStates (['STREAMING ' , 'TX_STREAMING ' , 'FAILED ' , 'INTERRUPTED ' ], 'DISCARD ' );
224
-
225
226
try {
226
- $ extra = $ this ->buildExtraParam (null , $ qid );
227
+ $ extra = $ this ->buildResultExtra (null , $ qid );
227
228
$ bolt = $ this ->protocol ();
228
229
229
230
if ($ bolt instanceof V4 ) {
@@ -245,18 +246,20 @@ public function discard(?int $qid): void
245
246
}
246
247
247
248
/**
249
+ * Runs a query/statement.
250
+ *
251
+ * Any of the preconditioned states are: 'STREAMING', 'TX_STREAMING', 'FAILED', 'INTERRUPTED'.
252
+ *
248
253
* @return BoltMeta
249
254
*/
250
255
public function run (string $ text , array $ parameters , ?string $ database , ?float $ timeout ): array
251
256
{
252
- $ this ->possibleStates (['READY ' , 'TX_READY ' , 'TX_STREAMING ' , 'FAILED ' , 'INTERRUPTED ' ], 'RUN ' );
253
-
254
257
if (!str_starts_with ($ this ->serverState , 'TX_ ' )) {
255
258
$ this ->consumeResults ();
256
259
}
257
260
258
261
try {
259
- $ extra = $ this ->buildExtra ($ database , $ timeout );
262
+ $ extra = $ this ->buildRunExtra ($ database , $ timeout );
260
263
261
264
$ tbr = $ this ->protocol ()->run ($ text , $ parameters , $ extra );
262
265
@@ -278,10 +281,13 @@ public function run(string $text, array $parameters, ?string $database, ?float $
278
281
}
279
282
}
280
283
284
+ /**
285
+ * Commits a transaction.
286
+ *
287
+ * Any of the preconditioned states are: 'TX_READY', 'INTERRUPTED'.
288
+ */
281
289
public function commit (): void
282
290
{
283
- $ this ->possibleStates (['TX_READY ' , 'INTERRUPTED ' ], 'COMMIT ' );
284
-
285
291
$ this ->consumeResults ();
286
292
287
293
try {
@@ -299,10 +305,13 @@ public function commit(): void
299
305
$ this ->serverState = 'READY ' ;
300
306
}
301
307
308
+ /**
309
+ * Rolls back a transaction.
310
+ *
311
+ * Any of the preconditioned states are: 'TX_READY', 'INTERRUPTED'.
312
+ */
302
313
public function rollback (): void
303
314
{
304
- $ this ->possibleStates (['TX_READY ' , 'INTERRUPTED ' ], 'ROLLBACK ' );
305
-
306
315
$ this ->consumeResults ();
307
316
308
317
try {
@@ -321,12 +330,15 @@ public function rollback(): void
321
330
}
322
331
323
332
/**
333
+ * Pulls a result set.
334
+ *
335
+ * Any of the preconditioned states are: 'TX_READY', 'INTERRUPTED'.
336
+ *
324
337
* @return non-empty-list<list>
325
338
*/
326
339
public function pull (?int $ qid , ?int $ fetchSize ): array
327
340
{
328
- $ this ->possibleStates (['STREAMING ' , 'TX_STREAMING ' , 'FAILED ' , 'INTERRUPTED ' ], 'ROLLBACK ' );
329
- $ extra = $ this ->buildExtraParam ($ fetchSize , $ qid );
341
+ $ extra = $ this ->buildResultExtra ($ fetchSize , $ qid );
330
342
331
343
$ bolt = $ this ->protocol ();
332
344
try {
@@ -362,12 +374,12 @@ public function getDriverConfiguration(): DriverConfiguration
362
374
363
375
public function __destruct ()
364
376
{
365
- if ($ this ->serverState !== 'DISCONNECTED ' && $ this ->serverState !== 'DEFUNCT ' && $ this -> boltProtocol !== null ) {
377
+ if ($ this ->serverState !== 'DISCONNECTED ' && $ this ->serverState !== 'DEFUNCT ' ) {
366
378
$ this ->close ();
367
379
}
368
380
}
369
381
370
- private function buildExtra (?string $ database , ?float $ timeout ): array
382
+ private function buildRunExtra (?string $ database , ?float $ timeout ): array
371
383
{
372
384
$ extra = [];
373
385
if ($ database ) {
@@ -380,7 +392,7 @@ private function buildExtra(?string $database, ?float $timeout): array
380
392
return $ extra ;
381
393
}
382
394
383
- public function buildExtraParam (?int $ fetchSize , ?int $ qid ): array
395
+ private function buildResultExtra (?int $ fetchSize , ?int $ qid ): array
384
396
{
385
397
$ extra = [];
386
398
if ($ fetchSize ) {
@@ -394,28 +406,14 @@ public function buildExtraParam(?int $fetchSize, ?int $qid): array
394
406
return $ extra ;
395
407
}
396
408
397
- /**
398
- * @return string
399
- */
400
409
public function getServerState (): string
401
410
{
402
411
return $ this ->serverState ;
403
412
}
404
413
405
- /**
406
- * @param callable(ServerStateTransition): void $listener
407
- */
408
- private function bindAfterTransitionEventListener ($ listener ): void
409
- {
410
- $ this ->subscribedResults [] = $ listener ;
411
- }
412
-
413
- private function possibleStates (array $ array , string $ string )
414
- {
415
- }
416
-
417
- private function signal (string $ string )
414
+ private function subscribeResult (SummarizedResult $ result ): void
418
415
{
416
+ $ this ->subscribedResults [] = WeakReference::create ($ result );
419
417
}
420
418
421
419
private function protocol (): V3
0 commit comments