diff --git a/UPGRADE-2.0.md b/UPGRADE-2.0.md index d623ae16c..cf87eebaa 100644 --- a/UPGRADE-2.0.md +++ b/UPGRADE-2.0.md @@ -15,3 +15,7 @@ UPGRADE FROM 1.x to 2.0 implementing classes to also implement iterator methods. The return types for the `key` and `current` methods have been narrowed to the types returned by cursor instances. + * The `MongoDB\Driver\CursorId` class was removed. + `MongoDB\Driver\Cursor::getId()` and + `MongoDB\Driver\CursorInterface::getId()` now return a `MongoDB\BSON\Int64` + instance. diff --git a/config.m4 b/config.m4 index 92cff6793..56f122c78 100644 --- a/config.m4 +++ b/config.m4 @@ -169,7 +169,6 @@ if test "$PHP_MONGODB" != "no"; then src/MongoDB/ClientEncryption.c \ src/MongoDB/Command.c \ src/MongoDB/Cursor.c \ - src/MongoDB/CursorId.c \ src/MongoDB/CursorInterface.c \ src/MongoDB/Manager.c \ src/MongoDB/Query.c \ diff --git a/config.w32 b/config.w32 index 40762d812..7dd7a89b0 100644 --- a/config.w32 +++ b/config.w32 @@ -116,7 +116,7 @@ if (PHP_MONGODB != "no") { EXTENSION("mongodb", "php_phongo.c", null, PHP_MONGODB_CFLAGS); MONGODB_ADD_SOURCES("/src", "phongo_apm.c phongo_bson.c phongo_bson_encode.c phongo_client.c phongo_compat.c phongo_error.c phongo_execute.c phongo_ini.c phongo_log.c phongo_util.c"); MONGODB_ADD_SOURCES("/src/BSON", "Binary.c BinaryInterface.c Document.c Iterator.c DBPointer.c Decimal128.c Decimal128Interface.c Int64.c Javascript.c JavascriptInterface.c MaxKey.c MaxKeyInterface.c MinKey.c MinKeyInterface.c ObjectId.c ObjectIdInterface.c PackedArray.c Persistable.c Regex.c RegexInterface.c Serializable.c Symbol.c Timestamp.c TimestampInterface.c Type.c Undefined.c Unserializable.c UTCDateTime.c UTCDateTimeInterface.c"); - MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorId.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c"); + MONGODB_ADD_SOURCES("/src/MongoDB", "BulkWrite.c ClientEncryption.c Command.c Cursor.c CursorInterface.c Manager.c Query.c ReadConcern.c ReadPreference.c Server.c ServerApi.c ServerDescription.c Session.c TopologyDescription.c WriteConcern.c WriteConcernError.c WriteError.c WriteResult.c"); MONGODB_ADD_SOURCES("/src/MongoDB/Exception", "AuthenticationException.c BulkWriteException.c CommandException.c ConnectionException.c ConnectionTimeoutException.c EncryptionException.c Exception.c ExecutionTimeoutException.c InvalidArgumentException.c LogicException.c RuntimeException.c ServerException.c SSLConnectionException.c UnexpectedValueException.c WriteException.c"); MONGODB_ADD_SOURCES("/src/MongoDB/Monitoring", "CommandFailedEvent.c CommandStartedEvent.c CommandSubscriber.c CommandSucceededEvent.c LogSubscriber.c SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c"); MONGODB_ADD_SOURCES("/src/libmongoc/src/common", PHP_MONGODB_COMMON_SOURCES); diff --git a/php_phongo.c b/php_phongo.c index e44eb3b19..b21f4d4da 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -254,7 +254,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ php_phongo_clientencryption_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_command_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_cursor_init_ce(INIT_FUNC_ARGS_PASSTHRU); - php_phongo_cursorid_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_manager_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_query_init_ce(INIT_FUNC_ARGS_PASSTHRU); php_phongo_readconcern_init_ce(INIT_FUNC_ARGS_PASSTHRU); diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index b41cb4561..491706c9c 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -115,17 +115,6 @@ static int php_phongo_cursor_to_array_apply(zend_object_iterator* iter, void* pu return ZEND_HASH_APPLY_KEEP; } -static void php_phongo_cursor_id_new_from_id(zval* object, int64_t cursorid) -{ - php_phongo_cursorid_t* intern; - - object_init_ex(object, php_phongo_cursorid_ce); - - intern = Z_CURSORID_OBJ_P(object); - intern->id = cursorid; - intern->initialized = true; -} - /* Returns an array of all result documents for this cursor */ static PHP_METHOD(MongoDB_Driver_Cursor, toArray) { @@ -143,22 +132,12 @@ static PHP_METHOD(MongoDB_Driver_Cursor, toArray) static PHP_METHOD(MongoDB_Driver_Cursor, getId) { php_phongo_cursor_t* intern; - zend_bool asInt64 = false; intern = Z_CURSOR_OBJ_P(getThis()); - PHONGO_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_BOOL(asInt64) - PHONGO_PARSE_PARAMETERS_END(); - - if (asInt64) { - phongo_int64_new(return_value, mongoc_cursor_get_id(intern->cursor)); - } else { - 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."); + PHONGO_PARSE_PARAMETERS_NONE(); - php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor)); - } + phongo_int64_new(return_value, mongoc_cursor_get_id(intern->cursor)); } /* Returns the Server object to which this cursor is attached */ diff --git a/src/MongoDB/Cursor.stub.php b/src/MongoDB/Cursor.stub.php index 44ae2e87c..05e7ecbe5 100644 --- a/src/MongoDB/Cursor.stub.php +++ b/src/MongoDB/Cursor.stub.php @@ -14,7 +14,7 @@ final private function __construct() {} public function current(): array|object|null {} - final public function getId(bool $asInt64 = false): CursorId|\MongoDB\BSON\Int64 {} + final public function getId(): \MongoDB\BSON\Int64 {} final public function getServer(): Server {} diff --git a/src/MongoDB/CursorId.c b/src/MongoDB/CursorId.c deleted file mode 100644 index 3a0576ac7..000000000 --- a/src/MongoDB/CursorId.c +++ /dev/null @@ -1,249 +0,0 @@ -/* - * Copyright 2014-present MongoDB, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include - -#include "php_phongo.h" -#include "phongo_error.h" -#include "phongo_util.h" -#include "CursorId_arginfo.h" - -zend_class_entry* php_phongo_cursorid_ce; - -/* Initialize the object from a numeric string and return whether it was - * successful. An exception will be thrown on error. */ -static bool php_phongo_cursorid_init_from_string(php_phongo_cursorid_t* intern, const char* s_id, size_t s_id_len) -{ - int64_t id; - - if (!php_phongo_parse_int64(&id, s_id, s_id_len)) { - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Error parsing \"%s\" as 64-bit id for %s initialization", s_id, ZSTR_VAL(php_phongo_cursorid_ce->name)); - return false; - } - - intern->id = id; - intern->initialized = true; - return true; -} - -/* Initialize the object from a HashTable and return whether it was successful. - * An exception will be thrown on error. */ -static bool php_phongo_cursorid_init_from_hash(php_phongo_cursorid_t* intern, HashTable* props) -{ - zval* value; - - if ((value = zend_hash_str_find(props, "id", sizeof("id") - 1)) && Z_TYPE_P(value) == IS_STRING) { - return php_phongo_cursorid_init_from_string(intern, Z_STRVAL_P(value), Z_STRLEN_P(value)); - } - - phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "%s initialization requires \"id\" string field", ZSTR_VAL(php_phongo_cursorid_ce->name)); - return false; -} - -static HashTable* php_phongo_cursorid_get_properties_hash(zend_object* object, bool is_temp, bool is_serialize) -{ - php_phongo_cursorid_t* intern; - HashTable* props; - - intern = Z_OBJ_CURSORID(object); - - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); - - if (!intern->initialized) { - return props; - } - - { - zval value; - - if (is_serialize) { - ZVAL_INT64_STRING(&value, intern->id); - } else { -#if SIZEOF_ZEND_LONG == 4 - if (intern->id > INT32_MAX || intern->id < INT32_MIN) { - ZVAL_INT64_STRING(&value, intern->id); - } else { - ZVAL_LONG(&value, intern->id); - } -#else - ZVAL_LONG(&value, intern->id); -#endif - } - zend_hash_str_update(props, "id", sizeof("id") - 1, &value); - } - - return props; -} - -PHP_METHOD(MongoDB_Driver_CursorId, __set_state) -{ - php_phongo_cursorid_t* intern; - HashTable* props; - zval* array; - - PHONGO_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(array) - PHONGO_PARSE_PARAMETERS_END(); - - object_init_ex(return_value, php_phongo_cursorid_ce); - - intern = Z_CURSORID_OBJ_P(return_value); - props = Z_ARRVAL_P(array); - - php_phongo_cursorid_init_from_hash(intern, props); -} - -/* Returns the string representation of the CursorId */ -PHP_METHOD(MongoDB_Driver_CursorId, __toString) -{ - php_phongo_cursorid_t* intern; - char* tmp; - int tmp_len; - - intern = Z_CURSORID_OBJ_P(getThis()); - - PHONGO_PARSE_PARAMETERS_NONE(); - - tmp_len = spprintf(&tmp, 0, "%" PRId64, intern->id); - RETVAL_STRINGL(tmp, tmp_len); - efree(tmp); -} - -PHP_METHOD(MongoDB_Driver_CursorId, serialize) -{ - php_phongo_cursorid_t* intern; - zval retval; - php_serialize_data_t var_hash; - smart_str buf = { 0 }; - - PHONGO_PARSE_PARAMETERS_NONE(); - - intern = Z_CURSORID_OBJ_P(getThis()); - - array_init_size(&retval, 1); - ADD_ASSOC_INT64_AS_STRING(&retval, "id", intern->id); - - PHP_VAR_SERIALIZE_INIT(var_hash); - php_var_serialize(&buf, &retval, &var_hash); - smart_str_0(&buf); - PHP_VAR_SERIALIZE_DESTROY(var_hash); - - PHONGO_RETVAL_SMART_STR(buf); - - smart_str_free(&buf); - zval_ptr_dtor(&retval); -} - -PHP_METHOD(MongoDB_Driver_CursorId, unserialize) -{ - php_phongo_cursorid_t* intern; - char* serialized; - size_t serialized_len; - zval props; - php_unserialize_data_t var_hash; - - intern = Z_CURSORID_OBJ_P(getThis()); - - PHONGO_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_STRING(serialized, serialized_len) - PHONGO_PARSE_PARAMETERS_END(); - - PHP_VAR_UNSERIALIZE_INIT(var_hash); - if (!php_var_unserialize(&props, (const unsigned char**) &serialized, (unsigned char*) serialized + serialized_len, &var_hash)) { - zval_ptr_dtor(&props); - phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s unserialization failed", ZSTR_VAL(php_phongo_cursorid_ce->name)); - - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - return; - } - PHP_VAR_UNSERIALIZE_DESTROY(var_hash); - - php_phongo_cursorid_init_from_hash(intern, HASH_OF(&props)); - zval_ptr_dtor(&props); -} - -PHP_METHOD(MongoDB_Driver_CursorId, __serialize) -{ - PHONGO_PARSE_PARAMETERS_NONE(); - - RETURN_ARR(php_phongo_cursorid_get_properties_hash(Z_OBJ_P(getThis()), true, true)); -} - -PHP_METHOD(MongoDB_Driver_CursorId, __unserialize) -{ - zval* data; - - PHONGO_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ARRAY(data) - PHONGO_PARSE_PARAMETERS_END(); - - php_phongo_cursorid_init_from_hash(Z_CURSORID_OBJ_P(getThis()), Z_ARRVAL_P(data)); -} - -PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_CursorId) - -/* MongoDB\Driver\CursorId object handlers */ -static zend_object_handlers php_phongo_handler_cursorid; - -static void php_phongo_cursorid_free_object(zend_object* object) -{ - php_phongo_cursorid_t* intern = Z_OBJ_CURSORID(object); - - zend_object_std_dtor(&intern->std); - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } -} - -static zend_object* php_phongo_cursorid_create_object(zend_class_entry* class_type) -{ - php_phongo_cursorid_t* intern = zend_object_alloc(sizeof(php_phongo_cursorid_t), class_type); - - zend_object_std_init(&intern->std, class_type); - object_properties_init(&intern->std, class_type); - - intern->std.handlers = &php_phongo_handler_cursorid; - - return &intern->std; -} - -static HashTable* php_phongo_cursorid_get_debug_info(zend_object* object, int* is_temp) -{ - *is_temp = 1; - return php_phongo_cursorid_get_properties_hash(object, true, false); -} - -static HashTable* php_phongo_cursorid_get_properties(zend_object* object) -{ - return php_phongo_cursorid_get_properties_hash(object, false, false); -} - -void php_phongo_cursorid_init_ce(INIT_FUNC_ARGS) -{ - php_phongo_cursorid_ce = register_class_MongoDB_Driver_CursorId(zend_ce_serializable, zend_ce_stringable); - php_phongo_cursorid_ce->create_object = php_phongo_cursorid_create_object; - - memcpy(&php_phongo_handler_cursorid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_cursorid.get_debug_info = php_phongo_cursorid_get_debug_info; - php_phongo_handler_cursorid.get_properties = php_phongo_cursorid_get_properties; - php_phongo_handler_cursorid.free_obj = php_phongo_cursorid_free_object; - php_phongo_handler_cursorid.offset = XtOffsetOf(php_phongo_cursorid_t, std); -} diff --git a/src/MongoDB/CursorId.stub.php b/src/MongoDB/CursorId.stub.php deleted file mode 100644 index 55412d36a..000000000 --- a/src/MongoDB/CursorId.stub.php +++ /dev/null @@ -1,25 +0,0 @@ -ce_flags |= ZEND_ACC_FINAL; - zend_class_implements(class_entry, 2, class_entry_Serializable, class_entry_Stringable); - - return class_entry; -} diff --git a/src/MongoDB/CursorInterface.stub.php b/src/MongoDB/CursorInterface.stub.php index 7eabe934a..6873320f0 100644 --- a/src/MongoDB/CursorInterface.stub.php +++ b/src/MongoDB/CursorInterface.stub.php @@ -11,7 +11,7 @@ interface CursorInterface extends \Iterator { public function current(): array|object|null {} - public function getId(): CursorId|\MongoDB\BSON\Int64; + public function getId(): \MongoDB\BSON\Int64; public function getServer(): Server; diff --git a/src/MongoDB/CursorInterface_arginfo.h b/src/MongoDB/CursorInterface_arginfo.h index b048178a0..00cc7cc8a 100644 --- a/src/MongoDB/CursorInterface_arginfo.h +++ b/src/MongoDB/CursorInterface_arginfo.h @@ -1,10 +1,10 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4503d323c3b7e45e21db5d48709c2a469e439a53 */ + * Stub hash: 3e304bb86abaff66e9714a02e3a20ec994b444ed */ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_MongoDB_Driver_CursorInterface_current, 0, 0, MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_NULL) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_MongoDB_Driver_CursorInterface_getId, 0, 0, MongoDB\\Driver\\CursorId|MongoDB\\BSON\\Int64, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_CursorInterface_getId, 0, 0, MongoDB\\BSON\\Int64, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_CursorInterface_getServer, 0, 0, MongoDB\\Driver\\Server, 0) diff --git a/src/MongoDB/Cursor_arginfo.h b/src/MongoDB/Cursor_arginfo.h index 0aebbaf85..84da619e1 100644 --- a/src/MongoDB/Cursor_arginfo.h +++ b/src/MongoDB/Cursor_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 154a75fecea87014fd07315ddec5d9f182dcf768 */ + * Stub hash: e598fccd4b9b82f6da64f43855fa7a302ac86ae8 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Cursor___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -7,8 +7,7 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_MongoDB_Driver_Cursor_current, 0, 0, MAY_BE_ARRAY|MAY_BE_OBJECT|MAY_BE_NULL) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_MongoDB_Driver_Cursor_getId, 0, 0, MongoDB\\Driver\\CursorId|MongoDB\\BSON\\Int64, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, asInt64, _IS_BOOL, 0, "false") +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Cursor_getId, 0, 0, MongoDB\\BSON\\Int64, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Cursor_getServer, 0, 0, MongoDB\\Driver\\Server, 0) diff --git a/src/phongo_bson_encode.c b/src/phongo_bson_encode.c index 77f3551ec..e20ab766c 100644 --- a/src/phongo_bson_encode.c +++ b/src/phongo_bson_encode.c @@ -147,11 +147,6 @@ static inline bool phongo_check_bson_serialize_return_type(zval* retval, zend_cl */ static void php_phongo_bson_append_object(bson_t* bson, php_phongo_field_path* field_path, php_phongo_bson_flags_t flags, const char* key, long key_len, zval* object) { - if (Z_TYPE_P(object) == IS_OBJECT && instanceof_function(Z_OBJCE_P(object), php_phongo_cursorid_ce)) { - bson_append_int64(bson, key, key_len, Z_CURSORID_OBJ_P(object)->id); - return; - } - if (Z_TYPE_P(object) == IS_OBJECT && instanceof_function(Z_OBJCE_P(object), php_phongo_type_ce)) { if (instanceof_function(Z_OBJCE_P(object), php_phongo_document_ce)) { php_phongo_document_t* intern = Z_DOCUMENT_OBJ_P(object); diff --git a/src/phongo_classes.h b/src/phongo_classes.h index 0bb513f08..090e4e7da 100644 --- a/src/phongo_classes.h +++ b/src/phongo_classes.h @@ -38,10 +38,6 @@ static inline php_phongo_cursor_t* php_cursor_fetch_object(zend_object* obj) { return (php_phongo_cursor_t*) ((char*) obj - XtOffsetOf(php_phongo_cursor_t, std)); } -static inline php_phongo_cursorid_t* php_cursorid_fetch_object(zend_object* obj) -{ - return (php_phongo_cursorid_t*) ((char*) obj - XtOffsetOf(php_phongo_cursorid_t, std)); -} static inline php_phongo_manager_t* php_manager_fetch_object(zend_object* obj) { return (php_phongo_manager_t*) ((char*) obj - XtOffsetOf(php_phongo_manager_t, std)); @@ -210,7 +206,6 @@ static inline php_phongo_topologyopeningevent_t* php_topologyopeningevent_fetch_ #define Z_CLIENTENCRYPTION_OBJ_P(zv) (php_clientencryption_fetch_object(Z_OBJ_P(zv))) #define Z_COMMAND_OBJ_P(zv) (php_command_fetch_object(Z_OBJ_P(zv))) #define Z_CURSOR_OBJ_P(zv) (php_cursor_fetch_object(Z_OBJ_P(zv))) -#define Z_CURSORID_OBJ_P(zv) (php_cursorid_fetch_object(Z_OBJ_P(zv))) #define Z_MANAGER_OBJ_P(zv) (php_manager_fetch_object(Z_OBJ_P(zv))) #define Z_QUERY_OBJ_P(zv) (php_query_fetch_object(Z_OBJ_P(zv))) #define Z_READCONCERN_OBJ_P(zv) (php_readconcern_fetch_object(Z_OBJ_P(zv))) @@ -257,7 +252,6 @@ static inline php_phongo_topologyopeningevent_t* php_topologyopeningevent_fetch_ #define Z_OBJ_CLIENTENCRYPTION(zo) (php_clientencryption_fetch_object(zo)) #define Z_OBJ_COMMAND(zo) (php_command_fetch_object(zo)) #define Z_OBJ_CURSOR(zo) (php_cursor_fetch_object(zo)) -#define Z_OBJ_CURSORID(zo) (php_cursorid_fetch_object(zo)) #define Z_OBJ_MANAGER(zo) (php_manager_fetch_object(zo)) #define Z_OBJ_QUERY(zo) (php_query_fetch_object(zo)) #define Z_OBJ_READCONCERN(zo) (php_readconcern_fetch_object(zo)) @@ -304,7 +298,6 @@ static inline php_phongo_topologyopeningevent_t* php_topologyopeningevent_fetch_ extern zend_class_entry* php_phongo_clientencryption_ce; extern zend_class_entry* php_phongo_command_ce; extern zend_class_entry* php_phongo_cursor_ce; -extern zend_class_entry* php_phongo_cursorid_ce; extern zend_class_entry* php_phongo_manager_ce; extern zend_class_entry* php_phongo_query_ce; extern zend_class_entry* php_phongo_readconcern_ce; @@ -421,7 +414,6 @@ extern void php_phongo_bulkwrite_init_ce(INIT_FUNC_ARGS); extern void php_phongo_clientencryption_init_ce(INIT_FUNC_ARGS); extern void php_phongo_command_init_ce(INIT_FUNC_ARGS); extern void php_phongo_cursor_init_ce(INIT_FUNC_ARGS); -extern void php_phongo_cursorid_init_ce(INIT_FUNC_ARGS); extern void php_phongo_manager_init_ce(INIT_FUNC_ARGS); extern void php_phongo_query_init_ce(INIT_FUNC_ARGS); extern void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS); diff --git a/src/phongo_structs.h b/src/phongo_structs.h index ff1804a0c..5a22cfc59 100644 --- a/src/phongo_structs.h +++ b/src/phongo_structs.h @@ -69,13 +69,6 @@ typedef struct { zend_object std; } php_phongo_cursor_t; -typedef struct { - bool initialized; - int64_t id; - HashTable* properties; - zend_object std; -} php_phongo_cursorid_t; - typedef struct { mongoc_client_t* client; int created_by_pid; diff --git a/tests/cursor/cursor-session-001.phpt b/tests/cursor/cursor-session-001.phpt index e5f0ef66f..006288f84 100644 --- a/tests/cursor/cursor-session-001.phpt +++ b/tests/cursor/cursor-session-001.phpt @@ -26,7 +26,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -35,7 +35,7 @@ $iterator->next(); * is exhausted. While this is primarily done to ensure implicit sessions for * command cursors are returned to the pool ASAP, it also applies to explicit * sessions. */ -printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-002.phpt b/tests/cursor/cursor-session-002.phpt index b8827c2c4..ab31c5a3c 100644 --- a/tests/cursor/cursor-session-002.phpt +++ b/tests/cursor/cursor-session-002.phpt @@ -28,12 +28,12 @@ $iterator->next(); /* Implicit sessions for query cursors are never exposed to PHPC, as they are * handled internally by libmongoc. Cursor debug ouput should never report such * sessions. */ -printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); -printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-003.phpt b/tests/cursor/cursor-session-003.phpt index 2eabbe616..1b52e06eb 100644 --- a/tests/cursor/cursor-session-003.phpt +++ b/tests/cursor/cursor-session-003.phpt @@ -30,7 +30,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -39,7 +39,7 @@ $iterator->next(); * is exhausted. While this is primarily done to ensure implicit sessions for * command cursors are returned to the pool ASAP, it also applies to explicit * sessions. */ -printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-session-004.phpt b/tests/cursor/cursor-session-004.phpt index 1fc23ffef..667d03909 100644 --- a/tests/cursor/cursor-session-004.phpt +++ b/tests/cursor/cursor-session-004.phpt @@ -29,7 +29,7 @@ $iterator = new IteratorIterator($cursor); $iterator->rewind(); $iterator->next(); -printf("Cursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("Cursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); $iterator->next(); @@ -38,7 +38,7 @@ $iterator->next(); * libmongoc, PHPC-1152 emulates its own implicit sessions for command cursors * in order to ensure that command cursors always share the same session as the * originating command. */ -printf("\nCursor ID is zero: %s\n", $cursor->getId(true) == 0 ? 'yes' : 'no'); +printf("\nCursor ID is zero: %s\n", $cursor->getId() == 0 ? 'yes' : 'no'); var_dump($cursor); ?> diff --git a/tests/cursor/cursor-tailable_error-002.phpt b/tests/cursor/cursor-tailable_error-002.phpt index dec2d52c6..9157c5e2d 100644 --- a/tests/cursor/cursor-tailable_error-002.phpt +++ b/tests/cursor/cursor-tailable_error-002.phpt @@ -57,7 +57,7 @@ echo throws(function() use ($manager) { if ($numAwaitAttempts === 5) { $cursor->getServer()->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command([ 'killCursors' => COLLECTION_NAME, - 'cursors' => [ $cursor->getId(true) ], + 'cursors' => [ $cursor->getId() ], ])); } diff --git a/tests/cursor/cursorid-getId-001.phpt b/tests/cursor/cursorid-getId-001.phpt index fd168d8ee..465349f19 100644 --- a/tests/cursor/cursorid-getId-001.phpt +++ b/tests/cursor/cursorid-getId-001.phpt @@ -20,24 +20,11 @@ $manager->executeBulkWrite(NS, $bulk); $cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2])); var_dump($cursor->getId()); -var_dump($cursor->getId(false)); -var_dump($cursor->getId(true)); ?> ===DONE=== --EXPECTF-- -Deprecated: MongoDB\Driver\Cursor::getId(): 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. in %s -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - %rint\(%d\)|string\(%d\) "%d"%r -} - -Deprecated: MongoDB\Driver\Cursor::getId(): 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. in %s -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - %rint\(%d\)|string\(%d\) "%d"%r -} object(MongoDB\BSON\Int64)#%d (%d) { ["integer"]=> string(%d) "%d" diff --git a/tests/cursorid/cursorid-001.phpt b/tests/cursorid/cursorid-001.phpt deleted file mode 100644 index 6cf970223..000000000 --- a/tests/cursorid/cursorid-001.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId BSON serialization ---SKIPIF-- - - - ---FILE-- -insert(['_id' => 1]); -$bulk->insert(['_id' => 2]); -$bulk->insert(['_id' => 3]); -$manager->executeBulkWrite(NS, $bulk); - -$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2])); -$cursorId = $cursor->getId(); - -hex_dump(fromPHP(['cid' => $cursorId])); - -?> -===DONE=== - ---EXPECTF-- -Deprecated: MongoDB\Driver\Cursor::getId(): 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. in %s - 0 : 12 00 00 00 12 63 69 64 00 %x %x %x %x %x %x %x [.....cid.%s] - 10 : %x 00 [%s.] -===DONE=== diff --git a/tests/cursorid/cursorid-002.phpt b/tests/cursorid/cursorid-002.phpt deleted file mode 100644 index 5809fd218..000000000 --- a/tests/cursorid/cursorid-002.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId BSON serialization for killCursors command ---SKIPIF-- - - - ---FILE-- -selectServer(new \MongoDB\Driver\ReadPreference('primary')); - -$bulk = new MongoDB\Driver\BulkWrite(); -$bulk->insert(['_id' => 1]); -$bulk->insert(['_id' => 2]); -$bulk->insert(['_id' => 3]); -$server->executeBulkWrite(NS, $bulk); - -$cursor = $server->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2])); -$cursorId = $cursor->getId(); - -$command = new MongoDB\Driver\Command([ - 'killCursors' => COLLECTION_NAME, - 'cursors' => [ $cursorId ], -]); - -/* Since the killCursors command result includes cursor IDs as 64-bit integers, - * unserializing the result document requires a 64-bit platform. */ -$result = $server->executeCommand(DATABASE_NAME, $command)->toArray()[0]; -printf("Killed %d cursor(s)\n", count($result->cursorsKilled)); -printf("Killed expected cursor: %s\n", (string) $cursorId === (string) $result->cursorsKilled[0] ? 'yes' : 'no'); - -?> -===DONE=== - ---EXPECTF-- -Deprecated: MongoDB\Driver\Cursor::getId(): 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. in %s -Killed 1 cursor(s) -Killed expected cursor: yes -===DONE=== diff --git a/tests/cursorid/cursorid-debug-001.phpt b/tests/cursorid/cursorid-debug-001.phpt deleted file mode 100644 index c08c99cff..000000000 --- a/tests/cursorid/cursorid-debug-001.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId debug output ---FILE-- - -===DONE=== - ---EXPECTF-- -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - %rint\(|string\(19\) "|%r7250031947823432848%r"|\)%r -} -===DONE=== diff --git a/tests/cursorid/cursorid-debug-002.phpt b/tests/cursorid/cursorid-debug-002.phpt deleted file mode 100644 index 6591a22ca..000000000 --- a/tests/cursorid/cursorid-debug-002.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId debug output on 32-bit platform ---SKIPIF-- - ---FILE-- - -===DONE=== - ---EXPECTF-- -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - string(19) "7250031947823432848" -} -===DONE=== diff --git a/tests/cursorid/cursorid-debug-003.phpt b/tests/cursorid/cursorid-debug-003.phpt deleted file mode 100644 index 2ff1b6448..000000000 --- a/tests/cursorid/cursorid-debug-003.phpt +++ /dev/null @@ -1,22 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId debug output on 64-bit platform ---SKIPIF-- - ---FILE-- - -===DONE=== - ---EXPECTF-- -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - int(7250031947823432848) -} -===DONE=== diff --git a/tests/cursorid/cursorid-serialization-002.phpt b/tests/cursorid/cursorid-serialization-002.phpt deleted file mode 100644 index 26bc6e220..000000000 --- a/tests/cursorid/cursorid-serialization-002.phpt +++ /dev/null @@ -1,44 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId serialization (__serialize and __unserialize) ---FILE-- - -===DONE=== - ---EXPECTF-- -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - %rint\(7250031947823432848\)|string\(19\) "7250031947823432848"%r -} -O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:19:"7250031947823432848";} -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - %rint\(7250031947823432848\)|string\(19\) "7250031947823432848"%r -} - -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - int(0) -} -O:23:"MongoDB\Driver\CursorId":1:{s:2:"id";s:1:"0";} -object(MongoDB\Driver\CursorId)#%d (%d) { - ["id"]=> - int(0) -} - -===DONE=== diff --git a/tests/cursorid/cursorid-serialization_error-001.phpt b/tests/cursorid/cursorid-serialization_error-001.phpt deleted file mode 100644 index 3adc7fdea..000000000 --- a/tests/cursorid/cursorid-serialization_error-001.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId unserialization errors (Serializable interface) ---FILE-- - -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\CursorId initialization requires "id" string field -===DONE=== diff --git a/tests/cursorid/cursorid-serialization_error-002.phpt b/tests/cursorid/cursorid-serialization_error-002.phpt deleted file mode 100644 index a647b8868..000000000 --- a/tests/cursorid/cursorid-serialization_error-002.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId unserialization errors (__serialize and __unserialize) ---FILE-- - -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\CursorId initialization requires "id" string field -===DONE=== diff --git a/tests/cursorid/cursorid-set_state-001.phpt b/tests/cursorid/cursorid-set_state-001.phpt deleted file mode 100644 index c0b8cb169..000000000 --- a/tests/cursorid/cursorid-set_state-001.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId::__set_state() ---FILE-- - '7250031947823432848', -])); -echo "\n"; - -?> -===DONE=== - ---EXPECTF-- -%r\\?%rMongoDB\Driver\CursorId::__set_state(array( - 'id' => %r(7250031947823432848|'7250031947823432848')%r, -)) -===DONE=== diff --git a/tests/cursorid/cursorid-set_state_error-001.phpt b/tests/cursorid/cursorid-set_state_error-001.phpt deleted file mode 100644 index 863940589..000000000 --- a/tests/cursorid/cursorid-set_state_error-001.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId::__set_state() requires "id" string field ---FILE-- - 0]); -}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; - -?> -===DONE=== - ---EXPECT-- -OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\CursorId initialization requires "id" string field -===DONE=== diff --git a/tests/cursorid/cursorid-tostring-001.phpt b/tests/cursorid/cursorid-tostring-001.phpt deleted file mode 100644 index 7625f3d58..000000000 --- a/tests/cursorid/cursorid-tostring-001.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId::__toString() ---FILE-- - -===DONE=== - ---EXPECT-- -string(19) "7250031947823432848" -===DONE=== diff --git a/tests/cursorid/cursorid-var_export-001.phpt b/tests/cursorid/cursorid-var_export-001.phpt deleted file mode 100644 index a38a16a3b..000000000 --- a/tests/cursorid/cursorid-var_export-001.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId: var_export() ---FILE-- - -===DONE=== - ---EXPECTF-- -%r\\?%rMongoDB\Driver\CursorId::__set_state(array( - 'id' => %r(7250031947823432848|'7250031947823432848')%r, -)) -===DONE=== diff --git a/tests/cursorid/cursorid_error-001.phpt b/tests/cursorid/cursorid_error-001.phpt deleted file mode 100644 index 1522a5112..000000000 --- a/tests/cursorid/cursorid_error-001.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -MongoDB\Driver\CursorId cannot be extended ---FILE-- - -===DONE=== - ---EXPECTF-- -Fatal error: Class MyCursorId %s final class %SMongoDB\Driver\CursorId%S in %s on line %d diff --git a/tests/functional/cursorid-001.phpt b/tests/functional/cursorid-001.phpt index ec9742437..581412031 100644 --- a/tests/functional/cursorid-001.phpt +++ b/tests/functional/cursorid-001.phpt @@ -20,7 +20,7 @@ $query = new MongoDB\Driver\Query(array(), array( $cursor = $manager->executeQuery(NS, $query); -$cursorid = $cursor->getId(true); +$cursorid = $cursor->getId(); var_dump($cursorid); var_dump($cursorid != 0);