Skip to content

Commit 1869a72

Browse files
authored
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
1 parent c394d37 commit 1869a72

20 files changed

+320
-118
lines changed

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandfailedevent_ce;
3131

3232
PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandFailedEvent)
3333

34-
/* Returns the command name for this event */
3534
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
3635
{
3736
php_phongo_commandfailedevent_t* intern;
@@ -43,7 +42,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getCommandName)
4342
RETVAL_STRING(intern->command_name);
4443
}
4544

46-
/* Returns the database name for this event */
4745
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName)
4846
{
4947
php_phongo_commandfailedevent_t* intern;
@@ -55,7 +53,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDatabaseName)
5553
RETVAL_STRING(intern->database_name);
5654
}
5755

58-
/* Returns the event's duration in microseconds */
5956
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicros)
6057
{
6158
php_phongo_commandfailedevent_t* intern;
@@ -67,7 +64,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getDurationMicro
6764
RETURN_LONG(intern->duration_micros);
6865
}
6966

70-
/* Returns the error document associated with the event */
7167
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
7268
{
7369
php_phongo_commandfailedevent_t* intern;
@@ -79,7 +75,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getError)
7975
RETURN_ZVAL(&intern->z_error, 1, 0);
8076
}
8177

82-
/* Returns the event's operation ID */
78+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getHost)
79+
{
80+
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
81+
82+
PHONGO_PARSE_PARAMETERS_NONE();
83+
84+
RETVAL_STRING(intern->host.host);
85+
}
86+
8387
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
8488
{
8589
php_phongo_commandfailedevent_t* intern;
@@ -93,7 +97,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getOperationId)
9397
RETVAL_STRING(operation_id);
9498
}
9599

96-
/* Returns the reply document associated with the event */
100+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getPort)
101+
{
102+
php_phongo_commandfailedevent_t* intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis());
103+
104+
PHONGO_PARSE_PARAMETERS_NONE();
105+
106+
RETVAL_LONG(intern->host.port);
107+
}
108+
97109
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
98110
{
99111
php_phongo_commandfailedevent_t* intern;
@@ -113,7 +125,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getReply)
113125
RETURN_ZVAL(&state.zchild, 0, 1);
114126
}
115127

116-
/* Returns the event's request ID */
117128
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
118129
{
119130
php_phongo_commandfailedevent_t* intern;
@@ -127,7 +138,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getRequestId)
127138
RETVAL_STRING(request_id);
128139
}
129140

130-
/* Returns the Server from which the event originated */
131141
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
132142
{
133143
php_phongo_commandfailedevent_t* intern;
@@ -139,7 +149,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandFailedEvent, getServer)
139149
phongo_server_init(return_value, &intern->manager, intern->server_id);
140150
}
141151

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

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

177-
/**
178-
* Event thrown when a command has failed to execute.
179-
*
180-
* This class is only constructed internally.
181-
*/
182-
183185
/* MongoDB\Driver\Monitoring\CommandFailedEvent object handlers */
184186
static zend_object_handlers php_phongo_handler_commandfailedevent;
185187

@@ -233,24 +235,26 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(phongo_compat_obj
233235

234236
intern = Z_OBJ_COMMANDFAILEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
235237
*is_temp = 1;
236-
array_init_size(&retval, 6);
238+
array_init_size(&retval, 11);
237239

240+
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
241+
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
238242
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
239243
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
240244

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

244-
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
245-
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
246-
247248
if (!php_phongo_bson_to_zval_ex(intern->reply, &reply_state)) {
248249
zval_ptr_dtor(&reply_state.zchild);
249250
goto done;
250251
}
251252

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

255+
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
256+
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
257+
254258
snprintf(request_id, sizeof(request_id), "%" PRId64, intern->request_id);
255259
ADD_ASSOC_STRING(&retval, "requestId", request_id);
256260

src/MongoDB/Monitoring/CommandFailedEvent.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ final public function getDurationMicros(): int {}
1919

2020
final public function getError(): \Exception {}
2121

22+
final public function getHost(): string {}
23+
2224
final public function getOperationId(): string {}
2325

26+
final public function getPort(): int {}
27+
2428
final public function getReply(): object {}
2529

2630
final public function getRequestId(): string {}
2731

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

3035
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}

src/MongoDB/Monitoring/CommandFailedEvent_arginfo.h

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

src/MongoDB/Monitoring/CommandStartedEvent.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ zend_class_entry* php_phongo_commandstartedevent_ce;
3131

3232
PHONGO_DISABLED_CONSTRUCTOR(MongoDB_Driver_Monitoring_CommandStartedEvent)
3333

34-
/* Returns the command document associated with the event */
3534
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand)
3635
{
3736
php_phongo_commandstartedevent_t* intern;
@@ -51,7 +50,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommand)
5150
RETURN_ZVAL(&state.zchild, 0, 1);
5251
}
5352

54-
/* Returns the command name for this event */
5553
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName)
5654
{
5755
php_phongo_commandstartedevent_t* intern;
@@ -63,7 +61,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getCommandName)
6361
RETVAL_STRING(intern->command_name);
6462
}
6563

66-
/* Returns the database name for this event */
6764
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName)
6865
{
6966
php_phongo_commandstartedevent_t* intern;
@@ -75,7 +72,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getDatabaseName
7572
RETVAL_STRING(intern->database_name);
7673
}
7774

78-
/* Returns the event's operation ID */
75+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getHost)
76+
{
77+
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
78+
79+
PHONGO_PARSE_PARAMETERS_NONE();
80+
81+
RETVAL_STRING(intern->host.host);
82+
}
83+
7984
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
8085
{
8186
php_phongo_commandstartedevent_t* intern;
@@ -89,7 +94,15 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getOperationId)
8994
RETVAL_STRING(operation_id);
9095
}
9196

92-
/* Returns the event's request ID */
97+
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getPort)
98+
{
99+
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
100+
101+
PHONGO_PARSE_PARAMETERS_NONE();
102+
103+
RETVAL_LONG(intern->host.port);
104+
}
105+
93106
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
94107
{
95108
php_phongo_commandstartedevent_t* intern;
@@ -103,7 +116,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getRequestId)
103116
RETVAL_STRING(request_id);
104117
}
105118

106-
/* Returns the Server from which the event originated */
107119
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer)
108120
{
109121
php_phongo_commandstartedevent_t* intern;
@@ -115,7 +127,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServer)
115127
phongo_server_init(return_value, &intern->manager, intern->server_id);
116128
}
117129

118-
/* Returns the event's service ID */
119130
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId)
120131
{
121132
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
@@ -129,7 +140,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServiceId)
129140
phongo_objectid_new(return_value, &intern->service_id);
130141
}
131142

132-
/* Returns the event's server connection ID */
133143
static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnectionId)
134144
{
135145
php_phongo_commandstartedevent_t* intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis());
@@ -150,12 +160,6 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_CommandStartedEvent, getServerConnec
150160
RETURN_LONG(intern->server_connection_id);
151161
}
152162

153-
/**
154-
* Event thrown when a command has started to execute.
155-
*
156-
* This class is only constructed internally.
157-
*/
158-
159163
/* MongoDB\Driver\Monitoring\CommandStartedEvent object handlers */
160164
static zend_object_handlers php_phongo_handler_commandstartedevent;
161165

@@ -205,7 +209,12 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob
205209

206210
intern = Z_OBJ_COMMANDSTARTEDEVENT(PHONGO_COMPAT_GET_OBJ(object));
207211
*is_temp = 1;
208-
array_init_size(&retval, 6);
212+
array_init_size(&retval, 10);
213+
214+
ADD_ASSOC_STRING(&retval, "host", intern->host.host);
215+
ADD_ASSOC_LONG_EX(&retval, "port", intern->host.port);
216+
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
217+
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);
209218

210219
if (!php_phongo_bson_to_zval_ex(intern->command, &command_state)) {
211220
zval_ptr_dtor(&command_state.zchild);
@@ -214,9 +223,6 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(phongo_compat_ob
214223

215224
ADD_ASSOC_ZVAL(&retval, "command", &command_state.zchild);
216225

217-
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
218-
ADD_ASSOC_STRING(&retval, "databaseName", intern->database_name);
219-
220226
snprintf(operation_id, sizeof(operation_id), "%" PRId64, intern->operation_id);
221227
ADD_ASSOC_STRING(&retval, "operationId", operation_id);
222228

src/MongoDB/Monitoring/CommandStartedEvent.stub.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ final public function getCommandName(): string {}
1717

1818
final public function getDatabaseName(): string {}
1919

20+
final public function getHost(): string {}
21+
2022
final public function getOperationId(): string {}
2123

24+
final public function getPort(): int {}
25+
2226
final public function getRequestId(): string {}
2327

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

2631
final public function getServiceId(): ?\MongoDB\BSON\ObjectId {}

src/MongoDB/Monitoring/CommandStartedEvent_arginfo.h

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

0 commit comments

Comments
 (0)