Skip to content

Commit c5bc3d7

Browse files
committed
PHPC-779: Switch MinKey from O to C type serialization
1 parent 43bb5a7 commit c5bc3d7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/BSON/MinKey.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,50 @@ PHP_METHOD(MinKey, __wakeup)
6868
}
6969
/* }}} */
7070

71+
/* {{{ proto string MinKey::serialize()
72+
*/
73+
PHP_METHOD(MinKey, serialize)
74+
{
75+
PHONGO_RETURN_STRING("");
76+
}
77+
/* }}} */
78+
79+
/* {{{ proto string MinKey::unserialize(string $serialized)
80+
*/
81+
PHP_METHOD(MinKey, unserialize)
82+
{
83+
zend_error_handling error_handling;
84+
char *serialized;
85+
phongo_zpp_char_len serialized_len;
86+
87+
zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling TSRMLS_CC);
88+
89+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &serialized_len) == FAILURE) {
90+
zend_restore_error_handling(&error_handling TSRMLS_CC);
91+
return;
92+
}
93+
zend_restore_error_handling(&error_handling TSRMLS_CC);
94+
}
95+
/* }}} */
96+
7197
/* {{{ BSON\MinKey */
7298

7399
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey___set_state, 0, 0, 1)
74100
ZEND_ARG_ARRAY_INFO(0, properties, 0)
75101
ZEND_END_ARG_INFO()
76102

103+
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey_unserialize, 0, 0, 1)
104+
ZEND_ARG_INFO(0, serialized)
105+
ZEND_END_ARG_INFO()
106+
77107
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey_void, 0, 0, 0)
78108
ZEND_END_ARG_INFO()
79109

80110
static zend_function_entry php_phongo_minkey_me[] = {
81111
PHP_ME(MinKey, __set_state, ai_MinKey___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
82112
PHP_ME(MinKey, __wakeup, ai_MinKey_void, ZEND_ACC_PUBLIC)
113+
PHP_ME(MinKey, serialize, ai_MinKey_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
114+
PHP_ME(MinKey, unserialize, ai_MinKey_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
83115
PHP_FE_END
84116
};
85117

@@ -136,6 +168,8 @@ PHP_MINIT_FUNCTION(MinKey)
136168
PHONGO_CE_FINAL(php_phongo_minkey_ce);
137169

138170
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
171+
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, zend_ce_serializable);
172+
139173
memcpy(&php_phongo_handler_minkey, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
140174
#if PHP_VERSION_ID >= 70000
141175
php_phongo_handler_minkey.free_obj = php_phongo_minkey_free_object;

tests/bson/bson-minkey-serialization-001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var_dump(unserialize($s));
1313
--EXPECTF--
1414
object(MongoDB\BSON\MinKey)#%d (%d) {
1515
}
16-
string(31) "O:19:"MongoDB\BSON\MinKey":0:{}"
16+
string(31) "C:19:"MongoDB\BSON\MinKey":0:{}"
1717
object(MongoDB\BSON\MinKey)#%d (%d) {
1818
}
1919
===DONE===

0 commit comments

Comments
 (0)