Skip to content

Commit e4e7974

Browse files
committed
PHPC-1925: Change ServerDescription::getType() to return a string
1 parent bcd2a7f commit e4e7974

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

src/MongoDB/ServerDescription.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828

2929
zend_class_entry* php_phongo_serverdescription_ce;
3030

31+
#define PHONGO_SERVER_UNKNOWN "Unknown"
32+
#define PHONGO_SERVER_STANDALONE "Standalone"
33+
#define PHONGO_SERVER_MONGOS "Mongos"
34+
#define PHONGO_SERVER_POSSIBLE_PRIMARY "PossiblePrimary"
35+
#define PHONGO_SERVER_RS_PRIMARY "RSPrimary"
36+
#define PHONGO_SERVER_RS_SECONDARY "RSSecondary"
37+
#define PHONGO_SERVER_RS_ARBITER "RSArbiter"
38+
#define PHONGO_SERVER_RS_OTHER "RSOther"
39+
#define PHONGO_SERVER_RS_GHOST "RSGhost"
40+
3141
/* {{{ proto array MongoDB\Driver\ServerDescription::getHelloResponse()
3242
Returns the most recent "hello" response */
3343
static PHP_METHOD(ServerDescription, getHelloResponse)
@@ -105,7 +115,7 @@ static PHP_METHOD(ServerDescription, getRoundTripTime)
105115
RETVAL_LONG(mongoc_server_description_round_trip_time(intern->server_description));
106116
} /* }}} */
107117

108-
/* {{{ proto integer MongoDB\Driver\ServerDescription::getType()
118+
/* {{{ proto string MongoDB\Driver\ServerDescription::getType()
109119
Returns the server’s node type */
110120
static PHP_METHOD(ServerDescription, getType)
111121
{
@@ -115,7 +125,7 @@ static PHP_METHOD(ServerDescription, getType)
115125

116126
PHONGO_PARSE_PARAMETERS_NONE();
117127

118-
RETVAL_LONG(php_phongo_server_description_type(intern->server_description));
128+
RETVAL_STRING(mongoc_server_description_type(intern->server_description));
119129
} /* }}} */
120130

121131
/* {{{ MongoDB\Driver\ServerDescription function entries */
@@ -250,15 +260,15 @@ void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) /* {{{ */
250260
php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object;
251261
php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std);
252262

253-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_UNKNOWN"), PHONGO_SERVER_UNKNOWN);
254-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_STANDALONE"), PHONGO_SERVER_STANDALONE);
255-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_MONGOS"), PHONGO_SERVER_MONGOS);
256-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_POSSIBLE_PRIMARY"), PHONGO_SERVER_POSSIBLE_PRIMARY);
257-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_PRIMARY"), PHONGO_SERVER_RS_PRIMARY);
258-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_SECONDARY"), PHONGO_SERVER_RS_SECONDARY);
259-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_ARBITER"), PHONGO_SERVER_RS_ARBITER);
260-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_OTHER"), PHONGO_SERVER_RS_OTHER);
261-
zend_declare_class_constant_long(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_GHOST"), PHONGO_SERVER_RS_GHOST);
263+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_UNKNOWN"), PHONGO_SERVER_UNKNOWN);
264+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_STANDALONE"), PHONGO_SERVER_STANDALONE);
265+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_MONGOS"), PHONGO_SERVER_MONGOS);
266+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_POSSIBLE_PRIMARY"), PHONGO_SERVER_POSSIBLE_PRIMARY);
267+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_PRIMARY"), PHONGO_SERVER_RS_PRIMARY);
268+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_SECONDARY"), PHONGO_SERVER_RS_SECONDARY);
269+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_ARBITER"), PHONGO_SERVER_RS_ARBITER);
270+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_OTHER"), PHONGO_SERVER_RS_OTHER);
271+
zend_declare_class_constant_string(php_phongo_serverdescription_ce, ZEND_STRL("TYPE_RS_GHOST"), PHONGO_SERVER_RS_GHOST);
262272
} /* }}} */
263273

264274
/*

tests/serverDescription/serverDescription-constants.phpt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ var_dump(MongoDB\Driver\ServerDescription::TYPE_RS_GHOST);
1717
===DONE===
1818
<?php exit(0); ?>
1919
--EXPECT--
20-
int(0)
21-
int(1)
22-
int(2)
23-
int(3)
24-
int(4)
25-
int(5)
26-
int(6)
27-
int(7)
28-
int(8)
20+
string(7) "Unknown"
21+
string(10) "Standalone"
22+
string(6) "Mongos"
23+
string(15) "PossiblePrimary"
24+
string(9) "RSPrimary"
25+
string(11) "RSSecondary"
26+
string(9) "RSArbiter"
27+
string(7) "RSOther"
28+
string(7) "RSGhost"
2929
===DONE===

0 commit comments

Comments
 (0)