Skip to content

Commit ef1eee4

Browse files
committed
PHPC-460: MaxKey and MinKey serialization and var_export
1 parent 41081da commit ef1eee4

8 files changed

+140
-60
lines changed

src/BSON/MaxKey.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,40 @@ PHONGO_API zend_class_entry *php_phongo_maxkey_ce;
4646

4747
zend_object_handlers php_phongo_handler_maxkey;
4848

49+
/* {{{ proto MaxKey::__set_state(array $properties)
50+
*/
51+
PHP_METHOD(MaxKey, __set_state)
52+
{
53+
zval *array;
54+
55+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
56+
RETURN_FALSE;
57+
}
58+
59+
object_init_ex(return_value, php_phongo_maxkey_ce);
60+
}
61+
/* }}} */
62+
63+
/* {{{ proto MaxKey::__wakeup()
64+
*/
65+
PHP_METHOD(MaxKey, __wakeup)
66+
{
67+
zend_parse_parameters_none();
68+
}
69+
/* }}} */
70+
4971
/* {{{ BSON\MaxKey */
5072

73+
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey___set_state, 0, 0, 1)
74+
ZEND_ARG_ARRAY_INFO(0, properties, 0)
75+
ZEND_END_ARG_INFO();
76+
77+
ZEND_BEGIN_ARG_INFO_EX(ai_MaxKey_void, 0, 0, 0)
78+
ZEND_END_ARG_INFO()
5179

5280
static zend_function_entry php_phongo_maxkey_me[] = {
53-
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
81+
PHP_ME(MaxKey, __set_state, ai_MaxKey___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
82+
PHP_ME(MaxKey, __wakeup, ai_MaxKey_void, ZEND_ACC_PUBLIC)
5483
PHP_FE_END
5584
};
5685

@@ -104,7 +133,6 @@ PHP_MINIT_FUNCTION(MaxKey)
104133
php_phongo_maxkey_ce = zend_register_internal_class(&ce TSRMLS_CC);
105134
php_phongo_maxkey_ce->create_object = php_phongo_maxkey_create_object;
106135
PHONGO_CE_FINAL(php_phongo_maxkey_ce);
107-
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_maxkey_ce);
108136

109137
zend_class_implements(php_phongo_maxkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
110138
memcpy(&php_phongo_handler_maxkey, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));

src/BSON/MinKey.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,40 @@ PHONGO_API zend_class_entry *php_phongo_minkey_ce;
4646

4747
zend_object_handlers php_phongo_handler_minkey;
4848

49+
/* {{{ proto MinKey::__set_state(array $properties)
50+
*/
51+
PHP_METHOD(MinKey, __set_state)
52+
{
53+
zval *array;
54+
55+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &array) == FAILURE) {
56+
RETURN_FALSE;
57+
}
58+
59+
object_init_ex(return_value, php_phongo_minkey_ce);
60+
}
61+
/* }}} */
62+
63+
/* {{{ proto MinKey::__wakeup()
64+
*/
65+
PHP_METHOD(MinKey, __wakeup)
66+
{
67+
zend_parse_parameters_none();
68+
}
69+
/* }}} */
70+
4971
/* {{{ BSON\MinKey */
5072

73+
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey___set_state, 0, 0, 1)
74+
ZEND_ARG_ARRAY_INFO(0, properties, 0)
75+
ZEND_END_ARG_INFO();
76+
77+
ZEND_BEGIN_ARG_INFO_EX(ai_MinKey_void, 0, 0, 0)
78+
ZEND_END_ARG_INFO()
5179

5280
static zend_function_entry php_phongo_minkey_me[] = {
53-
PHP_ME(Manager, __wakeUp, NULL, ZEND_ACC_PUBLIC)
81+
PHP_ME(MinKey, __set_state, ai_MinKey___set_state, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
82+
PHP_ME(MinKey, __wakeup, ai_MinKey_void, ZEND_ACC_PUBLIC)
5483
PHP_FE_END
5584
};
5685

@@ -105,7 +134,6 @@ PHP_MINIT_FUNCTION(MinKey)
105134
php_phongo_minkey_ce = zend_register_internal_class(&ce TSRMLS_CC);
106135
php_phongo_minkey_ce->create_object = php_phongo_minkey_create_object;
107136
PHONGO_CE_FINAL(php_phongo_minkey_ce);
108-
PHONGO_CE_DISABLE_SERIALIZATION(php_phongo_minkey_ce);
109137

110138
zend_class_implements(php_phongo_minkey_ce TSRMLS_CC, 1, php_phongo_type_ce);
111139
memcpy(&php_phongo_handler_minkey, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));

tests/bson/bson-maxkey-002.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
MongoDB\BSON\MaxKey serialization
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
var_dump($maxkey = new MongoDB\BSON\MaxKey);
10+
var_dump($s = serialize($maxkey));
11+
var_dump(unserialize($s));
12+
13+
?>
14+
===DONE===
15+
<?php exit(0); ?>
16+
--EXPECTF--
17+
object(MongoDB\BSON\MaxKey)#%d (%d) {
18+
}
19+
string(31) "O:19:"MongoDB\BSON\MaxKey":0:{}"
20+
object(MongoDB\BSON\MaxKey)#%d (%d) {
21+
}
22+
===DONE===
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\BSON\MaxKey::__set_state()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
var_export(MongoDB\BSON\MaxKey::__set_state([]));
10+
echo "\n";
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
MongoDB\BSON\MaxKey::__set_state(array(
17+
))
18+
===DONE===

tests/bson/bson-maxkey_error-002.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/bson/bson-minkey-002.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
MongoDB\BSON\MinKey serialization
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
var_dump($minkey = new MongoDB\BSON\MinKey);
10+
var_dump($s = serialize($minkey));
11+
var_dump(unserialize($s));
12+
13+
?>
14+
===DONE===
15+
<?php exit(0); ?>
16+
--EXPECTF--
17+
object(MongoDB\BSON\MinKey)#%d (%d) {
18+
}
19+
string(31) "O:19:"MongoDB\BSON\MinKey":0:{}"
20+
object(MongoDB\BSON\MinKey)#%d (%d) {
21+
}
22+
===DONE===
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
MongoDB\BSON\MinKey::__set_state()
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
var_export(MongoDB\BSON\MinKey::__set_state([]));
10+
echo "\n";
11+
12+
?>
13+
===DONE===
14+
<?php exit(0); ?>
15+
--EXPECT--
16+
MongoDB\BSON\MinKey::__set_state(array(
17+
))
18+
===DONE===

tests/bson/bson-minkey_error-002.phpt

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)