@@ -46,6 +46,38 @@ PHONGO_API zend_class_entry *php_phongo_regex_ce;
46
46
47
47
zend_object_handlers php_phongo_handler_regex ;
48
48
49
+ /* Initialize the object from a string and return whether it was successful. */
50
+ static bool php_phongo_regex_init (php_phongo_regex_t * intern , const char * pattern , phongo_zpp_char_len pattern_len , const char * flags , phongo_zpp_char_len flags_len )
51
+ {
52
+ intern -> pattern = estrndup (pattern , pattern_len );
53
+ intern -> pattern_len = pattern_len ;
54
+ intern -> flags = estrndup (flags , flags_len );
55
+ intern -> flags_len = flags_len ;
56
+
57
+ return true;
58
+ }
59
+
60
+ /* Initialize the object from a HashTable and return whether it was successful. */
61
+ static bool php_phongo_regex_init_from_hash (php_phongo_regex_t * intern , HashTable * props )
62
+ {
63
+ #if PHP_VERSION_ID >= 70000
64
+ zval * pattern , * flags ;
65
+
66
+ if ((pattern = zend_hash_str_find (props , "pattern" , sizeof ("pattern" )- 1 )) && Z_TYPE_P (pattern ) == IS_STRING &&
67
+ (flags = zend_hash_str_find (props , "flags" , sizeof ("flags" )- 1 )) && Z_TYPE_P (flags ) == IS_STRING ) {
68
+ return php_phongo_regex_init (intern , Z_STRVAL_P (pattern ), Z_STRLEN_P (pattern ), Z_STRVAL_P (flags ), Z_STRLEN_P (flags ));
69
+ }
70
+ #else
71
+ zval * * pattern , * * flags ;
72
+
73
+ if (zend_hash_find (props , "pattern" , sizeof ("pattern" ), (void * * ) & pattern ) == SUCCESS && Z_TYPE_PP (pattern ) == IS_STRING &&
74
+ zend_hash_find (props , "flags" , sizeof ("flags" ), (void * * ) & flags ) == SUCCESS && Z_TYPE_PP (flags ) == IS_STRING ) {
75
+ return php_phongo_regex_init (intern , Z_STRVAL_PP (pattern ), Z_STRLEN_PP (pattern ), Z_STRVAL_PP (flags ), Z_STRLEN_PP (flags ));
76
+ }
77
+ #endif
78
+ return false;
79
+ }
80
+
49
81
/* {{{ proto BSON\Regex Regex::__construct(string $pattern, string $flags)
50
82
Constructs a new regular expression. */
51
83
PHP_METHOD (Regex , __construct )
@@ -67,11 +99,7 @@ PHP_METHOD(Regex, __construct)
67
99
}
68
100
zend_restore_error_handling (& error_handling TSRMLS_CC );
69
101
70
-
71
- intern -> pattern = estrndup (pattern , pattern_len );
72
- intern -> pattern_len = pattern_len ;
73
- intern -> flags = estrndup (flags , flags_len );
74
- intern -> flags_len = flags_len ;
102
+ php_phongo_regex_init (intern , pattern , pattern_len , flags , flags_len );
75
103
}
76
104
/* }}} */
77
105
/* {{{ proto void Regex::getPattern()
@@ -108,6 +136,30 @@ PHP_METHOD(Regex, getFlags)
108
136
PHONGO_RETURN_STRINGL (intern -> flags , intern -> flags_len );
109
137
}
110
138
/* }}} */
139
+
140
+ /* {{{ proto Regex::__set_state(array $properties)
141
+ */
142
+ PHP_METHOD (Regex , __set_state )
143
+ {
144
+ php_phongo_regex_t * intern ;
145
+ HashTable * props ;
146
+ zval * array ;
147
+
148
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "a" , & array ) == FAILURE ) {
149
+ RETURN_FALSE ;
150
+ }
151
+
152
+ object_init_ex (return_value , php_phongo_regex_ce );
153
+
154
+ intern = Z_REGEX_OBJ_P (return_value );
155
+ props = Z_ARRVAL_P (array );
156
+
157
+ if (!php_phongo_regex_init_from_hash (intern , props )) {
158
+ php_error (E_ERROR , "Invalid serialization data for Regex object" );
159
+ }
160
+ }
161
+ /* }}} */
162
+
111
163
/* {{{ proto void Regex::__toString()
112
164
*/
113
165
PHP_METHOD (Regex , __toString )
@@ -130,6 +182,25 @@ PHP_METHOD(Regex, __toString)
130
182
}
131
183
/* }}} */
132
184
185
+ /* {{{ proto Regex::__wakeup()
186
+ */
187
+ PHP_METHOD (Regex , __wakeup )
188
+ {
189
+ php_phongo_regex_t * intern ;
190
+ HashTable * props ;
191
+
192
+ if (zend_parse_parameters_none () == FAILURE ) {
193
+ return ;
194
+ }
195
+
196
+ intern = Z_REGEX_OBJ_P (getThis ());
197
+ props = zend_std_get_properties (getThis () TSRMLS_CC );
198
+
199
+ if (!php_phongo_regex_init_from_hash (intern , props )) {
200
+ php_error (E_ERROR , "Invalid serialization data for Regex object" );
201
+ }
202
+ }
203
+ /* }}} */
133
204
134
205
/* {{{ BSON\Regex */
135
206
@@ -138,22 +209,20 @@ ZEND_BEGIN_ARG_INFO_EX(ai_Regex___construct, 0, 0, 2)
138
209
ZEND_ARG_INFO (0 , flags )
139
210
ZEND_END_ARG_INFO ();
140
211
141
- ZEND_BEGIN_ARG_INFO_EX (ai_Regex_getPattern , 0 , 0 , 0 )
142
- ZEND_END_ARG_INFO ();
143
-
144
- ZEND_BEGIN_ARG_INFO_EX (ai_Regex_getFlags , 0 , 0 , 0 )
145
- ZEND_END_ARG_INFO ();
146
-
147
- ZEND_BEGIN_ARG_INFO_EX (ai_Regex___toString , 0 , 0 , 0 )
148
- ZEND_END_ARG_INFO ();
212
+ ZEND_BEGIN_ARG_INFO_EX (ai_Regex___set_state , 0 , 0 , 1 )
213
+ ZEND_ARG_ARRAY_INFO (0 , properties , 0 )
214
+ ZEND_END_ARG_INFO ()
149
215
216
+ ZEND_BEGIN_ARG_INFO_EX (ai_Regex_void , 0 , 0 , 0 )
217
+ ZEND_END_ARG_INFO ()
150
218
151
219
static zend_function_entry php_phongo_regex_me [] = {
152
220
PHP_ME (Regex , __construct , ai_Regex___construct , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
153
- PHP_ME (Regex , getPattern , ai_Regex_getPattern , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
154
- PHP_ME (Regex , getFlags , ai_Regex_getFlags , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
155
- PHP_ME (Regex , __toString , ai_Regex___toString , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
156
- PHP_ME (Manager , __wakeUp , NULL , ZEND_ACC_PUBLIC )
221
+ PHP_ME (Regex , __set_state , ai_Regex___set_state , ZEND_ACC_PUBLIC |ZEND_ACC_STATIC )
222
+ PHP_ME (Regex , __toString , ai_Regex_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
223
+ PHP_ME (Regex , __wakeup , ai_Regex_void , ZEND_ACC_PUBLIC )
224
+ PHP_ME (Regex , getPattern , ai_Regex_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
225
+ PHP_ME (Regex , getFlags , ai_Regex_void , ZEND_ACC_PUBLIC |ZEND_ACC_FINAL )
157
226
PHP_FE_END
158
227
};
159
228
@@ -224,6 +293,45 @@ HashTable *php_phongo_regex_get_debug_info(zval *object, int *is_temp TSRMLS_DC)
224
293
225
294
return Z_ARRVAL (retval );
226
295
} /* }}} */
296
+
297
+ HashTable * php_phongo_regex_get_properties (zval * object TSRMLS_DC ) /* {{{ */
298
+ {
299
+ php_phongo_regex_t * intern ;
300
+ HashTable * props ;
301
+
302
+ intern = Z_REGEX_OBJ_P (object );
303
+ props = zend_std_get_properties (object TSRMLS_CC );
304
+
305
+ if (!intern -> pattern ) {
306
+ return props ;
307
+ }
308
+
309
+ #if PHP_VERSION_ID >= 70000
310
+ {
311
+ zval pattern , flags ;
312
+
313
+ ZVAL_STRINGL (& pattern , intern -> pattern , intern -> pattern_len );
314
+ zend_hash_str_update (props , "pattern" , sizeof ("pattern" )- 1 , & pattern );
315
+
316
+ ZVAL_STRINGL (& flags , intern -> flags , intern -> flags_len );
317
+ zend_hash_str_update (props , "flags" , sizeof ("flags" )- 1 , & flags );
318
+ }
319
+ #else
320
+ {
321
+ zval * pattern , * flags ;
322
+
323
+ MAKE_STD_ZVAL (pattern );
324
+ ZVAL_STRINGL (pattern , intern -> pattern , intern -> pattern_len , 1 );
325
+ zend_hash_update (props , "pattern" , sizeof ("pattern" ), & pattern , sizeof (pattern ), NULL );
326
+
327
+ MAKE_STD_ZVAL (flags );
328
+ ZVAL_STRINGL (flags , intern -> flags , intern -> flags_len , 1 );
329
+ zend_hash_update (props , "flags" , sizeof ("flags" ), & flags , sizeof (flags ), NULL );
330
+ }
331
+ #endif
332
+
333
+ return props ;
334
+ } /* }}} */
227
335
/* }}} */
228
336
229
337
/* {{{ PHP_MINIT_FUNCTION */
@@ -236,11 +344,10 @@ PHP_MINIT_FUNCTION(Regex)
236
344
php_phongo_regex_ce = zend_register_internal_class (& ce TSRMLS_CC );
237
345
php_phongo_regex_ce -> create_object = php_phongo_regex_create_object ;
238
346
PHONGO_CE_FINAL (php_phongo_regex_ce );
239
- PHONGO_CE_DISABLE_SERIALIZATION (php_phongo_regex_ce );
240
347
241
348
zend_class_implements (php_phongo_regex_ce TSRMLS_CC , 1 , php_phongo_type_ce );
242
349
memcpy (& php_phongo_handler_regex , phongo_get_std_object_handlers (), sizeof (zend_object_handlers ));
243
- php_phongo_handler_regex .get_debug_info = php_phongo_regex_get_debug_info ;
350
+ php_phongo_handler_regex .get_properties = php_phongo_regex_get_properties ;
244
351
#if PHP_VERSION_ID >= 70000
245
352
php_phongo_handler_regex .free_obj = php_phongo_regex_free_object ;
246
353
php_phongo_handler_regex .offset = XtOffsetOf (php_phongo_regex_t , std );
0 commit comments