9
9
10
10
namespace ArangoDb \Statement ;
11
11
12
+ use ArangoDb \Exception \NoCursorId ;
12
13
use ArangoDb \Exception \ServerException ;
13
- use ArangoDb \Http \Url ;
14
+ use ArangoDb \Http \TypeSupport ;
15
+ use ArangoDb \Type \CursorType ;
14
16
use Countable ;
15
- use Fig \Http \Message \RequestMethodInterface ;
16
17
use Fig \Http \Message \StatusCodeInterface ;
17
18
use Iterator ;
18
19
use Psr \Http \Client \ClientExceptionInterface ;
19
- use Psr \Http \Client \ClientInterface ;
20
- use Psr \Http \Message \RequestFactoryInterface ;
21
- use Psr \Http \Message \RequestInterface ;
22
20
23
21
/**
24
22
* @implements Iterator<int, mixed>
25
23
*/
26
24
final class Statement implements QueryResult, Iterator, Countable
27
25
{
28
26
/**
29
- * @var ClientInterface
27
+ * @var TypeSupport
30
28
*/
31
29
private $ client ;
32
30
33
31
/**
34
- * @var RequestFactoryInterface
32
+ * @var CursorType
35
33
*/
36
- private $ requestFactory ;
37
-
38
- /**
39
- * @var RequestInterface
40
- */
41
- private $ request ;
34
+ private $ cursor ;
42
35
43
36
/**
44
37
* @var StreamHandler
@@ -60,20 +53,17 @@ final class Statement implements QueryResult, Iterator, Countable
60
53
/**
61
54
* Query is executed on first access
62
55
*
63
- * @param ClientInterface $client - connection to be used
64
- * @param RequestInterface $request Cursor request
65
- * @param RequestFactoryInterface $requestFactory
56
+ * @param TypeSupport $client - connection to be used
57
+ * @param CursorType $cursor
66
58
* @param StreamHandlerFactoryInterface $streamHandlerFactory
67
59
*/
68
60
public function __construct (
69
- ClientInterface $ client ,
70
- RequestInterface $ request ,
71
- RequestFactoryInterface $ requestFactory ,
61
+ TypeSupport $ client ,
62
+ CursorType $ cursor ,
72
63
StreamHandlerFactoryInterface $ streamHandlerFactory
73
64
) {
74
65
$ this ->client = $ client ;
75
- $ this ->request = $ request ;
76
- $ this ->requestFactory = $ requestFactory ;
66
+ $ this ->cursor = $ cursor ;
77
67
$ this ->streamHandlerFactory = $ streamHandlerFactory ;
78
68
}
79
69
@@ -85,15 +75,17 @@ public function __construct(
85
75
*/
86
76
private function fetchOutstanding (): void
87
77
{
88
- $ request = $ this ->fetches === 0
89
- ? $ this ->request
90
- : $ this ->requestFactory ->createRequest (
91
- RequestMethodInterface::METHOD_PUT ,
92
- Url::CURSOR . '/ ' . $ this ->streamHandler ->cursorId ()
93
- );
94
-
95
- $ request ->getBody ()->rewind ();
96
- $ response = $ this ->client ->sendRequest ($ request );
78
+ if ($ this ->fetches === 0 ) {
79
+ $ request = $ this ->cursor ;
80
+ } else {
81
+ $ cursorId = $ this ->streamHandler ->cursorId ();
82
+
83
+ if ($ cursorId === null ) {
84
+ throw NoCursorId::forType ($ this ->cursor );
85
+ }
86
+ $ request = $ this ->cursor ::nextBatch ($ cursorId );
87
+ }
88
+ $ response = $ this ->client ->sendType ($ request );
97
89
98
90
$ httpStatusCode = $ response ->getStatusCode ();
99
91
0 commit comments