42
42
#include "php_bson.h"
43
43
44
44
45
- PHONGO_API zend_class_entry * php_phongo_commandresult_ce ;
45
+ PHONGO_API zend_class_entry * php_phongo_result_ce ;
46
46
47
- zend_object_handlers php_phongo_handler_commandresult ;
47
+ zend_object_handlers php_phongo_handler_result ;
48
48
49
- /* {{{ proto MongoDB\Driver\CommandResult CommandResult ::__construct(MongoDB\Driver\Server $server, array|object $responseDocument)
50
- Constructs a new CommandResult */
51
- PHP_METHOD (CommandResult , __construct )
49
+ /* {{{ proto MongoDB\Driver\Result Result ::__construct(MongoDB\Driver\Server $server, array|object $responseDocument)
50
+ Constructs a new Result */
51
+ PHP_METHOD (Result , __construct )
52
52
{
53
- php_phongo_commandresult_t * intern ;
53
+ php_phongo_result_t * intern ;
54
54
zend_error_handling error_handling ;
55
55
zval * server ;
56
56
zval * responseDocument ;
57
+ (void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
57
58
58
59
59
60
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
60
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
61
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
61
62
62
63
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "OA" , & server , php_phongo_server_ce , & responseDocument ) == FAILURE ) {
63
64
zend_restore_error_handling (& error_handling TSRMLS_CC );
@@ -67,43 +68,70 @@ PHP_METHOD(CommandResult, __construct)
67
68
68
69
}
69
70
/* }}} */
70
- /* {{{ proto MongoDB\Driver\Cursor CommandResult::getIterator()
71
+ /* {{{ proto void Result::setTypemap(array $typemap)
72
+ Sets a typemap to use for BSON unserialization */
73
+ PHP_METHOD (Result , setTypemap )
74
+ {
75
+ php_phongo_result_t * intern ;
76
+ php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
77
+ zend_error_handling error_handling ;
78
+ zval * typemap = NULL ;
79
+ (void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
80
+
81
+
82
+ zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
83
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
84
+
85
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "a!" , & typemap ) == FAILURE ) {
86
+ zend_restore_error_handling (& error_handling TSRMLS_CC );
87
+ return ;
88
+ }
89
+ zend_restore_error_handling (& error_handling TSRMLS_CC );
90
+
91
+ php_phongo_bson_typemap_to_state (typemap , & state .map TSRMLS_CC );
92
+
93
+ intern -> visitor_data = state ;
94
+ }
95
+ /* }}} */
96
+ /* {{{ proto MongoDB\Driver\Cursor Result::getIterator()
71
97
Returns the Cursor iterator */
72
- PHP_METHOD (CommandResult , getIterator )
98
+ PHP_METHOD (Result , getIterator )
73
99
{
74
- php_phongo_commandresult_t * intern ;
100
+ php_phongo_result_t * intern ;
75
101
zend_error_handling error_handling ;
102
+ (void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
76
103
77
104
78
105
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
79
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
106
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
80
107
81
108
if (zend_parse_parameters_none () == FAILURE ) {
82
109
zend_restore_error_handling (& error_handling TSRMLS_CC );
83
110
return ;
84
111
}
85
112
zend_restore_error_handling (& error_handling TSRMLS_CC );
86
113
87
- php_phongo_cursor_new_from_result ( return_value , & intern -> result TSRMLS_CC );
88
-
89
- if ( intern -> result . ce_get_iterator ) {
90
- object_init_ex (return_value , intern -> result . ce_get_iterator );
114
+ if ( intern -> ce_get_iterator ) {
115
+ object_init_ex ( return_value , intern -> ce_get_iterator );
116
+ } else {
117
+ php_phongo_cursor_new_from_result (return_value , intern TSRMLS_CC );
91
118
}
92
119
93
120
}
94
121
/* }}} */
95
- /* {{{ proto self CommandResult ::setIteratorClass(string $class)
122
+ /* {{{ proto self Result ::setIteratorClass(string $class)
96
123
Sets the class name of the Cursor implementation to be used */
97
- PHP_METHOD (CommandResult , setIteratorClass )
124
+ PHP_METHOD (Result , setIteratorClass )
98
125
{
99
- php_phongo_commandresult_t * intern ;
126
+ php_phongo_result_t * intern ;
100
127
zend_error_handling error_handling ;
101
128
char * class ;
102
129
int class_len ;
130
+ (void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
103
131
104
132
105
133
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
106
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
134
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
107
135
108
136
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "s" , & class , & class_len ) == FAILURE ) {
109
137
zend_restore_error_handling (& error_handling TSRMLS_CC );
@@ -113,17 +141,18 @@ PHP_METHOD(CommandResult, setIteratorClass)
113
141
114
142
}
115
143
/* }}} */
116
- /* {{{ proto self CommandResult ::setIteratorInitCallback(callable $callback)
144
+ /* {{{ proto self Result ::setIteratorInitCallback(callable $callback)
117
145
Sets a callback to invoke for initializing a custom Cursor */
118
- PHP_METHOD (CommandResult , setIteratorInitCallback )
146
+ PHP_METHOD (Result , setIteratorInitCallback )
119
147
{
120
- php_phongo_commandresult_t * intern ;
148
+ php_phongo_result_t * intern ;
121
149
zend_error_handling error_handling ;
122
150
zval * callback ;
151
+ (void )return_value ; (void )return_value_ptr ; (void )return_value_used ;
123
152
124
153
125
154
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
126
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
155
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
127
156
128
157
if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "o" , & callback ) == FAILURE ) {
129
158
zend_restore_error_handling (& error_handling TSRMLS_CC );
@@ -133,16 +162,17 @@ PHP_METHOD(CommandResult, setIteratorInitCallback)
133
162
134
163
}
135
164
/* }}} */
136
- /* {{{ proto array CommandResult::getResponseDocument ()
165
+ /* {{{ proto array Result::toArray ()
137
166
Returns the original response document from the server */
138
- PHP_METHOD (CommandResult , getResponseDocument )
167
+ PHP_METHOD (Result , toArray )
139
168
{
140
- php_phongo_commandresult_t * intern ;
169
+ php_phongo_result_t * intern ;
141
170
zend_error_handling error_handling ;
171
+ (void )return_value_ptr ; (void )return_value_used ;
142
172
143
173
144
174
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
145
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
175
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
146
176
147
177
if (zend_parse_parameters_none () == FAILURE ) {
148
178
zend_restore_error_handling (& error_handling TSRMLS_CC );
@@ -151,26 +181,27 @@ PHP_METHOD(CommandResult, getResponseDocument)
151
181
zend_restore_error_handling (& error_handling TSRMLS_CC );
152
182
153
183
154
- if (intern -> result . firstBatch ) {
184
+ if (intern -> firstBatch ) {
155
185
php_phongo_bson_state state = PHONGO_BSON_STATE_INITIALIZER ;
156
186
157
187
MAKE_STD_ZVAL (state .zchild );
158
- bson_to_zval (bson_get_data (intern -> result . firstBatch ), intern -> result . firstBatch -> len , & state );
188
+ bson_to_zval (bson_get_data (intern -> firstBatch ), intern -> firstBatch -> len , & state );
159
189
RETURN_ZVAL (state .zchild , 0 , 1 );
160
190
}
161
191
}
162
192
/* }}} */
163
- /* {{{ proto MongoDB\Driver\Server CommandResult ::getServer()
193
+ /* {{{ proto MongoDB\Driver\Server Result ::getServer()
164
194
Returns the Server object that this cursor is attached to */
165
- PHP_METHOD (CommandResult , getServer )
195
+ PHP_METHOD (Result , getServer )
166
196
{
167
- php_phongo_commandresult_t * intern ;
197
+ php_phongo_result_t * intern ;
168
198
zend_error_handling error_handling ;
169
199
mongoc_host_list_t host ;
200
+ (void )return_value_ptr ; (void )return_value_used ;
170
201
171
202
172
203
zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling TSRMLS_CC );
173
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
204
+ intern = (php_phongo_result_t * )zend_object_store_get_object (getThis () TSRMLS_CC );
174
205
175
206
if (zend_parse_parameters_none () == FAILURE ) {
176
207
zend_restore_error_handling (& error_handling TSRMLS_CC );
@@ -179,109 +210,114 @@ PHP_METHOD(CommandResult, getServer)
179
210
zend_restore_error_handling (& error_handling TSRMLS_CC );
180
211
181
212
182
- mongoc_cursor_get_host (intern -> result . cursor , & host );
183
- phongo_server_init (return_value , intern -> result . hint , & host TSRMLS_CC );
213
+ mongoc_cursor_get_host (intern -> cursor , & host );
214
+ phongo_server_init (return_value , intern -> hint , & host TSRMLS_CC );
184
215
}
185
216
/* }}} */
186
217
187
- /* {{{ MongoDB\Driver\CommandResult */
218
+ /* {{{ MongoDB\Driver\Result */
188
219
189
- ZEND_BEGIN_ARG_INFO_EX (ai_CommandResult___construct , 0 , 0 , 2 )
220
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result___construct , 0 , 0 , 2 )
190
221
ZEND_ARG_OBJ_INFO (0 , server , MongoDB \\Driver \\Server , 0 )
191
222
ZEND_ARG_INFO (0 , responseDocument )
192
223
ZEND_END_ARG_INFO ();
193
224
194
- ZEND_BEGIN_ARG_INFO_EX (ai_CommandResult_getIterator , 0 , 0 , 0 )
225
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result_setTypemap , 0 , 0 , 1 )
226
+ ZEND_ARG_ARRAY_INFO (0 , typemap , 0 )
227
+ ZEND_END_ARG_INFO ();
228
+
229
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result_getIterator , 0 , 0 , 0 )
195
230
ZEND_END_ARG_INFO ();
196
231
197
- ZEND_BEGIN_ARG_INFO_EX (ai_CommandResult_setIteratorClass , 0 , 0 , 1 )
232
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result_setIteratorClass , 0 , 0 , 1 )
198
233
ZEND_ARG_INFO (0 , class )
199
234
ZEND_END_ARG_INFO ();
200
235
201
- ZEND_BEGIN_ARG_INFO_EX (ai_CommandResult_setIteratorInitCallback , 0 , 0 , 1 )
236
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result_setIteratorInitCallback , 0 , 0 , 1 )
202
237
ZEND_ARG_INFO (0 , callback ) /* callable */
203
238
ZEND_END_ARG_INFO ();
204
239
205
- ZEND_BEGIN_ARG_INFO_EX (ai_CommandResult_getResponseDocument , 0 , 0 , 0 )
240
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result_toArray , 0 , 0 , 0 )
206
241
ZEND_END_ARG_INFO ();
207
242
208
- ZEND_BEGIN_ARG_INFO_EX (ai_CommandResult_getServer , 0 , 0 , 0 )
243
+ ZEND_BEGIN_ARG_INFO_EX (ai_Result_getServer , 0 , 0 , 0 )
209
244
ZEND_END_ARG_INFO ();
210
245
211
246
212
- static zend_function_entry php_phongo_commandresult_me [] = {
213
- PHP_ME (CommandResult , __construct , ai_CommandResult___construct , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
214
- PHP_ME (CommandResult , getIterator , ai_CommandResult_getIterator , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
215
- PHP_ME (CommandResult , setIteratorClass , ai_CommandResult_setIteratorClass , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
216
- PHP_ME (CommandResult , setIteratorInitCallback , ai_CommandResult_setIteratorInitCallback , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
217
- PHP_ME (CommandResult , getResponseDocument , ai_CommandResult_getResponseDocument , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
218
- PHP_ME (CommandResult , getServer , ai_CommandResult_getServer , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
247
+ static zend_function_entry php_phongo_result_me [] = {
248
+ PHP_ME (Result , __construct , ai_Result___construct , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
249
+ PHP_ME (Result , setTypemap , ai_Result_setTypemap , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
250
+ PHP_ME (Result , getIterator , ai_Result_getIterator , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
251
+ PHP_ME (Result , setIteratorClass , ai_Result_setIteratorClass , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
252
+ PHP_ME (Result , setIteratorInitCallback , ai_Result_setIteratorInitCallback , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
253
+ PHP_ME (Result , toArray , ai_Result_toArray , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
254
+ PHP_ME (Result , getServer , ai_Result_getServer , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
219
255
PHP_FE_END
220
256
};
221
257
222
258
/* }}} */
223
259
224
260
225
- /* {{{ php_phongo_commandresult_t object handlers */
226
- static void php_phongo_commandresult_free_object (void * object TSRMLS_DC ) /* {{{ */
261
+ /* {{{ php_phongo_result_t object handlers */
262
+ static void php_phongo_result_free_object (void * object TSRMLS_DC ) /* {{{ */
227
263
{
228
- php_phongo_commandresult_t * intern = (php_phongo_commandresult_t * )object ;
264
+ php_phongo_result_t * intern = (php_phongo_result_t * )object ;
229
265
230
- zend_object_std_dtor (& intern -> result . std TSRMLS_CC );
266
+ zend_object_std_dtor (& intern -> std TSRMLS_CC );
231
267
232
- php_phongo_result_free (& intern -> result );
268
+ php_phongo_result_free (intern );
233
269
234
270
efree (intern );
235
271
} /* }}} */
236
272
237
- zend_object_value php_phongo_commandresult_create_object (zend_class_entry * class_type TSRMLS_DC ) /* {{{ */
273
+ zend_object_value php_phongo_result_create_object (zend_class_entry * class_type TSRMLS_DC ) /* {{{ */
238
274
{
239
275
zend_object_value retval ;
240
- php_phongo_commandresult_t * intern = NULL ;
276
+ php_phongo_result_t * intern = NULL ;
241
277
242
- intern = (php_phongo_commandresult_t * )ecalloc (1 , sizeof * intern );
278
+ intern = (php_phongo_result_t * )ecalloc (1 , sizeof * intern );
243
279
244
- zend_object_std_init (& intern -> result . std , class_type TSRMLS_CC );
245
- object_properties_init (& intern -> result . std , class_type );
280
+ zend_object_std_init (& intern -> std , class_type TSRMLS_CC );
281
+ object_properties_init (& intern -> std , class_type );
246
282
247
- retval .handle = zend_objects_store_put (intern , (zend_objects_store_dtor_t ) zend_objects_destroy_object , php_phongo_commandresult_free_object , NULL TSRMLS_CC );
248
- retval .handlers = & php_phongo_handler_commandresult ;
283
+ retval .handle = zend_objects_store_put (intern , (zend_objects_store_dtor_t ) zend_objects_destroy_object , php_phongo_result_free_object , NULL TSRMLS_CC );
284
+ retval .handlers = & php_phongo_handler_result ;
249
285
250
286
return retval ;
251
287
} /* }}} */
252
288
253
- HashTable * php_phongo_commandresult_get_debug_info (zval * object , int * is_temp TSRMLS_DC ) /* {{{ */
289
+ HashTable * php_phongo_result_get_debug_info (zval * object , int * is_temp TSRMLS_DC ) /* {{{ */
254
290
{
255
- php_phongo_commandresult_t * intern ;
291
+ php_phongo_result_t * intern ;
256
292
zval retval = zval_used_for_init ;
257
293
258
294
259
295
* is_temp = 1 ;
260
- intern = (php_phongo_commandresult_t * )zend_object_store_get_object (object TSRMLS_CC );
296
+ intern = (php_phongo_result_t * )zend_object_store_get_object (object TSRMLS_CC );
261
297
262
- php_phongo_result_to_zval (& retval , & intern -> result );
298
+ php_phongo_result_to_zval (& retval , intern );
263
299
264
300
return Z_ARRVAL (retval );
265
301
266
302
} /* }}} */
267
303
/* }}} */
268
304
269
305
/* {{{ PHP_MINIT_FUNCTION */
270
- PHP_MINIT_FUNCTION (CommandResult )
306
+ PHP_MINIT_FUNCTION (Result )
271
307
{
272
308
(void )type ; (void )module_number ;
273
309
zend_class_entry ce ;
274
310
275
- INIT_NS_CLASS_ENTRY (ce , "MongoDB\\Driver" , "CommandResult " , php_phongo_commandresult_me );
276
- php_phongo_commandresult_ce = zend_register_internal_class (& ce TSRMLS_CC );
277
- php_phongo_commandresult_ce -> create_object = php_phongo_commandresult_create_object ;
278
- php_phongo_commandresult_ce -> ce_flags |= ZEND_ACC_FINAL_CLASS ;
279
- php_phongo_commandresult_ce -> get_iterator = phongo_result_get_iterator ;
311
+ INIT_NS_CLASS_ENTRY (ce , "MongoDB\\Driver" , "Result " , php_phongo_result_me );
312
+ php_phongo_result_ce = zend_register_internal_class (& ce TSRMLS_CC );
313
+ php_phongo_result_ce -> create_object = php_phongo_result_create_object ;
314
+ php_phongo_result_ce -> ce_flags |= ZEND_ACC_FINAL_CLASS ;
315
+ php_phongo_result_ce -> get_iterator = phongo_result_get_iterator ;
280
316
281
- memcpy (& php_phongo_handler_commandresult , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
282
- php_phongo_handler_commandresult .get_debug_info = php_phongo_commandresult_get_debug_info ;
317
+ memcpy (& php_phongo_handler_result , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
318
+ php_phongo_handler_result .get_debug_info = php_phongo_result_get_debug_info ;
283
319
284
- zend_class_implements (php_phongo_commandresult_ce TSRMLS_CC , 1 , zend_ce_aggregate );
320
+ zend_class_implements (php_phongo_result_ce TSRMLS_CC , 1 , zend_ce_aggregate );
285
321
286
322
287
323
return SUCCESS ;
0 commit comments