@@ -39,7 +39,8 @@ static bool php_phongo_cursorid_init_from_string(php_phongo_cursorid_t* intern,
39
39
return false;
40
40
}
41
41
42
- intern -> id = id ;
42
+ intern -> id = id ;
43
+ intern -> initialized = true;
43
44
return true;
44
45
} /* }}} */
45
46
@@ -57,6 +58,61 @@ static bool php_phongo_cursorid_init_from_hash(php_phongo_cursorid_t* intern, Ha
57
58
return false;
58
59
} /* }}} */
59
60
61
+ static HashTable * php_phongo_cursorid_get_properties_hash (phongo_compat_object_handler_type * object , bool is_debug ) /* {{{ */
62
+ {
63
+ php_phongo_cursorid_t * intern ;
64
+ HashTable * props ;
65
+
66
+ intern = Z_OBJ_CURSORID (PHONGO_COMPAT_GET_OBJ (object ));
67
+
68
+ PHONGO_GET_PROPERTY_HASH_INIT_PROPS (is_debug , intern , props , 2 );
69
+
70
+ if (!intern -> initialized ) {
71
+ return props ;
72
+ }
73
+
74
+ {
75
+ zval value ;
76
+
77
+ if (is_debug ) {
78
+ #if SIZEOF_ZEND_LONG == 4
79
+ ZVAL_INT64_STRING (& value , intern -> id );
80
+ #else
81
+ ZVAL_LONG (& value , intern -> id );
82
+ #endif
83
+ } else {
84
+ ZVAL_INT64_STRING (& value , intern -> id );
85
+ }
86
+ zend_hash_str_update (props , "id" , sizeof ("id" ) - 1 , & value );
87
+ }
88
+
89
+ return props ;
90
+ } /* }}} */
91
+
92
+ /* {{{ proto MongoDB\Driver\CursorId MongoDB\Driver\CursorId::__set_state(array $properties)
93
+ */
94
+ static PHP_METHOD (CursorId , __set_state )
95
+ {
96
+ zend_error_handling error_handling ;
97
+ php_phongo_cursorid_t * intern ;
98
+ HashTable * props ;
99
+ zval * array ;
100
+
101
+ zend_replace_error_handling (EH_THROW , phongo_exception_from_phongo_domain (PHONGO_ERROR_INVALID_ARGUMENT ), & error_handling );
102
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "a" , & array ) == FAILURE ) {
103
+ zend_restore_error_handling (& error_handling );
104
+ return ;
105
+ }
106
+ zend_restore_error_handling (& error_handling );
107
+
108
+ object_init_ex (return_value , php_phongo_cursorid_ce );
109
+
110
+ intern = Z_CURSORID_OBJ_P (return_value );
111
+ props = Z_ARRVAL_P (array );
112
+
113
+ php_phongo_cursorid_init_from_hash (intern , props );
114
+ } /* }}} */
115
+
60
116
/* {{{ proto string MongoDB\Driver\CursorId::__toString()
61
117
Returns the string representation of the CursorId */
62
118
static PHP_METHOD (CursorId , __toString )
@@ -148,6 +204,10 @@ static PHP_METHOD(CursorId, unserialize)
148
204
} /* }}} */
149
205
150
206
/* {{{ MongoDB\Driver\CursorId function entries */
207
+ ZEND_BEGIN_ARG_INFO_EX (ai_CursorId___set_state , 0 , 0 , 1 )
208
+ ZEND_ARG_ARRAY_INFO (0 , properties , 0 )
209
+ ZEND_END_ARG_INFO ()
210
+
151
211
ZEND_BEGIN_ARG_INFO_EX (ai_CursorId_unserialize , 0 , 0 , 1 )
152
212
ZEND_ARG_INFO (0 , serialized )
153
213
ZEND_END_ARG_INFO ()
@@ -157,6 +217,7 @@ ZEND_END_ARG_INFO()
157
217
158
218
static zend_function_entry php_phongo_cursorid_me [] = {
159
219
/* clang-format off */
220
+ PHP_ME (CursorId , __set_state , ai_CursorId___set_state , ZEND_ACC_PUBLIC | ZEND_ACC_STATIC )
160
221
PHP_ME (CursorId , __toString , ai_CursorId_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
161
222
PHP_ME (CursorId , serialize , ai_CursorId_void , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
162
223
PHP_ME (CursorId , unserialize , ai_CursorId_unserialize , ZEND_ACC_PUBLIC | ZEND_ACC_FINAL )
@@ -175,6 +236,11 @@ static void php_phongo_cursorid_free_object(zend_object* object) /* {{{ */
175
236
php_phongo_cursorid_t * intern = Z_OBJ_CURSORID (object );
176
237
177
238
zend_object_std_dtor (& intern -> std );
239
+
240
+ if (intern -> properties ) {
241
+ zend_hash_destroy (intern -> properties );
242
+ FREE_HASHTABLE (intern -> properties );
243
+ }
178
244
} /* }}} */
179
245
180
246
static zend_object * php_phongo_cursorid_create_object (zend_class_entry * class_type ) /* {{{ */
@@ -193,24 +259,16 @@ static zend_object* php_phongo_cursorid_create_object(zend_class_entry* class_ty
193
259
194
260
static HashTable * php_phongo_cursorid_get_debug_info (phongo_compat_object_handler_type * object , int * is_temp ) /* {{{ */
195
261
{
196
- php_phongo_cursorid_t * intern ;
197
- zval retval = ZVAL_STATIC_INIT ;
198
-
199
262
* is_temp = 1 ;
200
- intern = Z_OBJ_CURSORID (PHONGO_COMPAT_GET_OBJ (object ));
201
-
202
- array_init (& retval );
203
-
204
- #if SIZEOF_ZEND_LONG == 4
205
- ADD_ASSOC_INT64_AS_STRING (& retval , "id" , intern -> id );
206
- #else
207
- ADD_ASSOC_LONG_EX (& retval , "id" , intern -> id );
208
- #endif
209
-
210
- return Z_ARRVAL (retval );
263
+ return php_phongo_cursorid_get_properties_hash (object , true);
211
264
} /* }}} */
212
265
/* }}} */
213
266
267
+ static HashTable * php_phongo_cursorid_get_properties (phongo_compat_object_handler_type * object ) /* {{{ */
268
+ {
269
+ return php_phongo_cursorid_get_properties_hash (object , false);
270
+ } /* }}} */
271
+
214
272
void php_phongo_cursorid_init_ce (INIT_FUNC_ARGS ) /* {{{ */
215
273
{
216
274
zend_class_entry ce ;
@@ -224,6 +282,7 @@ void php_phongo_cursorid_init_ce(INIT_FUNC_ARGS) /* {{{ */
224
282
225
283
memcpy (& php_phongo_handler_cursorid , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
226
284
php_phongo_handler_cursorid .get_debug_info = php_phongo_cursorid_get_debug_info ;
285
+ php_phongo_handler_cursorid .get_properties = php_phongo_cursorid_get_properties ;
227
286
php_phongo_handler_cursorid .free_obj = php_phongo_cursorid_free_object ;
228
287
php_phongo_handler_cursorid .offset = XtOffsetOf (php_phongo_cursorid_t , std );
229
288
} /* }}} */
0 commit comments