Skip to content

Commit 8c22f43

Browse files
committed
Add properties to TopologyOpeningEvent class
1 parent 4b2a031 commit 8c22f43

7 files changed

Lines changed: 40 additions & 39 deletions

File tree

src/MongoDB/Monitoring/TopologyClosedEvent_arginfo.h

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

src/MongoDB/Monitoring/TopologyOpeningEvent.c

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ static PHP_METHOD(MongoDB_Driver_Monitoring_TopologyOpeningEvent, getTopologyId)
3737
phongo_objectid_new(return_value, &intern->topology_id);
3838
}
3939

40+
static void phongo_topologyopeningevent_update_properties(phongo_topologyopeningevent_t* intern)
41+
{
42+
zval topology_id;
43+
44+
if (phongo_objectid_new(&topology_id, &intern->topology_id)) {
45+
zend_update_property(phongo_topologyopeningevent_ce, &intern->std, ZEND_STRL("topologyId"), &topology_id);
46+
zval_ptr_dtor(&topology_id);
47+
}
48+
}
49+
4050
/* MongoDB\Driver\Monitoring\TopologyOpeningEvent object handlers */
4151
static zend_object_handlers phongo_handler_topologyopeningevent;
4252

@@ -56,37 +66,21 @@ static zend_object* phongo_topologyopeningevent_create_object(zend_class_entry*
5666
return &intern->std;
5767
}
5868

59-
static HashTable* phongo_topologyopeningevent_get_debug_info(zend_object* object, int* is_temp)
60-
{
61-
PHONGO_INTERN_FROM_Z_OBJ(topologyopeningevent, object);
62-
63-
zval retval = ZVAL_STATIC_INIT;
64-
65-
*is_temp = 1;
66-
array_init_size(&retval, 1);
67-
68-
{
69-
zval topology_id;
70-
71-
if (!phongo_objectid_new(&topology_id, &intern->topology_id)) {
72-
/* Exception should already have been thrown */
73-
goto done;
74-
}
75-
76-
ADD_ASSOC_ZVAL_EX(&retval, "topologyId", &topology_id);
77-
}
78-
79-
done:
80-
return Z_ARRVAL(retval);
81-
}
82-
8369
void phongo_topologyopeningevent_init_ce(INIT_FUNC_ARGS)
8470
{
8571
phongo_topologyopeningevent_ce = register_class_MongoDB_Driver_Monitoring_TopologyOpeningEvent();
8672
phongo_topologyopeningevent_ce->create_object = phongo_topologyopeningevent_create_object;
8773

8874
memcpy(&phongo_handler_topologyopeningevent, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
89-
phongo_handler_topologyopeningevent.get_debug_info = phongo_topologyopeningevent_get_debug_info;
90-
phongo_handler_topologyopeningevent.free_obj = phongo_topologyopeningevent_free_object;
91-
phongo_handler_topologyopeningevent.offset = XtOffsetOf(phongo_topologyopeningevent_t, std);
75+
phongo_handler_topologyopeningevent.free_obj = phongo_topologyopeningevent_free_object;
76+
phongo_handler_topologyopeningevent.offset = XtOffsetOf(phongo_topologyopeningevent_t, std);
77+
}
78+
79+
void phongo_topologyopeningevent_init(zval* return_value, const mongoc_apm_topology_opening_t* event)
80+
{
81+
PHONGO_INTERN_INIT_EX(topologyopeningevent, return_value);
82+
83+
mongoc_apm_topology_opening_get_topology_id(event, &intern->topology_id);
84+
85+
phongo_topologyopeningevent_update_properties(intern);
9286
}

src/MongoDB/Monitoring/TopologyOpeningEvent.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
/** @not-serializable */
1111
final class TopologyOpeningEvent
1212
{
13+
public readonly \MongoDB\BSON\ObjectId $topologyId;
14+
1315
final private function __construct() {}
1416

1517
final public function getTopologyId(): \MongoDB\BSON\ObjectId {}

src/MongoDB/Monitoring/TopologyOpeningEvent_arginfo.h

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/phongo_apm.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,9 @@ static void phongo_apm_topology_closed(const mongoc_apm_topology_closed_t* event
355355

356356
static void phongo_apm_topology_opening(const mongoc_apm_topology_opening_t* event)
357357
{
358-
mongoc_client_t* client;
359-
HashTable* subscribers;
360-
phongo_topologyopeningevent_t* p_event;
361-
zval z_event;
358+
mongoc_client_t* client;
359+
HashTable* subscribers;
360+
zval z_event;
362361

363362
client = mongoc_apm_topology_opening_get_context(event);
364363
subscribers = phongo_apm_get_subscribers_to_notify(phongo_sdamsubscriber_ce, client);
@@ -368,11 +367,7 @@ static void phongo_apm_topology_opening(const mongoc_apm_topology_opening_t* eve
368367
goto cleanup;
369368
}
370369

371-
object_init_ex(&z_event, phongo_topologyopeningevent_ce);
372-
p_event = Z_TOPOLOGYOPENINGEVENT_OBJ_P(&z_event);
373-
374-
mongoc_apm_topology_opening_get_topology_id(event, &p_event->topology_id);
375-
370+
phongo_topologyopeningevent_init(&z_event, event);
376371
phongo_apm_dispatch_event(subscribers, "topologyOpening", &z_event);
377372
zval_ptr_dtor(&z_event);
378373

src/phongo_apm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ void phongo_serverheartbeatsucceededevent_init(zval* return_value, const mongoc_
3636
void phongo_serveropeningevent_init(zval* return_value, const mongoc_apm_server_opening_t* event);
3737
void phongo_topologychangedevent_init(zval* return_value, const mongoc_apm_topology_changed_t* event);
3838
void phongo_topologyclosedevent_init(zval* return_value, const mongoc_apm_topology_closed_t* event);
39+
void phongo_topologyopeningevent_init(zval* return_value, const mongoc_apm_topology_opening_t* event);
3940

4041
#endif /* PHONGO_APM_H */

tests/apm/topologyOpeningEvent-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class MySubscriber implements MongoDB\Driver\Monitoring\SDAMSubscriber
2828
public function topologyOpening(MongoDB\Driver\Monitoring\TopologyOpeningEvent $event): void
2929
{
3030
printf("getTopologyId() returns an ObjectId: %s\n", ($event->getTopologyId() instanceof MongoDB\BSON\ObjectId) ? 'yes' : 'no');
31+
printf("topologyId returns an ObjectId: %s\n", ($event->topologyId instanceof MongoDB\BSON\ObjectId) ? 'yes' : 'no');
3132

3233
var_dump($event);
3334
}
@@ -44,6 +45,7 @@ $m->executeCommand(DATABASE_NAME, $command);
4445
<?php exit(0); ?>
4546
--EXPECTF--
4647
getTopologyId() returns an ObjectId: yes
48+
topologyId returns an ObjectId: yes
4749
object(MongoDB\Driver\Monitoring\TopologyOpeningEvent)#%d (%d) {
4850
["topologyId"]=>
4951
object(MongoDB\BSON\ObjectId)#%d (%d) {

0 commit comments

Comments
 (0)