Skip to content

Commit e3d105a

Browse files
authored
PHPC-1925: Change ServerDescription::getType() to return a string (#1249)
1 parent 7e0e2e1 commit e3d105a

File tree

6 files changed

+37
-27
lines changed

6 files changed

+37
-27
lines changed

src/MongoDB/ServerDescription.c

Lines changed: 22 additions & 12 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 */
@@ -192,7 +202,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(phongo_compat_object
192202
ZVAL_LONG(&port, host_list->port);
193203
zend_hash_str_update(props, "port", sizeof("port") - 1, &port);
194204

195-
ZVAL_LONG(&type, php_phongo_server_description_type(intern->server_description));
205+
ZVAL_STRING(&type, mongoc_server_description_type(intern->server_description));
196206
zend_hash_str_update(props, "type", sizeof("type") - 1, &type);
197207
}
198208

@@ -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/server/server-getServerDescription-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object(MongoDB\Driver\ServerDescription)#%d (%d) {
2121
["port"]=>
2222
int(%d)
2323
["type"]=>
24-
int(%d)
24+
string(%d) "%r(Standalone|Mongos|RSPrimary)%r"
2525
["hello_response"]=>
2626
array(%d) {
2727
%a

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===

tests/serverDescription/serverDescription-debug-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object(MongoDB\Driver\ServerDescription)#%d (%d) {
2222
["port"]=>
2323
int(%d)
2424
["type"]=>
25-
int(%d)
25+
string(%d) "%r(Standalone|Mongos|RSPrimary)%r"
2626
["hello_response"]=>
2727
array(%d) {
2828
%a

tests/serverDescription/serverDescription-getType-001.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ $manager = create_test_manager();
1717
$server = $manager->selectServer(new MongoDB\Driver\ReadPreference('primary'));
1818
$type = $server->getServerDescription()->getType();
1919

20-
var_dump(in_array($type, $expected_types));
20+
var_dump($type);
2121

2222
?>
2323
===DONE===
2424
<?php exit(0); ?>
25-
--EXPECT--
26-
bool(true)
25+
--EXPECTF--
26+
string(%d) "%r(Standalone|Mongos|RSPrimary)%r"
2727
===DONE===

tests/serverDescription/serverDescription-var_export-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ echo var_export($server->getServerDescription(), true), "\n";
2020
MongoDB\Driver\ServerDescription::__set_state(array(
2121
'host' => '%s',
2222
'port' => %d,
23-
'type' => %d,
23+
'type' => '%r(Standalone|Mongos|RSPrimary)%r',
2424
'hello_response' =>
2525
array (
2626
%a

0 commit comments

Comments
 (0)