@@ -53,28 +53,28 @@ PHP_METHOD(ReadPreference, __construct)
53
53
{
54
54
php_phongo_readpreference_t * intern ;
55
55
zend_error_handling error_handling ;
56
- long readPreference ;
56
+ long mode ;
57
57
zval * tagSets = NULL ;
58
58
(void )return_value_ptr ; (void )return_value ; (void )return_value_used ;
59
59
60
60
61
61
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
62
62
intern = (php_phongo_readpreference_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
63
63
64
- if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "l|a!" , & readPreference , & tagSets ) == FAILURE ) {
64
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "l|a!" , & mode , & tagSets ) == FAILURE ) {
65
65
zend_restore_error_handling (& error_handling TSRMLS_CC );
66
66
return ;
67
67
}
68
68
zend_restore_error_handling (& error_handling TSRMLS_CC );
69
69
70
70
71
- switch (readPreference ) {
71
+ switch (mode ) {
72
72
case MONGOC_READ_PRIMARY :
73
73
case MONGOC_READ_SECONDARY :
74
74
case MONGOC_READ_PRIMARY_PREFERRED :
75
75
case MONGOC_READ_SECONDARY_PREFERRED :
76
76
case MONGOC_READ_NEAREST :
77
- intern -> read_preference = mongoc_read_prefs_new (readPreference );
77
+ intern -> read_preference = mongoc_read_prefs_new (mode );
78
78
79
79
if (tagSets ) {
80
80
bson_t * tags = bson_new ();
@@ -83,31 +83,83 @@ PHP_METHOD(ReadPreference, __construct)
83
83
mongoc_read_prefs_set_tags (intern -> read_preference , tags );
84
84
bson_destroy (tags );
85
85
if (!mongoc_read_prefs_is_valid (intern -> read_preference )) {
86
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s" , " Invalid tagSet " );
86
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Invalid tagSets " );
87
87
return ;
88
88
}
89
89
}
90
90
break ;
91
91
default :
92
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s " , "Invalid ReadPreference" );
92
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Invalid mode: %ld " , mode );
93
93
return ;
94
94
}
95
95
}
96
96
/* }}} */
97
97
98
+ /* {{{ proto string ReadPreference::getMode()
99
+ Returns the ReadPreference mode */
100
+ PHP_METHOD (ReadPreference , getMode )
101
+ {
102
+ php_phongo_readpreference_t * intern ;
103
+ (void )return_value_ptr ; (void )return_value_used ;
104
+
105
+ intern = (php_phongo_readpreference_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
106
+
107
+ if (zend_parse_parameters_none () == FAILURE ) {
108
+ return ;
109
+ }
110
+
111
+ RETURN_LONG (mongoc_read_prefs_get_mode (intern -> read_preference ));
112
+ }
113
+ /* }}} */
114
+
115
+ /* {{{ proto array ReadPreference::getTagSets()
116
+ Returns the ReadPreference tag sets */
117
+ PHP_METHOD (ReadPreference , getTagSets )
118
+ {
119
+ php_phongo_readpreference_t * intern ;
120
+ (void )return_value_ptr ; (void )return_value_used ;
121
+
122
+ intern = (php_phongo_readpreference_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
123
+
124
+ if (zend_parse_parameters_none () == FAILURE ) {
125
+ return ;
126
+ }
127
+
128
+ if (intern -> read_preference -> tags .len ) {
129
+ php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
130
+ /* Use native arrays for debugging output */
131
+ state .map .root_type = PHONGO_TYPEMAP_NATIVE_ARRAY ;
132
+ state .map .document_type = PHONGO_TYPEMAP_NATIVE_ARRAY ;
133
+
134
+ MAKE_STD_ZVAL (state .zchild );
135
+ bson_to_zval (bson_get_data (& intern -> read_preference -> tags ), intern -> read_preference -> tags .len , & state );
136
+ RETURN_ZVAL (state .zchild , 0 , 1 );
137
+ } else {
138
+ RETURN_NULL ();
139
+ }
140
+ }
141
+ /* }}} */
142
+
98
143
/**
99
144
* Value object for read preferences used in issuing commands and queries.
100
145
*/
101
146
/* {{{ MongoDB\Driver\ReadPreference */
102
147
103
148
ZEND_BEGIN_ARG_INFO_EX (ai_ReadPreference___construct , 0 , 0 , 1 )
104
- ZEND_ARG_INFO (0 , readPreference )
149
+ ZEND_ARG_INFO (0 , mode )
105
150
ZEND_ARG_ARRAY_INFO (0 , tagSets , 1 )
106
151
ZEND_END_ARG_INFO ();
107
152
153
+ ZEND_BEGIN_ARG_INFO_EX (ai_ReadPreference_getMode , 0 , 0 , 0 )
154
+ ZEND_END_ARG_INFO ();
155
+
156
+ ZEND_BEGIN_ARG_INFO_EX (ai_ReadPreference_getTagSets , 0 , 0 , 0 )
157
+ ZEND_END_ARG_INFO ();
108
158
109
159
static zend_function_entry php_phongo_readpreference_me [] = {
110
160
PHP_ME (ReadPreference , __construct , ai_ReadPreference___construct , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
161
+ PHP_ME (ReadPreference , getMode , ai_ReadPreference_getMode , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
162
+ PHP_ME (ReadPreference , getTagSets , ai_ReadPreference_getTagSets , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
111
163
PHP_FE_END
112
164
};
113
165
0 commit comments