Skip to content

Commit 43bb5a7

Browse files
committed
PHPC-779: Switch MaxKey from O to C type serialization
1 parent 8050b14 commit 43bb5a7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/BSON/MaxKey.c

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

71+
/* {{{ proto string MaxKey::serialize()
72+
*/
73+
PHP_METHOD(MaxKey, serialize)
74+
{
75+
PHONGO_RETURN_STRING("");
76+
}
77+
/* }}} */
78+
79+
/* {{{ proto string MaxKey::unserialize(string $serialized)
80+
*/
81+
PHP_METHOD(MaxKey, 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\MaxKey */
7298

7399
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey___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_MaxKey_unserialize, 0, 0, 1)
104+
ZEND_ARG_INFO(0, serialized)
105+
ZEND_END_ARG_INFO()
106+
77107
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey_void, 0, 0, 0)
78108
ZEND_END_ARG_INFO()
79109

80110
static zend_function_entry php_phongo_maxkey_me[] = {
81111
PHP_ME(MaxKey, __set_state, ai_MaxKey___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
82112
PHP_ME(MaxKey, __wakeup, ai_MaxKey_void, ZEND_ACC_PUBLIC)
113+
PHP_ME(MaxKey, serialize, ai_MaxKey_void, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
114+
PHP_ME(MaxKey, unserialize, ai_MaxKey_unserialize, ZEND_ACC_PUBLIC|ZEND_ACC_FINAL)
83115
PHP_FE_END
84116
};
85117

@@ -135,6 +167,8 @@ PHP_MINIT_FUNCTION(MaxKey)
135167
PHONGO_CE_FINAL(php_phongo_maxkey_ce);
136168

137169
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
170+
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, zend_ce_serializable);
171+
138172
memcpy(&php_phongo_handler_maxkey, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
139173
#if PHP_VERSION_ID >= 70000
140174
php_phongo_handler_maxkey.free_obj = php_phongo_maxkey_free_object;

tests/bson/bson-maxkey-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\MaxKey)#%d (%d) {
1515
}
16-
string(31) "O:19:"MongoDB\BSON\MaxKey":0:{}"
16+
string(31) "C:19:"MongoDB\BSON\MaxKey":0:{}"
1717
object(MongoDB\BSON\MaxKey)#%d (%d) {
1818
}
1919
===DONE===

0 commit comments

Comments
 (0)