From c394d374b6c3c748ff078323efead3c656d688e9 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Fri, 13 Sep 2024 17:01:59 +0200 Subject: [PATCH 1/3] PHPC-2443: Deprecate string argument and accept Int64 instances in UTCDateTime constructor (#1643) * Refactor UTCDateTime initialisation logic * PHPC-2443: Deprecate passing string values to UTCDateTime constructor * PHPC-2443: Accept Int64 instances in UTCDateTime constructor * Use Int64 instances in tests * Use 64-bit value in UTCDateTime tests * Fix missing word in deprecation message * Extract init methods for utcdatetime_t --- src/BSON/UTCDateTime.c | 68 ++++++++++++------- src/BSON/UTCDateTime.stub.php | 4 +- src/BSON/UTCDateTime_arginfo.h | 4 +- tests/bson/bson-fromPHP-003.phpt | 4 +- tests/bson/bson-fromPHP_error-003.phpt | 2 +- tests/bson/bson-toPHP-004.phpt | 2 +- tests/bson/bson-utcdatetime-001.phpt | 2 +- tests/bson/bson-utcdatetime-002.phpt | 4 +- tests/bson/bson-utcdatetime-008.phpt | 21 ++++++ tests/bson/bson-utcdatetime-009.phpt | 20 ++++++ tests/bson/bson-utcdatetime-clone-001.phpt | 2 +- tests/bson/bson-utcdatetime-clone-002.phpt | 2 +- .../bson-utcdatetime-get_properties-001.phpt | 2 +- .../bson-utcdatetime-get_properties-002.phpt | 2 +- tests/bson/bson-utcdatetime-int-size-001.phpt | 30 -------- tests/bson/bson-utcdatetime-int-size-002.phpt | 32 --------- .../bson-utcdatetime-serialization-003.phpt | 6 +- .../bson/bson-utcdatetime-todatetime-001.phpt | 2 +- .../bson/bson-utcdatetime-todatetime-002.phpt | 2 +- ...n-utcdatetime-todatetimeimmutable-001.phpt | 2 +- ...n-utcdatetime-todatetimeimmutable-002.phpt | 2 +- tests/bson/bson-utcdatetime-tostring-001.phpt | 2 +- tests/bson/bson-utcdatetime_error-001.phpt | 2 +- tests/bson/bson-utcdatetime_error-003.phpt | 9 ++- tests/bson/bson-utcdatetimeinterface-001.phpt | 2 +- tests/bson/bug0631.phpt | 2 +- .../writeresult-getupsertedids-002.phpt | 2 +- 27 files changed, 120 insertions(+), 114 deletions(-) create mode 100644 tests/bson/bson-utcdatetime-008.phpt create mode 100644 tests/bson/bson-utcdatetime-009.phpt delete mode 100644 tests/bson/bson-utcdatetime-int-size-001.phpt delete mode 100644 tests/bson/bson-utcdatetime-int-size-002.phpt diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 8cb153f84..8a732bfbc 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -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(phongo_compat_object_handler_type* object, bool is_temp) { php_phongo_utcdatetime_t* intern; @@ -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) diff --git a/src/BSON/UTCDateTime.stub.php b/src/BSON/UTCDateTime.stub.php index ac9143a33..575a70641 100644 --- a/src/BSON/UTCDateTime.stub.php +++ b/src/BSON/UTCDateTime.stub.php @@ -10,9 +10,9 @@ final class UTCDateTime implements UTCDateTimeInterface, \JsonSerializable, Type, \Serializable { #if PHP_VERSION_ID >= 80000 - final public function __construct(int|string|float|\DateTimeInterface|null $milliseconds = null) {} + final public function __construct(int|string|float|\DateTimeInterface|Int64|null $milliseconds = null) {} #else - /** @param int|string|float|\DateTimeInterface|null $milliseconds */ + /** @param int|string|float|\DateTimeInterface|Int64|null $milliseconds */ final public function __construct($milliseconds = null) {} #endif diff --git a/src/BSON/UTCDateTime_arginfo.h b/src/BSON/UTCDateTime_arginfo.h index df008acda..581ef5fb6 100644 --- a/src/BSON/UTCDateTime_arginfo.h +++ b/src/BSON/UTCDateTime_arginfo.h @@ -1,9 +1,9 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 2b7ac84585a74a210af3cb2061541977cc309e2d */ + * Stub hash: 11f44ab06f1806ec74876a6034c6fd75672fe2a8 */ #if PHP_VERSION_ID >= 80000 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_BSON_UTCDateTime___construct, 0, 0, 0) - ZEND_ARG_OBJ_TYPE_MASK(0, milliseconds, DateTimeInterface, MAY_BE_LONG|MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_NULL, "null") + ZEND_ARG_OBJ_TYPE_MASK(0, milliseconds, DateTimeInterface|MongoDB\\BSON\\Int64, MAY_BE_LONG|MAY_BE_STRING|MAY_BE_DOUBLE|MAY_BE_NULL, "null") ZEND_END_ARG_INFO() #endif diff --git a/tests/bson/bson-fromPHP-003.phpt b/tests/bson/bson-fromPHP-003.phpt index 38df0c17e..85fc850b2 100644 --- a/tests/bson/bson-fromPHP-003.phpt +++ b/tests/bson/bson-fromPHP-003.phpt @@ -12,8 +12,8 @@ class MyDocument { } $tests = array( - array(new MongoDB\BSON\UTCDateTime('1416445411987')), - array('x' => new MongoDB\BSON\UTCDateTime('1416445411987')), + array(new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987'))), + array('x' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987'))), array(new MyDocument), array('x' => new MyDocument), ); diff --git a/tests/bson/bson-fromPHP_error-003.phpt b/tests/bson/bson-fromPHP_error-003.phpt index b6f355ec8..195dccf0a 100644 --- a/tests/bson/bson-fromPHP_error-003.phpt +++ b/tests/bson/bson-fromPHP_error-003.phpt @@ -16,7 +16,7 @@ $tests = array( new MongoDB\BSON\ObjectId, new MongoDB\BSON\Regex('regexp', 'i'), new MongoDB\BSON\Timestamp(1234, 5678), - new MongoDB\BSON\UTCDateTime('1416445411987'), + new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987')), ); foreach ($tests as $document) { diff --git a/tests/bson/bson-toPHP-004.phpt b/tests/bson/bson-toPHP-004.phpt index 1bf4f1b81..c8e5497f8 100644 --- a/tests/bson/bson-toPHP-004.phpt +++ b/tests/bson/bson-toPHP-004.phpt @@ -29,7 +29,7 @@ $tests = [ new MongoDB\BSON\ObjectId('586c18d86118fd6c9012dec1'), new MongoDB\BSON\Regex('foo'), new MongoDB\BSON\Timestamp(1234, 5678), - new MongoDB\BSON\UTCDateTime('1483479256924'), + new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1483479256924')), ]; foreach ($tests as $value) { diff --git a/tests/bson/bson-utcdatetime-001.phpt b/tests/bson/bson-utcdatetime-001.phpt index 73bf8922e..7175e4004 100644 --- a/tests/bson/bson-utcdatetime-001.phpt +++ b/tests/bson/bson-utcdatetime-001.phpt @@ -11,7 +11,7 @@ require_once __DIR__ . "/../utils/basic.inc"; $manager = create_test_manager(); -$utcdatetime = new MongoDB\BSON\UTCDateTime("1416445411987"); +$utcdatetime = new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987')); $bulk = new MongoDB\Driver\BulkWrite(); $bulk->insert(array('_id' => 1, 'x' => $utcdatetime)); diff --git a/tests/bson/bson-utcdatetime-002.phpt b/tests/bson/bson-utcdatetime-002.phpt index 6da9fd291..27db72e4c 100644 --- a/tests/bson/bson-utcdatetime-002.phpt +++ b/tests/bson/bson-utcdatetime-002.phpt @@ -3,7 +3,7 @@ MongoDB\BSON\UTCDateTime debug handler --FILE-- - %rint\(|string\(13\) "|%r1416445411987%r"|\)%r + string(13) "1416445411987" } ===DONE=== diff --git a/tests/bson/bson-utcdatetime-008.phpt b/tests/bson/bson-utcdatetime-008.phpt new file mode 100644 index 000000000..d39e02088 --- /dev/null +++ b/tests/bson/bson-utcdatetime-008.phpt @@ -0,0 +1,21 @@ +--TEST-- +MongoDB\BSON\UTCDateTime construction from 64-bit integer as string +--FILE-- + +===DONE=== + +--EXPECTF-- +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s +object(MongoDB\BSON\UTCDateTime)#%d (%d) { + ["milliseconds"]=> + string(13) "1416445411987" +} +===DONE=== diff --git a/tests/bson/bson-utcdatetime-009.phpt b/tests/bson/bson-utcdatetime-009.phpt new file mode 100644 index 000000000..f17bc0e35 --- /dev/null +++ b/tests/bson/bson-utcdatetime-009.phpt @@ -0,0 +1,20 @@ +--TEST-- +MongoDB\BSON\UTCDateTime construction from Int64 object +--FILE-- + +===DONE=== + +--EXPECTF-- +object(MongoDB\BSON\UTCDateTime)#%d (%d) { + ["milliseconds"]=> + string(13) "1416445411987" +} +===DONE=== diff --git a/tests/bson/bson-utcdatetime-clone-001.phpt b/tests/bson/bson-utcdatetime-clone-001.phpt index 1a516c367..ac7e05111 100644 --- a/tests/bson/bson-utcdatetime-clone-001.phpt +++ b/tests/bson/bson-utcdatetime-clone-001.phpt @@ -8,7 +8,7 @@ MongoDB\BSON\UTCDateTime can be cloned (PHP < 8.2) require_once __DIR__ . "/../utils/basic.inc"; -$utcdatetime = new MongoDB\BSON\UTCDateTime("1416445411987"); +$utcdatetime = new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987')); $clone = clone $utcdatetime; diff --git a/tests/bson/bson-utcdatetime-clone-002.phpt b/tests/bson/bson-utcdatetime-clone-002.phpt index a7834ae59..b9e8922c1 100644 --- a/tests/bson/bson-utcdatetime-clone-002.phpt +++ b/tests/bson/bson-utcdatetime-clone-002.phpt @@ -8,7 +8,7 @@ MongoDB\BSON\UTCDateTime can be cloned (PHP >= 8.2) require_once __DIR__ . "/../utils/basic.inc"; -$utcdatetime = new MongoDB\BSON\UTCDateTime("1416445411987"); +$utcdatetime = new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1416445411987')); $clone = clone $utcdatetime; diff --git a/tests/bson/bson-utcdatetime-get_properties-001.phpt b/tests/bson/bson-utcdatetime-get_properties-001.phpt index ab4dd66d9..572884228 100644 --- a/tests/bson/bson-utcdatetime-get_properties-001.phpt +++ b/tests/bson/bson-utcdatetime-get_properties-001.phpt @@ -3,7 +3,7 @@ MongoDB\BSON\UTCDateTime get_properties handler (get_object_vars) --FILE-- $value) { var_dump($key); diff --git a/tests/bson/bson-utcdatetime-int-size-001.phpt b/tests/bson/bson-utcdatetime-int-size-001.phpt deleted file mode 100644 index be2eaf9d7..000000000 --- a/tests/bson/bson-utcdatetime-int-size-001.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -MongoDB\BSON\UTCDateTime integer parsing from string ---INI-- -date.timezone=UTC -error_reporting=-1 -dislay_errors=1 ---FILE-- -toDateTime()); - -?> -===DONE=== - ---EXPECTF-- -object(MongoDB\BSON\UTCDateTime)#%d (1) { - ["milliseconds"]=> - string(13) "1416445411987" -} -object(DateTime)#%d (3) { - ["date"]=> - string(26) "2014-11-20 01:03:31.987000" - ["timezone_type"]=> - int(1) - ["timezone"]=> - string(6) "+00:00" -} -===DONE=== diff --git a/tests/bson/bson-utcdatetime-int-size-002.phpt b/tests/bson/bson-utcdatetime-int-size-002.phpt deleted file mode 100644 index d303c9574..000000000 --- a/tests/bson/bson-utcdatetime-int-size-002.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -MongoDB\BSON\UTCDateTime integer parsing from number (64-bit) ---SKIPIF-- - ---INI-- -date.timezone=UTC -error_reporting=-1 -dislay_errors=1 ---FILE-- -toDateTime()); - -?> -===DONE=== - ---EXPECTF-- -object(MongoDB\BSON\UTCDateTime)#%d (1) { - ["milliseconds"]=> - string(13) "1416445411987" -} -object(DateTime)#%d (3) { - ["date"]=> - string(26) "2014-11-20 01:03:31.987000" - ["timezone_type"]=> - int(1) - ["timezone"]=> - string(6) "+00:00" -} -===DONE=== diff --git a/tests/bson/bson-utcdatetime-serialization-003.phpt b/tests/bson/bson-utcdatetime-serialization-003.phpt index 941057adf..c15c7548f 100644 --- a/tests/bson/bson-utcdatetime-serialization-003.phpt +++ b/tests/bson/bson-utcdatetime-serialization-003.phpt @@ -4,9 +4,9 @@ MongoDB\BSON\UTCDateTime serialization (__serialize and __unserialize) toDateTime(); var_dump(get_class($datetime)); var_dump($datetime->format(DATE_RSS)); diff --git a/tests/bson/bson-utcdatetime-todatetime-002.phpt b/tests/bson/bson-utcdatetime-todatetime-002.phpt index e003cd188..f127f19fe 100644 --- a/tests/bson/bson-utcdatetime-todatetime-002.phpt +++ b/tests/bson/bson-utcdatetime-todatetime-002.phpt @@ -5,7 +5,7 @@ date.timezone=UTC --FILE-- toDateTime(); var_dump(get_class($datetime)); echo $datetime->format('U.u'), "\n"; diff --git a/tests/bson/bson-utcdatetime-todatetimeimmutable-001.phpt b/tests/bson/bson-utcdatetime-todatetimeimmutable-001.phpt index 4d7bd8385..3e17543fb 100644 --- a/tests/bson/bson-utcdatetime-todatetimeimmutable-001.phpt +++ b/tests/bson/bson-utcdatetime-todatetimeimmutable-001.phpt @@ -5,7 +5,7 @@ date.timezone=America/Los_Angeles --FILE-- toDateTimeImmutable(); var_dump(get_class($datetime)); var_dump($datetime->format(DATE_RSS)); diff --git a/tests/bson/bson-utcdatetime-todatetimeimmutable-002.phpt b/tests/bson/bson-utcdatetime-todatetimeimmutable-002.phpt index b959d0bc1..8ccf140c9 100644 --- a/tests/bson/bson-utcdatetime-todatetimeimmutable-002.phpt +++ b/tests/bson/bson-utcdatetime-todatetimeimmutable-002.phpt @@ -5,7 +5,7 @@ date.timezone=UTC --FILE-- toDateTimeImmutable(); var_dump(get_class($datetime)); echo $datetime->format('U.u'), "\n"; diff --git a/tests/bson/bson-utcdatetime-tostring-001.phpt b/tests/bson/bson-utcdatetime-tostring-001.phpt index 53b9fdd82..b88fbe867 100644 --- a/tests/bson/bson-utcdatetime-tostring-001.phpt +++ b/tests/bson/bson-utcdatetime-tostring-001.phpt @@ -3,7 +3,7 @@ MongoDB\BSON\UTCDateTime::__toString() --FILE-- diff --git a/tests/bson/bson-utcdatetime_error-001.phpt b/tests/bson/bson-utcdatetime_error-001.phpt index 54534fbf6..7dc837507 100644 --- a/tests/bson/bson-utcdatetime_error-001.phpt +++ b/tests/bson/bson-utcdatetime_error-001.phpt @@ -14,5 +14,5 @@ echo throws(function() { --EXPECT-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -Expected instance of DateTimeInterface, stdClass given +Expected instance of DateTimeInterface or MongoDB\BSON\Int64, stdClass given ===DONE=== diff --git a/tests/bson/bson-utcdatetime_error-003.phpt b/tests/bson/bson-utcdatetime_error-003.phpt index 760eff8b2..6eb1fa741 100644 --- a/tests/bson/bson-utcdatetime_error-003.phpt +++ b/tests/bson/bson-utcdatetime_error-003.phpt @@ -26,13 +26,20 @@ echo throws(function() { ?> ===DONE=== ---EXPECT-- +--EXPECTF-- +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s OK: Got MongoDB\Driver\Exception\InvalidArgumentException Error parsing "1234.5678" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization + +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s OK: Got MongoDB\Driver\Exception\InvalidArgumentException Error parsing "9223372036854775808" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization + +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s OK: Got MongoDB\Driver\Exception\InvalidArgumentException Error parsing "-9223372036854775809" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization + +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a string is deprecated and will be removed in ext-mongodb 2.0 in %s OK: Got MongoDB\Driver\Exception\InvalidArgumentException Error parsing "18446744073709551615" as 64-bit integer for MongoDB\BSON\UTCDateTime initialization ===DONE=== diff --git a/tests/bson/bson-utcdatetimeinterface-001.phpt b/tests/bson/bson-utcdatetimeinterface-001.phpt index 26c31b2fb..babd2f798 100644 --- a/tests/bson/bson-utcdatetimeinterface-001.phpt +++ b/tests/bson/bson-utcdatetimeinterface-001.phpt @@ -3,7 +3,7 @@ MongoDB\BSON\UTCDateTimeInterface is implemented by MongoDB\BSON\UTCDateTime --FILE-- diff --git a/tests/bson/bug0631.phpt b/tests/bson/bug0631.phpt index c07f95863..3099076cd 100644 --- a/tests/bson/bug0631.phpt +++ b/tests/bson/bug0631.phpt @@ -7,7 +7,7 @@ date.timezone=UTC require_once __DIR__ . '/../utils/basic.inc'; -$utcdatetime = new MongoDB\BSON\UTCDateTime('1466540755123'); +$utcdatetime = new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1466540755123')); $datetime = $utcdatetime->toDateTime(); $s = serialize($datetime); diff --git a/tests/writeResult/writeresult-getupsertedids-002.phpt b/tests/writeResult/writeresult-getupsertedids-002.phpt index 786fa0956..713a8c212 100644 --- a/tests/writeResult/writeresult-getupsertedids-002.phpt +++ b/tests/writeResult/writeresult-getupsertedids-002.phpt @@ -25,7 +25,7 @@ $tests = [ new MongoDB\BSON\MinKey, new MongoDB\BSON\ObjectId('586c18d86118fd6c9012dec1'), new MongoDB\BSON\Timestamp(1234, 5678), - new MongoDB\BSON\UTCDateTime('1483479256924'), + new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1483479256924')), ]; $manager = create_test_manager(); From 3ffbe120f2d523180073c01dbbe213b81289fb5e Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Fri, 13 Sep 2024 17:02:41 +0200 Subject: [PATCH 2/3] PHPC-2413: Use new distros for RHEL ppc and Z (#1647) --- .evergreen/config/build-variants.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.evergreen/config/build-variants.yml b/.evergreen/config/build-variants.yml index fb0e81113..9dc1374a1 100644 --- a/.evergreen/config/build-variants.yml +++ b/.evergreen/config/build-variants.yml @@ -30,26 +30,26 @@ buildvariants: run_on: rhel90-small tasks: - name: "build-php-openssl3" - - 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: From 1869a724dbc01d65f48d8552b7f88d2277c7baf8 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Sun, 15 Sep 2024 21:50:04 -0400 Subject: [PATCH 3/3] PHPC-2442: Deprecate getServer, add getHost and getPort to APM events (#1644) Also updates initial array size for debug output and reorders output fields. * Expect alternative deprecation message for PHP 7.4 * Remove redundant comments for APM event methods --- src/MongoDB/Monitoring/CommandFailedEvent.c | 44 ++++++----- .../Monitoring/CommandFailedEvent.stub.php | 5 ++ .../Monitoring/CommandFailedEvent_arginfo.h | 12 ++- src/MongoDB/Monitoring/CommandStartedEvent.c | 42 ++++++----- .../Monitoring/CommandStartedEvent.stub.php | 5 ++ .../Monitoring/CommandStartedEvent_arginfo.h | 13 +++- .../Monitoring/CommandSucceededEvent.c | 43 ++++++----- .../Monitoring/CommandSucceededEvent.stub.php | 5 ++ .../CommandSucceededEvent_arginfo.h | 12 ++- src/phongo_apm.c | 6 ++ src/phongo_structs.h | 75 ++++++++++--------- tests/apm/commandFailedEvent-001.phpt | 8 +- tests/apm/commandFailedEvent-debug-001.phpt | 8 +- .../apm/commandFailedEvent-getServer-001.phpt | 44 +++++++++++ tests/apm/commandStartedEvent-001.phpt | 8 +- tests/apm/commandStartedEvent-debug-001.phpt | 10 ++- .../commandStartedEvent-getServer-001.phpt | 40 ++++++++++ tests/apm/commandSucceededEvent-001.phpt | 8 +- .../apm/commandSucceededEvent-debug-001.phpt | 8 +- .../commandSucceededEvent-getServer-001.phpt | 42 +++++++++++ 20 files changed, 320 insertions(+), 118 deletions(-) create mode 100644 tests/apm/commandFailedEvent-getServer-001.phpt create mode 100644 tests/apm/commandStartedEvent-getServer-001.phpt create mode 100644 tests/apm/commandSucceededEvent-getServer-001.phpt diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index 75a8e3e2e..bec83a1fa 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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()); @@ -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()); @@ -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; @@ -233,17 +235,16 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(phongo_compat_obj intern = Z_OBJ_COMMANDFAILEDEVENT(PHONGO_COMPAT_GET_OBJ(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; @@ -251,6 +252,9 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(phongo_compat_obj 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); diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.stub.php b/src/MongoDB/Monitoring/CommandFailedEvent.stub.php index 9c8c9041b..22dc30616 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.stub.php +++ b/src/MongoDB/Monitoring/CommandFailedEvent.stub.php @@ -19,12 +19,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 {} diff --git a/src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h b/src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h index d193f7075..39d94c991 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h +++ b/src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 6fd7c6597ad8e67b399cf4e7c41bb6cc5e6666d6 */ + * Stub hash: 3e04d69c1e4a42ee94149ac14ce1f3595448b472 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -15,8 +15,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getError, 0, 0, Exception, 0) ZEND_END_ARG_INFO() +#define arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getHost arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getCommandName + #define arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getOperationId arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getCommandName +#define arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getPort arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getDurationMicros + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getReply, 0, 0, IS_OBJECT, 0) ZEND_END_ARG_INFO() @@ -37,7 +41,9 @@ static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName) static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicros); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError); +static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getHost); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId); +static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getPort); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer); @@ -51,10 +57,12 @@ static const zend_function_entry class_MongoDB_Driver_Monitoring_CommandFailedEv ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getDatabaseName, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicros, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getDurationMicros, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getError, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getError, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getHost, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getHost, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getOperationId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getPort, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getPort, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getReply, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getRequestId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) - ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL|ZEND_ACC_DEPRECATED) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getServiceId, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getServiceId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandFailedEvent, getServerConnectionId, arginfo_class_MongoDB_Driver_Monitoring_CommandFailedEvent_getServerConnectionId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_FE_END diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.c b/src/MongoDB/Monitoring/CommandStartedEvent.c index f45159e8c..5c9f7446b 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.c +++ b/src/MongoDB/Monitoring/CommandStartedEvent.c @@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandstartedevent_ce; PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandStartedEvent) -/* Returns the command document associated with the event */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand) { php_phongo_commandstartedevent_t* intern; @@ -51,7 +50,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand) RETURN_ZVAL(&state.zchild, 0, 1); } -/* Returns the command name for this event */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName) { php_phongo_commandstartedevent_t* intern; @@ -63,7 +61,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName) RETVAL_STRING(intern->command_name); } -/* Returns the database name for this event */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName) { php_phongo_commandstartedevent_t* intern; @@ -75,7 +72,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName RETVAL_STRING(intern->database_name); } -/* Returns the event's operation ID */ +static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getHost) +{ + php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + + PHONGO_PARSE_PARAMETERS_NONE(); + + RETVAL_STRING(intern->host.host); +} + static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId) { php_phongo_commandstartedevent_t* intern; @@ -89,7 +94,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId) RETVAL_STRING(operation_id); } -/* Returns the event's request ID */ +static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getPort) +{ + php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + + PHONGO_PARSE_PARAMETERS_NONE(); + + RETVAL_LONG(intern->host.port); +} + static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId) { php_phongo_commandstartedevent_t* intern; @@ -103,7 +116,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId) RETVAL_STRING(request_id); } -/* Returns the Server from which the event originated */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer) { php_phongo_commandstartedevent_t* intern; @@ -115,7 +127,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer) phongo_server_init(return_value, &intern->manager, intern->server_id); } -/* Returns the event's service ID */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId) { php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); @@ -129,7 +140,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId) phongo_objectid_new(return_value, &intern->service_id); } -/* Returns the event's server connection ID */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnectionId) { php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); @@ -150,12 +160,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnec RETURN_LONG(intern->server_connection_id); } -/** - * Event thrown when a command has started to execute. - * - * This class is only constructed internally. - */ - /* MongoDB\Driver\Monitoring\CommandStartedEvent object handlers */ static zend_object_handlers php_phongo_handler_commandstartedevent; @@ -205,7 +209,12 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob intern = Z_OBJ_COMMANDSTARTEDEVENT(PHONGO_COMPAT_GET_OBJ(object)); *is_temp = 1; - array_init_size(&retval, 6); + array_init_size(&retval, 10); + + 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_STRING(&retval, "databaseName", intern->database_name); if (!php_phongo_bson_to_zval_ex(intern->command, &command_state)) { zval_ptr_dtor(&command_state.zchild); @@ -214,9 +223,6 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild); - ADD_ASSOC_STRING(&retval, "commandName", intern->command_name); - ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name); - snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id); ADD_ASSOC_STRING(&retval, "operationId", operation_id); diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.stub.php b/src/MongoDB/Monitoring/CommandStartedEvent.stub.php index c3dbf3718..f0ce09513 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.stub.php +++ b/src/MongoDB/Monitoring/CommandStartedEvent.stub.php @@ -17,10 +17,15 @@ final public function getCommandName(): string {} final public function getDatabaseName(): string {} + final public function getHost(): string {} + final public function getOperationId(): string {} + final public function getPort(): int {} + final public function getRequestId(): string {} + /** @deprecated */ final public function getServer(): \MongoDB\Driver\Server {} final public function getServiceId(): ?\MongoDB\BSON\ObjectId {} diff --git a/src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h b/src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h index f52bb79e1..34d7bd51c 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h +++ b/src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 4ff134c852d47ac645fcc505d3b9319eb46a3899 */ + * Stub hash: be9f02816a4b44d256cb139d12c55cc9ac5d15e5 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -12,8 +12,13 @@ ZEND_END_ARG_INFO() #define arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getDatabaseName arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getCommandName +#define arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getHost arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getCommandName + #define arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getOperationId arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getCommandName +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getPort, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() + #define arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getRequestId arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getCommandName ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getServer, 0, 0, MongoDB\\Driver\\Server, 0) @@ -30,7 +35,9 @@ static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, __construct); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName); +static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getHost); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId); +static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getPort); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId); @@ -42,9 +49,11 @@ static const zend_function_entry class_MongoDB_Driver_Monitoring_CommandStartedE ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getCommand, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getCommandName, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getDatabaseName, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getHost, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getHost, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getOperationId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getPort, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getPort, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getRequestId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) - ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL|ZEND_ACC_DEPRECATED) ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getServiceId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnectionId, arginfo_class_MongoDB_Driver_Monitoring_CommandStartedEvent_getServerConnectionId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_FE_END diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index e635850a1..6902a6ef2 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandsucceededevent_ce; PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandSucceededEvent) -/* Returns the command name for this event */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getCommandName) { php_phongo_commandsucceededevent_t* intern; @@ -43,7 +42,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getCommandNam RETVAL_STRING(intern->command_name); } -/* Returns the database name for this event */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDatabaseName) { php_phongo_commandsucceededevent_t* intern; @@ -55,7 +53,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDatabaseNa RETVAL_STRING(intern->database_name); } -/* Returns the event's duration in microseconds */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDurationMicros) { php_phongo_commandsucceededevent_t* intern; @@ -67,7 +64,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDurationMi RETURN_LONG(intern->duration_micros); } -/* Returns the event's operation ID */ +static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getHost) +{ + php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + + PHONGO_PARSE_PARAMETERS_NONE(); + + RETVAL_STRING(intern->host.host); +} + static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationId) { php_phongo_commandsucceededevent_t* intern; @@ -81,7 +86,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationI RETVAL_STRING(operation_id); } -/* Returns the reply document associated with the event */ +static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getPort) +{ + php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + + PHONGO_PARSE_PARAMETERS_NONE(); + + RETVAL_LONG(intern->host.port); +} + static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply) { php_phongo_commandsucceededevent_t* intern; @@ -101,7 +114,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply) RETURN_ZVAL(&state.zchild, 0, 1); } -/* Returns the event's request ID */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getRequestId) { php_phongo_commandsucceededevent_t* intern; @@ -115,7 +127,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getRequestId) RETVAL_STRING(request_id); } -/* Returns the Server from which the event originated */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer) { php_phongo_commandsucceededevent_t* intern; @@ -127,7 +138,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer) phongo_server_init(return_value, &intern->manager, intern->server_id); } -/* Returns the event's service ID */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServiceId) { php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); @@ -141,7 +151,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServiceId) phongo_objectid_new(return_value, &intern->service_id); } -/* Returns the event's server connection ID */ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServerConnectionId) { php_phongo_commandsucceededevent_t* intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); @@ -162,12 +171,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServerConn RETURN_LONG(intern->server_connection_id); } -/** - * Event thrown when a command has succeeded to execute. - * - * This class is only constructed internally. - */ - /* MongoDB\Driver\Monitoring\CommandSucceededEvent object handlers */ static zend_object_handlers php_phongo_handler_commandsucceededevent; @@ -217,14 +220,13 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(phongo_compat_ intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(PHONGO_COMPAT_GET_OBJ(object)); *is_temp = 1; - array_init_size(&retval, 6); + array_init_size(&retval, 10); + 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); - 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; @@ -232,6 +234,9 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(phongo_compat_ 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); diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.stub.php b/src/MongoDB/Monitoring/CommandSucceededEvent.stub.php index e671c06b6..4f2ec888a 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.stub.php +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.stub.php @@ -17,12 +17,17 @@ final public function getDatabaseName(): string {} final public function getDurationMicros(): int {} + 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 {} diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent_arginfo.h b/src/MongoDB/Monitoring/CommandSucceededEvent_arginfo.h index 8ccdb3bb5..047fdcf8f 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent_arginfo.h +++ b/src/MongoDB/Monitoring/CommandSucceededEvent_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 86e4fd7aeffe8b4d03c32f4221450d80b3f322a9 */ + * Stub hash: c29b3eb0f340867cc1707b29e935f42fdbc0f031 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent___construct, 0, 0, 0) ZEND_END_ARG_INFO() @@ -12,8 +12,12 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getDurationMicros, 0, 0, IS_LONG, 0) ZEND_END_ARG_INFO() +#define arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getHost arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getCommandName + #define arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getOperationId arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getCommandName +#define arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getPort arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getDurationMicros + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getReply, 0, 0, IS_OBJECT, 0) ZEND_END_ARG_INFO() @@ -33,7 +37,9 @@ static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, __construct) static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getCommandName); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDatabaseName); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDurationMicros); +static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getHost); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationId); +static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getPort); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getRequestId); static ZEND_METHOD(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer); @@ -46,10 +52,12 @@ static const zend_function_entry class_MongoDB_Driver_Monitoring_CommandSucceede ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getCommandName, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getCommandName, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDatabaseName, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getDatabaseName, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getDurationMicros, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getDurationMicros, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getHost, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getHost, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getOperationId, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getOperationId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getPort, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getPort, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getReply, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getReply, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getRequestId, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getRequestId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) - ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) + ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServer, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getServer, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL|ZEND_ACC_DEPRECATED) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServiceId, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getServiceId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_ME(MongoDB_Driver_Monitoring_CommandSucceededEvent, getServerConnectionId, arginfo_class_MongoDB_Driver_Monitoring_CommandSucceededEvent_getServerConnectionId, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL) ZEND_FE_END diff --git a/src/phongo_apm.c b/src/phongo_apm.c index b0c3d1a6c..0f622d002 100644 --- a/src/phongo_apm.c +++ b/src/phongo_apm.c @@ -143,6 +143,8 @@ static void phongo_apm_command_started(const mongoc_apm_command_started_t* event object_init_ex(&z_event, php_phongo_commandstartedevent_ce); p_event = Z_COMMANDSTARTEDEVENT_OBJ_P(&z_event); + memcpy(&p_event->host, mongoc_apm_command_started_get_host(event), sizeof(mongoc_host_list_t)); + p_event->command_name = estrdup(mongoc_apm_command_started_get_command_name(event)); p_event->database_name = estrdup(mongoc_apm_command_started_get_database_name(event)); p_event->server_id = mongoc_apm_command_started_get_server_id(event); @@ -189,6 +191,8 @@ static void phongo_apm_command_succeeded(const mongoc_apm_command_succeeded_t* e object_init_ex(&z_event, php_phongo_commandsucceededevent_ce); p_event = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(&z_event); + memcpy(&p_event->host, mongoc_apm_command_succeeded_get_host(event), sizeof(mongoc_host_list_t)); + p_event->command_name = estrdup(mongoc_apm_command_succeeded_get_command_name(event)); p_event->database_name = estrdup(mongoc_apm_command_succeeded_get_database_name(event)); p_event->server_id = mongoc_apm_command_succeeded_get_server_id(event); @@ -237,6 +241,8 @@ static void phongo_apm_command_failed(const mongoc_apm_command_failed_t* event) object_init_ex(&z_event, php_phongo_commandfailedevent_ce); p_event = Z_COMMANDFAILEDEVENT_OBJ_P(&z_event); + memcpy(&p_event->host, mongoc_apm_command_failed_get_host(event), sizeof(mongoc_host_list_t)); + p_event->command_name = estrdup(mongoc_apm_command_failed_get_command_name(event)); p_event->database_name = estrdup(mongoc_apm_command_failed_get_database_name(event)); p_event->server_id = mongoc_apm_command_failed_get_server_id(event); diff --git a/src/phongo_structs.h b/src/phongo_structs.h index 3c0979438..488e192db 100644 --- a/src/phongo_structs.h +++ b/src/phongo_structs.h @@ -281,48 +281,51 @@ typedef struct { } php_phongo_utcdatetime_t; typedef struct { - zval manager; - char* command_name; - char* database_name; - uint32_t server_id; - int64_t operation_id; - int64_t request_id; - int64_t duration_micros; - bson_t* reply; - zval z_error; - bool has_service_id; - bson_oid_t service_id; - int64_t server_connection_id; - zend_object std; + zval manager; + char* command_name; + char* database_name; + uint32_t server_id; + int64_t operation_id; + int64_t request_id; + int64_t duration_micros; + bson_t* reply; + zval z_error; + bool has_service_id; + bson_oid_t service_id; + int64_t server_connection_id; + mongoc_host_list_t host; + zend_object std; } php_phongo_commandfailedevent_t; typedef struct { - zval manager; - char* command_name; - char* database_name; - uint32_t server_id; - int64_t operation_id; - int64_t request_id; - bson_t* command; - bool has_service_id; - bson_oid_t service_id; - int64_t server_connection_id; - zend_object std; + zval manager; + char* command_name; + char* database_name; + uint32_t server_id; + int64_t operation_id; + int64_t request_id; + bson_t* command; + bool has_service_id; + bson_oid_t service_id; + int64_t server_connection_id; + mongoc_host_list_t host; + zend_object std; } php_phongo_commandstartedevent_t; typedef struct { - zval manager; - char* command_name; - char* database_name; - uint32_t server_id; - int64_t operation_id; - int64_t request_id; - int64_t duration_micros; - bson_t* reply; - bool has_service_id; - bson_oid_t service_id; - int64_t server_connection_id; - zend_object std; + zval manager; + char* command_name; + char* database_name; + uint32_t server_id; + int64_t operation_id; + int64_t request_id; + int64_t duration_micros; + bson_t* reply; + bool has_service_id; + bson_oid_t service_id; + int64_t server_connection_id; + mongoc_host_list_t host; + zend_object std; } php_phongo_commandsucceededevent_t; typedef struct { diff --git a/tests/apm/commandFailedEvent-001.phpt b/tests/apm/commandFailedEvent-001.phpt index 14b409a9b..ac09b30f4 100644 --- a/tests/apm/commandFailedEvent-001.phpt +++ b/tests/apm/commandFailedEvent-001.phpt @@ -31,10 +31,11 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber var_dump($event->getDurationMicros()); echo "getDurationMicros() returns > 0: ", $event->getDurationMicros() > 0 ? 'yes' : 'no', "\n"; var_dump($event->getError() instanceof MongoDB\Driver\Exception\Exception); + var_dump($event->getHost()); var_dump($event->getOperationId()); + var_dump($event->getPort()); var_dump($event->getReply()); var_dump($event->getRequestId()); - var_dump($event->getServer()); /* Note: getServerConnectionId() and getServiceId() have more stringent * requirements and are tested separately. */ @@ -60,11 +61,10 @@ string(5) "admin" int(%d) getDurationMicros() returns > 0: yes bool(true) +string(%d) "%s" string(%d) "%d" +int(%d) object(stdClass)#%d (%d) { %A } string(%d) "%d" -object(MongoDB\Driver\Server)#%d (%d) { - %A -} diff --git a/tests/apm/commandFailedEvent-debug-001.phpt b/tests/apm/commandFailedEvent-debug-001.phpt index ba8383b3b..a1647d352 100644 --- a/tests/apm/commandFailedEvent-debug-001.phpt +++ b/tests/apm/commandFailedEvent-debug-001.phpt @@ -42,6 +42,10 @@ throws(function() use ($manager, $command) { --EXPECTF-- object(MongoDB\Driver\Monitoring\CommandFailedEvent)#%d (%d) { + ["host"]=> + string(%d) "%s" + ["port"]=> + int(%d) ["commandName"]=> string(9) "aggregate" ["durationMicros"]=> @@ -49,11 +53,11 @@ object(MongoDB\Driver\Monitoring\CommandFailedEvent)#%d (%d) { ["error"]=> object(MongoDB\Driver\Exception\ServerException)#%d (%d) {%A } - ["operationId"]=> - string(%d) "%d" ["reply"]=> object(stdClass)#%d (%d) {%A } + ["operationId"]=> + string(%d) "%d" ["requestId"]=> string(%d) "%d" ["server"]=> diff --git a/tests/apm/commandFailedEvent-getServer-001.phpt b/tests/apm/commandFailedEvent-getServer-001.phpt new file mode 100644 index 000000000..bd7fc0906 --- /dev/null +++ b/tests/apm/commandFailedEvent-getServer-001.phpt @@ -0,0 +1,44 @@ +--TEST-- +MongoDB\Driver\Monitoring\CommandFailedEvent::getServer() +--SKIPIF-- + + + +--FILE-- +getServer()); + } +} + +$manager = create_test_manager(); + +$subscriber = new MySubscriber(); +MongoDB\Driver\Monitoring\addSubscriber($subscriber); + +$command = new MongoDB\Driver\Command(['unsupportedCommand' => 1]); + +try { + $manager->executeCommand('admin', $command); +} catch (Exception $e) { +} + +?> +--EXPECTF-- +Deprecated: %r(Function|Method)%r MongoDB\Driver\Monitoring\CommandFailedEvent::getServer() is deprecated in %s +object(MongoDB\Driver\Server)#%d (%d) { + %A +} diff --git a/tests/apm/commandStartedEvent-001.phpt b/tests/apm/commandStartedEvent-001.phpt index 4c240cbe5..972685341 100644 --- a/tests/apm/commandStartedEvent-001.phpt +++ b/tests/apm/commandStartedEvent-001.phpt @@ -15,9 +15,10 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber var_dump($event->getCommand()); var_dump($event->getCommandName()); var_dump($event->getDatabaseName()); + var_dump($event->getHost()); var_dump($event->getOperationId()); + var_dump($event->getPort()); var_dump($event->getRequestId()); - var_dump($event->getServer()); /* Note: getServerConnectionId() and getServiceId() have more stringent * requirements and are tested separately. */ @@ -47,8 +48,7 @@ object(stdClass)#%d (%d) { } string(4) "ping" string(5) "admin" +string(%d) "%s" string(%d) "%d" +int(%d) string(%d) "%d" -object(MongoDB\Driver\Server)#%d (%d) { - %A -} diff --git a/tests/apm/commandStartedEvent-debug-001.phpt b/tests/apm/commandStartedEvent-debug-001.phpt index b9b090554..3923f030b 100644 --- a/tests/apm/commandStartedEvent-debug-001.phpt +++ b/tests/apm/commandStartedEvent-debug-001.phpt @@ -33,13 +33,17 @@ $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1] --EXPECTF-- object(MongoDB\Driver\Monitoring\CommandStartedEvent)#%d (%d) { - ["command"]=> - object(stdClass)#%d (%d) {%A - } + ["host"]=> + string(%d) "%s" + ["port"]=> + int(%d) ["commandName"]=> string(4) "ping" ["databaseName"]=> string(%d) "%s" + ["command"]=> + object(stdClass)#%d (%d) {%A + } ["operationId"]=> string(%d) "%d" ["requestId"]=> diff --git a/tests/apm/commandStartedEvent-getServer-001.phpt b/tests/apm/commandStartedEvent-getServer-001.phpt new file mode 100644 index 000000000..73e0c82b6 --- /dev/null +++ b/tests/apm/commandStartedEvent-getServer-001.phpt @@ -0,0 +1,40 @@ +--TEST-- +MongoDB\Driver\Monitoring\CommandStartedEvent::getServer() +--SKIPIF-- + + + +--FILE-- +getServer()); + } + + public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event): void + { + } + + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void + { + } +} + +$manager = create_test_manager(); + +$subscriber = new MySubscriber(); +MongoDB\Driver\Monitoring\addSubscriber($subscriber); + +$command = new MongoDB\Driver\Command(['ping' => 1]); +$manager->executeCommand('admin', $command); + +?> +--EXPECTF-- +Deprecated: %r(Function|Method)%r MongoDB\Driver\Monitoring\CommandStartedEvent::getServer() is deprecated in %s +object(MongoDB\Driver\Server)#%d (%d) { + %A +} diff --git a/tests/apm/commandSucceededEvent-001.phpt b/tests/apm/commandSucceededEvent-001.phpt index c502dac4d..988dc5b41 100644 --- a/tests/apm/commandSucceededEvent-001.phpt +++ b/tests/apm/commandSucceededEvent-001.phpt @@ -28,10 +28,11 @@ class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber var_dump($event->getDatabaseName()); var_dump($event->getDurationMicros()); echo "getDurationMicros() returns > 0: ", $event->getDurationMicros() > 0 ? 'yes' : 'no', "\n"; + var_dump($event->getHost()); var_dump($event->getOperationId()); + var_dump($event->getPort()); var_dump($event->getReply()); var_dump($event->getRequestId()); - var_dump($event->getServer()); /* Note: getServerConnectionId() and getServiceId() have more stringent * requirements and are tested separately. */ @@ -56,11 +57,10 @@ string(4) "ping" string(5) "admin" int(%d) getDurationMicros() returns > 0: yes +string(%d) "%s" string(%d) "%d" +int(%d) object(stdClass)#%d (%d) { %A } string(%d) "%d" -object(MongoDB\Driver\Server)#%d (%d) { - %A -} diff --git a/tests/apm/commandSucceededEvent-debug-001.phpt b/tests/apm/commandSucceededEvent-debug-001.phpt index 361d2be23..696a76b52 100644 --- a/tests/apm/commandSucceededEvent-debug-001.phpt +++ b/tests/apm/commandSucceededEvent-debug-001.phpt @@ -33,15 +33,19 @@ $manager->executeCommand(DATABASE_NAME, new MongoDB\Driver\Command(['ping' => 1] --EXPECTF-- object(MongoDB\Driver\Monitoring\CommandSucceededEvent)#%d (%d) { + ["host"]=> + string(%d) "%s" + ["port"]=> + int(%d) ["commandName"]=> string(4) "ping" ["durationMicros"]=> int(%d) - ["operationId"]=> - string(%d) "%d" ["reply"]=> object(stdClass)#%d (%d) {%A } + ["operationId"]=> + string(%d) "%d" ["requestId"]=> string(%d) "%d" ["server"]=> diff --git a/tests/apm/commandSucceededEvent-getServer-001.phpt b/tests/apm/commandSucceededEvent-getServer-001.phpt new file mode 100644 index 000000000..a1b0115b9 --- /dev/null +++ b/tests/apm/commandSucceededEvent-getServer-001.phpt @@ -0,0 +1,42 @@ +--TEST-- +MongoDB\Driver\Monitoring\CommandSucceededEvent::getServer() +--SKIPIF-- + + + +--FILE-- +getServer()); + } + + public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event): void + { + } +} + +$manager = create_test_manager(); + +$subscriber = new MySubscriber(); +MongoDB\Driver\Monitoring\addSubscriber($subscriber); + +$command = new MongoDB\Driver\Command(['ping' => 1]); +$manager->executeCommand('admin', $command); + +?> +--EXPECTF-- +Deprecated: %r(Function|Method)%r MongoDB\Driver\Monitoring\CommandSucceededEvent::getServer() is deprecated in %s +object(MongoDB\Driver\Server)#%d (%d) { + %A +}