34
34
35
35
zend_class_entry * php_phongo_readpreference_ce ;
36
36
37
+ #define PHONGO_READ_PRIMARY "primary"
38
+ #define PHONGO_READ_PRIMARY_PREFERRED "primaryPreferred"
39
+ #define PHONGO_READ_SECONDARY "secondary"
40
+ #define PHONGO_READ_SECONDARY_PREFERRED "secondaryPreferred"
41
+ #define PHONGO_READ_NEAREST "nearest"
42
+
37
43
/* Initialize the object from a HashTable and return whether it was successful.
38
44
* An exception will be thrown on error. */
39
45
static bool php_phongo_readpreference_init_from_hash (php_phongo_readpreference_t * intern , HashTable * props TSRMLS_DC ) /* {{{ */
@@ -42,15 +48,15 @@ static bool php_phongo_readpreference_init_from_hash(php_phongo_readpreference_t
42
48
zval * mode , * tagSets , * maxStalenessSeconds ;
43
49
44
50
if ((mode = zend_hash_str_find (props , "mode" , sizeof ("mode" ) - 1 )) && Z_TYPE_P (mode ) == IS_STRING ) {
45
- if (strcasecmp (Z_STRVAL_P (mode ), "primary" ) == 0 ) {
51
+ if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_PRIMARY ) == 0 ) {
46
52
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_PRIMARY );
47
- } else if (strcasecmp (Z_STRVAL_P (mode ), "primaryPreferred" ) == 0 ) {
53
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_PRIMARY_PREFERRED ) == 0 ) {
48
54
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_PRIMARY_PREFERRED );
49
- } else if (strcasecmp (Z_STRVAL_P (mode ), "secondary" ) == 0 ) {
55
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_SECONDARY ) == 0 ) {
50
56
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_SECONDARY );
51
- } else if (strcasecmp (Z_STRVAL_P (mode ), "secondaryPreferred" ) == 0 ) {
57
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_SECONDARY_PREFERRED ) == 0 ) {
52
58
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_SECONDARY_PREFERRED );
53
- } else if (strcasecmp (Z_STRVAL_P (mode ), "nearest" ) == 0 ) {
59
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_NEAREST ) == 0 ) {
54
60
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_NEAREST );
55
61
} else {
56
62
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires specific values for \"mode\" string field" , ZSTR_VAL (php_phongo_readpreference_ce -> name ));
@@ -113,15 +119,15 @@ static bool php_phongo_readpreference_init_from_hash(php_phongo_readpreference_t
113
119
zval * * mode , * * tagSets , * * maxStalenessSeconds ;
114
120
115
121
if (zend_hash_find (props , "mode" , sizeof ("mode" ), (void * * ) & mode ) == SUCCESS && Z_TYPE_PP (mode ) == IS_STRING ) {
116
- if (strcasecmp (Z_STRVAL_PP (mode ), "primary" ) == 0 ) {
122
+ if (strcasecmp (Z_STRVAL_PP (mode ), PHONGO_READ_PRIMARY ) == 0 ) {
117
123
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_PRIMARY );
118
- } else if (strcasecmp (Z_STRVAL_PP (mode ), "primaryPreferred" ) == 0 ) {
124
+ } else if (strcasecmp (Z_STRVAL_PP (mode ), PHONGO_READ_PRIMARY_PREFERRED ) == 0 ) {
119
125
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_PRIMARY_PREFERRED );
120
- } else if (strcasecmp (Z_STRVAL_PP (mode ), "secondary" ) == 0 ) {
126
+ } else if (strcasecmp (Z_STRVAL_PP (mode ), PHONGO_READ_SECONDARY ) == 0 ) {
121
127
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_SECONDARY );
122
- } else if (strcasecmp (Z_STRVAL_PP (mode ), "secondaryPreferred" ) == 0 ) {
128
+ } else if (strcasecmp (Z_STRVAL_PP (mode ), PHONGO_READ_SECONDARY_PREFERRED ) == 0 ) {
123
129
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_SECONDARY_PREFERRED );
124
- } else if (strcasecmp (Z_STRVAL_PP (mode ), "nearest" ) == 0 ) {
130
+ } else if (strcasecmp (Z_STRVAL_PP (mode ), PHONGO_READ_NEAREST ) == 0 ) {
125
131
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_NEAREST );
126
132
} else {
127
133
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires specific values for \"mode\" string field" , ZSTR_VAL (php_phongo_readpreference_ce -> name ));
@@ -225,15 +231,15 @@ static PHP_METHOD(ReadPreference, __construct)
225
231
return ;
226
232
}
227
233
} else if (Z_TYPE_P (mode ) == IS_STRING ) {
228
- if (strcasecmp (Z_STRVAL_P (mode ), "primary" ) == 0 ) {
234
+ if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_PRIMARY ) == 0 ) {
229
235
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_PRIMARY );
230
- } else if (strcasecmp (Z_STRVAL_P (mode ), "primaryPreferred" ) == 0 ) {
236
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_PRIMARY_PREFERRED ) == 0 ) {
231
237
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_PRIMARY_PREFERRED );
232
- } else if (strcasecmp (Z_STRVAL_P (mode ), "secondary" ) == 0 ) {
238
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_SECONDARY ) == 0 ) {
233
239
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_SECONDARY );
234
- } else if (strcasecmp (Z_STRVAL_P (mode ), "secondaryPreferred" ) == 0 ) {
240
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_SECONDARY_PREFERRED ) == 0 ) {
235
241
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_SECONDARY_PREFERRED );
236
- } else if (strcasecmp (Z_STRVAL_P (mode ), "nearest" ) == 0 ) {
242
+ } else if (strcasecmp (Z_STRVAL_P (mode ), PHONGO_READ_NEAREST ) == 0 ) {
237
243
intern -> read_preference = mongoc_read_prefs_new (MONGOC_READ_NEAREST );
238
244
} else {
239
245
phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Invalid mode: '%s'" , Z_STRVAL_P (mode ));
@@ -382,15 +388,15 @@ static const char* php_phongo_readpreference_get_mode_string(mongoc_read_mode_t
382
388
{
383
389
switch (mode ) {
384
390
case MONGOC_READ_PRIMARY :
385
- return "primary" ;
391
+ return PHONGO_READ_PRIMARY ;
386
392
case MONGOC_READ_PRIMARY_PREFERRED :
387
- return "primaryPreferred" ;
393
+ return PHONGO_READ_PRIMARY_PREFERRED ;
388
394
case MONGOC_READ_SECONDARY :
389
- return "secondary" ;
395
+ return PHONGO_READ_SECONDARY ;
390
396
case MONGOC_READ_SECONDARY_PREFERRED :
391
- return "secondaryPreferred" ;
397
+ return PHONGO_READ_SECONDARY_PREFERRED ;
392
398
case MONGOC_READ_NEAREST :
393
- return "nearest" ;
399
+ return PHONGO_READ_NEAREST ;
394
400
default : /* Do nothing */
395
401
break ;
396
402
}
0 commit comments