Skip to content

PHPC-2242, PHPC-2243, PHPC-2244: BSON class improvements #1435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ if test "$PHP_MONGODB" != "no"; then
src/BSON/Unserializable.c \
src/BSON/UTCDateTime.c \
src/BSON/UTCDateTimeInterface.c \
src/BSON/Value.c \
src/BSON/functions.c \
src/MongoDB/BulkWrite.c \
src/MongoDB/ClientEncryption.c \
Expand Down
2 changes: 1 addition & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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_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 Value.c functions.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 functions.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/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 SDAMSubscriber.c Subscriber.c ServerChangedEvent.c ServerClosedEvent.c ServerHeartbeatFailedEvent.c ServerHeartbeatStartedEvent.c ServerHeartbeatSucceededEvent.c ServerOpeningEvent.c TopologyChangedEvent.c TopologyClosedEvent.c TopologyOpeningEvent.c functions.c");
Expand Down
1 change: 0 additions & 1 deletion php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
php_phongo_timestamp_interface_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_utcdatetime_interface_init_ce(INIT_FUNC_ARGS_PASSTHRU);

php_phongo_value_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_iterator_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_packedarray_init_ce(INIT_FUNC_ARGS_PASSTHRU);
php_phongo_document_init_ce(INIT_FUNC_ARGS_PASSTHRU);
Expand Down
5 changes: 3 additions & 2 deletions src/BSON/Document.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "phongo_bson_encode.h"
#include "BSON/Document_arginfo.h"
#include "BSON/Iterator.h"
#include "BSON/Value.h"

zend_class_entry* php_phongo_document_ce;

Expand Down Expand Up @@ -187,7 +186,7 @@ static PHP_METHOD(MongoDB_BSON_Document, get)
RETURN_NULL();
}

phongo_value_new(return_value, bson_iter_value(&iter));
phongo_bson_value_to_zval(bson_iter_value(&iter), return_value);
}

static PHP_METHOD(MongoDB_BSON_Document, getIterator)
Expand Down Expand Up @@ -257,6 +256,8 @@ static PHP_METHOD(MongoDB_BSON_Document, toPHP)

intern = Z_DOCUMENT_OBJ_P(getThis());

state.map.int64_as_object = true;

if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) {
zval_ptr_dtor(&state.zchild);
php_phongo_bson_typemap_dtor(&state.map);
Expand Down
7 changes: 6 additions & 1 deletion src/BSON/Document.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ final static public function fromPHP(array|object $value): Document {}
final static public function fromPHP($value): Document {}
#endif

final public function get(string $key): Value {}
#if PHP_VERSION_ID >= 80000
final public function get(string $key): mixed {}
#else
/** @return mixed */
final public function get(string $key) {}
#endif

final public function getIterator(): Iterator {}

Expand Down
22 changes: 20 additions & 2 deletions src/BSON/Document_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a5464ed3bb6f730295df4e7945b5d3125b7af437 */
* Stub hash: 5994291bf2bfdac1b9d8bad9b96d4f443c2f49aa */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Document___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand All @@ -24,9 +24,17 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_Document_fromP
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_Document_get, 0, 1, MongoDB\\BSON\\Value, 0)
#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_BSON_Document_get, 0, 1, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_END_ARG_INFO()
#endif

#if !(PHP_VERSION_ID >= 80000)
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Document_get, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_Document_getIterator, 0, 0, MongoDB\\BSON\\Iterator, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -81,7 +89,12 @@ static ZEND_METHOD(MongoDB_BSON_Document, fromPHP);
#if !(PHP_VERSION_ID >= 80000)
static ZEND_METHOD(MongoDB_BSON_Document, fromPHP);
#endif
#if PHP_VERSION_ID >= 80000
static ZEND_METHOD(MongoDB_BSON_Document, get);
#endif
#if !(PHP_VERSION_ID >= 80000)
static ZEND_METHOD(MongoDB_BSON_Document, get);
#endif
static ZEND_METHOD(MongoDB_BSON_Document, getIterator);
static ZEND_METHOD(MongoDB_BSON_Document, has);
#if PHP_VERSION_ID >= 80000
Expand Down Expand Up @@ -110,7 +123,12 @@ static const zend_function_entry class_MongoDB_BSON_Document_methods[] = {
#if !(PHP_VERSION_ID >= 80000)
ZEND_ME(MongoDB_BSON_Document, fromPHP, arginfo_class_MongoDB_BSON_Document_fromPHP, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
#endif
#if PHP_VERSION_ID >= 80000
ZEND_ME(MongoDB_BSON_Document, get, arginfo_class_MongoDB_BSON_Document_get, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
#if !(PHP_VERSION_ID >= 80000)
ZEND_ME(MongoDB_BSON_Document, get, arginfo_class_MongoDB_BSON_Document_get, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
ZEND_ME(MongoDB_BSON_Document, getIterator, arginfo_class_MongoDB_BSON_Document_getIterator, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_ME(MongoDB_BSON_Document, has, arginfo_class_MongoDB_BSON_Document_has, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#if PHP_VERSION_ID >= 80000
Expand Down
3 changes: 1 addition & 2 deletions src/BSON/Iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "phongo_error.h"
#include "BSON/Iterator.h"
#include "BSON/Iterator_arginfo.h"
#include "BSON/Value.h"

zend_class_entry* php_phongo_iterator_ce;

Expand Down Expand Up @@ -90,7 +89,7 @@ static void php_phongo_iterator_build_current(php_phongo_iterator_t* intern)
{
php_phongo_iterator_free_current(intern);

phongo_value_new(&intern->current, bson_iter_value(&intern->iter));
phongo_bson_value_to_zval(bson_iter_value(&intern->iter), &intern->current);
}

static HashTable* php_phongo_iterator_get_properties_hash(phongo_compat_object_handler_type* object, bool is_temp)
Expand Down
7 changes: 6 additions & 1 deletion src/BSON/Iterator.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ final class Iterator implements \Iterator
{
final private function __construct() {}

final public function current(): Value {}
#if PHP_VERSION_ID >= 80000
final public function current(): mixed {}
#else
/** @return mixed */
final public function current() {}
#endif

#if PHP_VERSION_ID >= 80000
final public function key(): string|int {}
Expand Down
24 changes: 20 additions & 4 deletions src/BSON/Iterator_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 97a4909ec6d6a3815686576310306dbb449ffb3b */
* Stub hash: 3c935268e2187085468340004c8dc67052d5c19b */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Iterator___construct, 0, 0, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_Iterator_current, 0, 0, MongoDB\\BSON\\Value, 0)
#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_BSON_Iterator_current, 0, 0, IS_MIXED, 0)
ZEND_END_ARG_INFO()
#endif

#if !(PHP_VERSION_ID >= 80000)
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Iterator_current, 0, 0, 0)
ZEND_END_ARG_INFO()
#endif

#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_MongoDB_BSON_Iterator_key, 0, 0, MAY_BE_STRING|MAY_BE_LONG)
ZEND_END_ARG_INFO()
#endif

#if !(PHP_VERSION_ID >= 80000)
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_Iterator_key, 0, 0, 0)
ZEND_END_ARG_INFO()
#define arginfo_class_MongoDB_BSON_Iterator_key arginfo_class_MongoDB_BSON_Iterator_current
#endif

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_BSON_Iterator_next, 0, 0, IS_VOID, 0)
Expand All @@ -29,7 +35,12 @@ ZEND_END_ARG_INFO()


static ZEND_METHOD(MongoDB_BSON_Iterator, __construct);
#if PHP_VERSION_ID >= 80000
static ZEND_METHOD(MongoDB_BSON_Iterator, current);
#endif
#if !(PHP_VERSION_ID >= 80000)
static ZEND_METHOD(MongoDB_BSON_Iterator, current);
#endif
#if PHP_VERSION_ID >= 80000
static ZEND_METHOD(MongoDB_BSON_Iterator, key);
#endif
Expand All @@ -44,7 +55,12 @@ static ZEND_METHOD(MongoDB_BSON_Iterator, __wakeup);

static const zend_function_entry class_MongoDB_BSON_Iterator_methods[] = {
ZEND_ME(MongoDB_BSON_Iterator, __construct, arginfo_class_MongoDB_BSON_Iterator___construct, ZEND_ACC_PRIVATE|ZEND_ACC_FINAL)
#if PHP_VERSION_ID >= 80000
ZEND_ME(MongoDB_BSON_Iterator, current, arginfo_class_MongoDB_BSON_Iterator_current, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
#if !(PHP_VERSION_ID >= 80000)
ZEND_ME(MongoDB_BSON_Iterator, current, arginfo_class_MongoDB_BSON_Iterator_current, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
#if PHP_VERSION_ID >= 80000
ZEND_ME(MongoDB_BSON_Iterator, key, arginfo_class_MongoDB_BSON_Iterator_key, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
Expand Down
6 changes: 3 additions & 3 deletions src/BSON/PackedArray.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "phongo_bson_encode.h"
#include "BSON/PackedArray_arginfo.h"
#include "BSON/Iterator.h"
#include "BSON/Value.h"

zend_class_entry* php_phongo_packedarray_ce;

Expand Down Expand Up @@ -138,7 +137,7 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, get)
RETURN_NULL();
}

phongo_value_new(return_value, bson_iter_value(&iter));
phongo_bson_value_to_zval(bson_iter_value(&iter), return_value);
}

static PHP_METHOD(MongoDB_BSON_PackedArray, getIterator)
Expand Down Expand Up @@ -185,7 +184,8 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, toPHP)

intern = Z_PACKEDARRAY_OBJ_P(getThis());

state.is_visiting_array = true;
state.is_visiting_array = true;
state.map.int64_as_object = true;

if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) {
zval_ptr_dtor(&state.zchild);
Expand Down
7 changes: 6 additions & 1 deletion src/BSON/PackedArray.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ private function __construct() {}

final static public function fromPHP(array $value): PackedArray {}

final public function get(int $index): Value {}
#if PHP_VERSION_ID >= 80000
final public function get(int $index): mixed {}
#else
/** @return mixed */
final public function get(int $index) {}
#endif

final public function getIterator(): Iterator {}

Expand Down
22 changes: 20 additions & 2 deletions src/BSON/PackedArray_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 5473b762427402941b0f73ff5b9f11ca45b98b26 */
* Stub hash: 3668c2846f7f546547f3203320342b4ef816b117 */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_PackedArray___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand All @@ -8,9 +8,17 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_PackedArray_fr
ZEND_ARG_TYPE_INFO(0, value, IS_ARRAY, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_PackedArray_get, 0, 1, MongoDB\\BSON\\Value, 0)
#if PHP_VERSION_ID >= 80000
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_BSON_PackedArray_get, 0, 1, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif

#if !(PHP_VERSION_ID >= 80000)
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_PackedArray_get, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
ZEND_END_ARG_INFO()
#endif

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_BSON_PackedArray_getIterator, 0, 0, MongoDB\\BSON\\Iterator, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -54,7 +62,12 @@ ZEND_END_ARG_INFO()

static ZEND_METHOD(MongoDB_BSON_PackedArray, __construct);
static ZEND_METHOD(MongoDB_BSON_PackedArray, fromPHP);
#if PHP_VERSION_ID >= 80000
static ZEND_METHOD(MongoDB_BSON_PackedArray, get);
#endif
#if !(PHP_VERSION_ID >= 80000)
static ZEND_METHOD(MongoDB_BSON_PackedArray, get);
#endif
static ZEND_METHOD(MongoDB_BSON_PackedArray, getIterator);
static ZEND_METHOD(MongoDB_BSON_PackedArray, has);
#if PHP_VERSION_ID >= 80000
Expand All @@ -74,7 +87,12 @@ static ZEND_METHOD(MongoDB_BSON_PackedArray, __serialize);
static const zend_function_entry class_MongoDB_BSON_PackedArray_methods[] = {
ZEND_ME(MongoDB_BSON_PackedArray, __construct, arginfo_class_MongoDB_BSON_PackedArray___construct, ZEND_ACC_PRIVATE)
ZEND_ME(MongoDB_BSON_PackedArray, fromPHP, arginfo_class_MongoDB_BSON_PackedArray_fromPHP, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC|ZEND_ACC_FINAL)
#if PHP_VERSION_ID >= 80000
ZEND_ME(MongoDB_BSON_PackedArray, get, arginfo_class_MongoDB_BSON_PackedArray_get, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
#if !(PHP_VERSION_ID >= 80000)
ZEND_ME(MongoDB_BSON_PackedArray, get, arginfo_class_MongoDB_BSON_PackedArray_get, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#endif
ZEND_ME(MongoDB_BSON_PackedArray, getIterator, arginfo_class_MongoDB_BSON_PackedArray_getIterator, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
ZEND_ME(MongoDB_BSON_PackedArray, has, arginfo_class_MongoDB_BSON_PackedArray_has, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
#if PHP_VERSION_ID >= 80000
Expand Down
Loading