Skip to content
This repository was archived by the owner on Jun 18, 2020. It is now read-only.

Commit d14ea1d

Browse files
committed
Remove loading of first batch from constructor
- This makes calling rewind() explicit - If an exception is thrown, the response can be retrieved
1 parent d167923 commit d14ea1d

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

phpstorm-stubs/arangodb/arangodb.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,17 @@ public static function fromJson(string $json): Vpack
235235
/**
236236
* Handles queries
237237
*
238+
* You must call rewind first to get a result
239+
*
238240
* @link https://github.com/sandrokeil/arangodb-php-driver/blob/master/src/cursorIterator.h
239241
*/
240242
final class Cursor implements \Countable
241243
{
244+
public CONST ENTRY_TYPE = 0;
245+
public CONST ENTRY_TYPE_JSON = 100;
246+
public CONST ENTRY_TYPE_ARRAY = 101;
247+
public CONST ENTRY_TYPE_OBJECT = 102;
248+
242249
/**
243250
* Returns the number of results
244251
*
@@ -249,6 +256,7 @@ final class Cursor implements \Countable
249256
public function count()
250257
{
251258
}
259+
252260
/**
253261
* Return the current element
254262
* @link http://php.net/manual/en/iterator.current.php
@@ -287,15 +295,20 @@ public function valid()
287295
}
288296

289297
/**
290-
* Rewind the Iterator to the first element
291-
*
292-
* If iteration has already begun, this will throw an exception.
298+
* Rewind the Iterator to the first element and resets the cursor
293299
*
294300
* @link http://php.net/manual/en/iterator.rewind.php
295301
* @return void Any returned value is ignored.
296302
*/
297303
public function rewind()
298304
{
299305
}
306+
307+
/**
308+
* Rewinds the cursor and returns the result
309+
*/
310+
public function toArray(): array
311+
{
312+
}
300313
}
301314
}

src/cursor.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace arangodb { namespace fuerte { namespace php {
44

55
Cursor::Cursor(Connection* connection, Vpack* vpack): vpack(*vpack), connection(connection)
66
{
7-
this->rewind();
87
}
98

109
void Cursor::setOption(int option, int value)
@@ -128,8 +127,8 @@ namespace arangodb { namespace fuerte { namespace php {
128127
}
129128

130129
Php::Value Cursor::toArray() {
130+
this->rewind();
131131
Php::Array result;
132-
133132
int counter = 0;
134133
while(this->valid()) {
135134
result[counter++] = this->current();

tests/ConnectionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public function it_rewinds_cursor_multiple_times()
260260
'batchSize' => 10
261261
]));
262262

263+
$cursor->rewind();
263264
$iterations = 0;
264265
$dataSet1 = [];
265266
$dataSet2 = [];
@@ -295,6 +296,7 @@ public function it_gets_raw_response_from_cursor()
295296
'batchSize' => 10
296297
]));
297298

299+
$cursor->rewind();
298300
$response = $cursor->getResponse();
299301

300302
$this->assertInstanceOf(\ArangoDb\Response::class, $response);
@@ -314,6 +316,7 @@ public function it_rewinds_cursor_half_way_through()
314316
'batchSize' => 10
315317
]));
316318

319+
$cursor->rewind();
317320
$iterations = 0;
318321
$dataSet1 = [];
319322
$dataSet2 = [];

0 commit comments

Comments
 (0)