Skip to content

Commit 43b1605

Browse files
Merge v1.20 into master (#1635)
2 parents 87c9104 + 0cfecc2 commit 43b1605

14 files changed

+127
-29
lines changed

src/MongoDB/Cursor.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,22 @@ static PHP_METHOD(MongoDB_Driver_Cursor, toArray)
143143
static PHP_METHOD(MongoDB_Driver_Cursor, getId)
144144
{
145145
php_phongo_cursor_t* intern;
146+
zend_bool asInt64 = false;
146147

147148
intern = Z_CURSOR_OBJ_P(getThis());
148149

149-
PHONGO_PARSE_PARAMETERS_NONE();
150+
PHONGO_PARSE_PARAMETERS_START(0, 1)
151+
Z_PARAM_OPTIONAL
152+
Z_PARAM_BOOL(asInt64)
153+
PHONGO_PARSE_PARAMETERS_END();
150154

151-
php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor));
155+
if (asInt64) {
156+
phongo_int64_new(return_value, mongoc_cursor_get_id(intern->cursor));
157+
} else {
158+
php_error_docref(NULL, E_DEPRECATED, "The method \"MongoDB\\Driver\\Cursor::getId\" will no longer return a \"MongoDB\\Driver\\CursorId\" instance in the future. Pass \"true\" as argument to change to the new behavior and receive a \"MongoDB\\BSON\\Int64\" instance instead.");
159+
160+
php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor));
161+
}
152162
}
153163

154164
/* Returns the Server object to which this cursor is attached */

src/MongoDB/Cursor.stub.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public function current(): array|object|null {}
1818
public function current() {}
1919
#endif
2020

21-
final public function getId(): CursorId {}
21+
#if PHP_VERSION_ID >= 80000
22+
/** @tentative-return-type */
23+
final public function getId(bool $asInt64 = false): CursorId|\MongoDB\BSON\Int64 {}
24+
#else
25+
/** @return CursorId|\MongoDB\BSON\Int64 */
26+
final public function getId(bool $asInt64 = false) {}
27+
#endif
2228

2329
final public function getServer(): Server {}
2430

src/MongoDB/CursorInterface.stub.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99

1010
interface CursorInterface extends \Traversable
1111
{
12+
#if PHP_VERSION_ID >= 80000
1213
/** @tentative-return-type */
13-
public function getId(): CursorId;
14+
public function getId(): CursorId|\MongoDB\BSON\Int64;
15+
#else
16+
/** @return CursorId|\MongoDB\BSON\Int64 */
17+
public function getId();
18+
#endif
1419

1520
/** @tentative-return-type */
1621
public function getServer(): Server;

src/MongoDB/CursorInterface_arginfo.h

Lines changed: 18 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MongoDB/Cursor_arginfo.h

Lines changed: 21 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/cursor/cursor-session-001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ $iterator = new IteratorIterator($cursor);
2626
$iterator->rewind();
2727
$iterator->next();
2828

29-
printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
29+
printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
3030
var_dump($cursor);
3131

3232
$iterator->next();
@@ -35,7 +35,7 @@ $iterator->next();
3535
* is exhausted. While this is primarily done to ensure implicit sessions for
3636
* command cursors are returned to the pool ASAP, it also applies to explicit
3737
* sessions. */
38-
printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
38+
printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
3939
var_dump($cursor);
4040

4141
?>

tests/cursor/cursor-session-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ $iterator->next();
2828
/* Implicit sessions for query cursors are never exposed to PHPC, as they are
2929
* handled internally by libmongoc. Cursor debug ouput should never report such
3030
* sessions. */
31-
printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
31+
printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
3232
var_dump($cursor);
3333

3434
$iterator->next();
3535

36-
printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
36+
printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
3737
var_dump($cursor);
3838

3939
?>

tests/cursor/cursor-session-003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $iterator = new IteratorIterator($cursor);
3030
$iterator->rewind();
3131
$iterator->next();
3232

33-
printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
33+
printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
3434
var_dump($cursor);
3535

3636
$iterator->next();
@@ -39,7 +39,7 @@ $iterator->next();
3939
* is exhausted. While this is primarily done to ensure implicit sessions for
4040
* command cursors are returned to the pool ASAP, it also applies to explicit
4141
* sessions. */
42-
printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
42+
printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
4343
var_dump($cursor);
4444

4545
?>

tests/cursor/cursor-session-004.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $iterator = new IteratorIterator($cursor);
2929
$iterator->rewind();
3030
$iterator->next();
3131

32-
printf("Cursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
32+
printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
3333
var_dump($cursor);
3434

3535
$iterator->next();
@@ -38,7 +38,7 @@ $iterator->next();
3838
* libmongoc, PHPC-1152 emulates its own implicit sessions for command cursors
3939
* in order to ensure that command cursors always share the same session as the
4040
* originating command. */
41-
printf("\nCursor ID is zero: %s\n", (string) $cursor->getId() === '0' ? 'yes' : 'no');
41+
printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no');
4242
var_dump($cursor);
4343

4444
?>

tests/cursor/cursor-tailable_error-002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ echo throws(function() use ($manager) {
5757
if ($numAwaitAttempts === 5) {
5858
$cursor->getServer()->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command([
5959
'killCursors' => COLLECTION_NAME,
60-
'cursors' => [ $cursor->getId() ],
60+
'cursors' => [ $cursor->getId(true) ],
6161
]));
6262
}
6363

0 commit comments

Comments
 (0)