Skip to content

Commit

Permalink
Merge v1.20 into v1.x (#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
mongodb-php-bot authored Sep 16, 2024
2 parents dfc8a85 + 3a62cd6 commit 04c29be
Show file tree
Hide file tree
Showing 48 changed files with 449 additions and 241 deletions.
20 changes: 10 additions & 10 deletions .evergreen/config/build-variants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ buildvariants:
run_on: rhel90-small
tasks:
- name: "build-all-php"
- name: build-rhel83-zseries
display_name: "Build: RHEL 8.3 Zseries"
- name: build-rhel8-zseries
display_name: "Build: RHEL 8 Zseries"
tags: ["build", "rhel", "zseries", "tag"]
run_on: rhel83-zseries-small
run_on: rhel8-zseries-small
tasks:
- name: "build-all-php"
- name: build-rhel82-arm64
display_name: "Build: RHEL 8.2 ARM64"
- name: build-rhel8-arm64
display_name: "Build: RHEL 8 ARM64"
tags: ["build", "rhel", "arm64", "tag"]
run_on: rhel82-arm64
tasks:
- name: "build-all-php"
- name: build-rhel81-power8
display_name: "Build: RHEL 8.1 Power8"
- name: build-rhel8-power8
display_name: "Build: RHEL 8 Power8"
tags: ["build", "rhel", "power8", "tag"]
run_on: rhel81-power8-large
run_on: rhel8-power-large
tasks:
- name: "build-all-php"
- name: build-rhel80
display_name: "Build: RHEL 8.0"
- name: build-rhel8
display_name: "Build: RHEL 8 x64"
tags: ["build", "rhel", "x64", "pr", "tag"]
run_on: rhel80-small
tasks:
Expand Down
68 changes: 44 additions & 24 deletions src/BSON/UTCDateTime.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,35 @@ static bool php_phongo_utcdatetime_init_from_date(php_phongo_utcdatetime_t* inte
return true;
}

static bool php_phongo_utcdatetime_init_from_object(php_phongo_utcdatetime_t* intern, zend_object* object)
{
if (instanceof_function(object->ce, php_date_get_interface_ce())) {
php_phongo_utcdatetime_init_from_date(intern, php_date_obj_from_obj(object));

return true;
}

if (instanceof_function(object->ce, php_phongo_int64_ce)) {
php_phongo_utcdatetime_init(intern, php_int64_fetch_object(object)->integer);

return true;
}

phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected instance of %s or %s, %s given", ZSTR_VAL(php_date_get_interface_ce()->name), ZSTR_VAL(php_phongo_int64_ce->name), ZSTR_VAL(object->ce->name));

return false;
}

static bool php_phongo_utcdatetime_init_from_double(php_phongo_utcdatetime_t* intern, double milliseconds)
{
char tmp[24];
int tmp_len;

tmp_len = snprintf(tmp, sizeof(tmp), "%.0f", milliseconds > 0 ? floor(milliseconds) : ceil(milliseconds));

return php_phongo_utcdatetime_init_from_string(intern, tmp, tmp_len);
}

static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object, bool is_temp)
{
php_phongo_utcdatetime_t* intern;
Expand Down Expand Up @@ -179,36 +208,27 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct)
return;
}

if (Z_TYPE_P(milliseconds) == IS_OBJECT) {
if (instanceof_function(Z_OBJCE_P(milliseconds), php_date_get_interface_ce())) {
php_phongo_utcdatetime_init_from_date(intern, Z_PHPDATE_P(milliseconds));
} else {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected instance of DateTimeInterface, %s given", ZSTR_VAL(Z_OBJCE_P(milliseconds)->name));
}
return;
}

if (Z_TYPE_P(milliseconds) == IS_LONG) {
php_phongo_utcdatetime_init(intern, Z_LVAL_P(milliseconds));
return;
}
switch (Z_TYPE_P(milliseconds)) {
case IS_OBJECT:
php_phongo_utcdatetime_init_from_object(intern, Z_OBJ_P(milliseconds));
return;

if (Z_TYPE_P(milliseconds) == IS_DOUBLE) {
char tmp[24];
int tmp_len;
case IS_LONG:
php_phongo_utcdatetime_init(intern, Z_LVAL_P(milliseconds));
return;

tmp_len = snprintf(tmp, sizeof(tmp), "%.0f", Z_DVAL_P(milliseconds) > 0 ? floor(Z_DVAL_P(milliseconds)) : ceil(Z_DVAL_P(milliseconds)));
case IS_DOUBLE:
php_phongo_utcdatetime_init_from_double(intern, Z_DVAL_P(milliseconds));
return;

php_phongo_utcdatetime_init_from_string(intern, tmp, tmp_len);
return;
}
case IS_STRING:
php_error_docref(NULL, E_DEPRECATED, "Creating a %s instance with a string is deprecated and will be removed in ext-mongodb 2.0", ZSTR_VAL(php_phongo_utcdatetime_ce->name));

if (Z_TYPE_P(milliseconds) != IS_STRING) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds));
return;
php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds));
return;
}

php_phongo_utcdatetime_init_from_string(intern, Z_STRVAL_P(milliseconds), Z_STRLEN_P(milliseconds));
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Expected integer or string, %s given", PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(milliseconds));
}

static PHP_METHOD(MongoDB_BSON_UTCDateTime, __set_state)
Expand Down
2 changes: 1 addition & 1 deletion src/BSON/UTCDateTime.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final class UTCDateTime implements UTCDateTimeInterface, \JsonSerializable, Type, \Serializable, \Stringable
{
final public function __construct(int|string|float|\DateTimeInterface|null $milliseconds = null) {}
final public function __construct(int|string|float|\DateTimeInterface|Int64|null $milliseconds = null) {}

final public function toDateTime(): \DateTime {}

Expand Down
4 changes: 2 additions & 2 deletions src/BSON/UTCDateTime_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 24 additions & 20 deletions src/MongoDB/Monitoring/CommandFailedEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandfailedevent_ce;

PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandFailedEvent)

/* Returns the command name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -43,7 +42,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
RETVAL_STRING(intern->command_name);
}

/* Returns the database name for this event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -55,7 +53,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName)
RETVAL_STRING(intern->database_name);
}

/* Returns the event's duration in microseconds */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicros)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -67,7 +64,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicro
RETURN_LONG(intern->duration_micros);
}

/* Returns the error document associated with the event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -79,7 +75,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
RETURN_ZVAL(&intern->z_error, 1, 0);
}

/* Returns the event's operation ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getHost)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_STRING(intern->host.host);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -93,7 +97,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
RETVAL_STRING(operation_id);
}

/* Returns the reply document associated with the event */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getPort)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());

PHONGO_PARSE_PARAMETERS_NONE();

RETVAL_LONG(intern->host.port);
}

static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -113,7 +125,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
RETURN_ZVAL(&state.zchild, 0, 1);
}

/* Returns the event's request ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -127,7 +138,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
RETVAL_STRING(request_id);
}

/* Returns the Server from which the event originated */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
{
php_phongo_commandfailedevent_t* intern;
Expand All @@ -139,7 +149,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
phongo_server_init(return_value, &intern->manager, intern->server_id);
}

/* Returns the event's service ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
Expand All @@ -153,7 +162,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId)
phongo_objectid_new(return_value, &intern->service_id);
}

/* Returns the event's server connection ID */
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServerConnectionId)
{
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
Expand All @@ -174,12 +182,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServerConnect
RETURN_LONG(intern->server_connection_id);
}

/**
* Event thrown when a command has failed to execute.
*
* This class is only constructed internally.
*/

/* MongoDB\Driver\Monitoring\CommandFailedEvent object handlers */
static zend_object_handlers php_phongo_handler_commandfailedevent;

Expand Down Expand Up @@ -233,24 +235,26 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje

intern = Z_OBJ_COMMANDFAILEDEVENT(object);
*is_temp = 1;
array_init_size(&retval, 6);
array_init_size(&retval, 11);

ADD_ASSOC_STRING(&retval, "host", intern->host.host);
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);

ADD_ASSOC_ZVAL_EX(&retval, "error", &intern->z_error);
Z_ADDREF(intern->z_error);

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
zval_ptr_dtor(&reply_state.zchild);
goto done;
}

ADD_ASSOC_ZVAL(&retval, "reply", &reply_state.zchild);

snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
ADD_ASSOC_STRING(&retval, "requestId", request_id);

Expand Down
5 changes: 5 additions & 0 deletions src/MongoDB/Monitoring/CommandFailedEvent.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ final public function getDurationMicros(): int {}

final public function getError(): \Exception {}

final public function getHost(): string {}

final public function getOperationId(): string {}

final public function getPort(): int {}

final public function getReply(): object {}

final public function getRequestId(): string {}

/** @deprecated */
final public function getServer(): \MongoDB\Driver\Server {}

final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}
Expand Down
12 changes: 10 additions & 2 deletions src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 04c29be

Please sign in to comment.