Skip to content

Commit 802e2ae

Browse files
committed
PHPC-336: BSON\Binary debug handler
1 parent 914aaba commit 802e2ae

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/BSON/Binary.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444

4545
PHONGO_API zend_class_entry *php_phongo_binary_ce;
4646

47+
zend_object_handlers php_phongo_handler_binary;
48+
4749
/* {{{ proto BSON\Binary Binary::__construct(string $data, int $subtype)
4850
Construct a new BSON Binary type */
4951
PHP_METHOD(Binary, __construct)
@@ -152,10 +154,25 @@ zend_object_value php_phongo_binary_create_object(zend_class_entry *class_type T
152154
object_properties_init(&intern->std, class_type);
153155

154156
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_binary_free_object, NULL TSRMLS_CC);
155-
retval.handlers = phongo_get_std_object_handlers();
157+
retval.handlers = &php_phongo_handler_binary;
156158

157159
return retval;
158160
} /* }}} */
161+
162+
HashTable *php_phongo_binary_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
163+
{
164+
php_phongo_binary_t *intern;
165+
zval retval = zval_used_for_init;
166+
167+
intern = (php_phongo_binary_t *)zend_object_store_get_object(object TSRMLS_CC);
168+
*is_temp = 1;
169+
array_init_size(&retval, 2);
170+
171+
add_assoc_stringl_ex(&retval, ZEND_STRS("data"), intern->data, intern->data_len, 1);
172+
add_assoc_long_ex(&retval, ZEND_STRS("subtype"), intern->subtype);
173+
174+
return Z_ARRVAL(retval);
175+
} /* }}} */
159176
/* }}} */
160177

161178
/* {{{ PHP_MINIT_FUNCTION */
@@ -170,6 +187,9 @@ PHP_MINIT_FUNCTION(Binary)
170187

171188
zend_class_implements(php_phongo_binary_ce TSRMLS_CC, 1, php_phongo_type_ce);
172189

190+
memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
191+
php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info;
192+
173193
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_GENERIC"), BSON_SUBTYPE_BINARY TSRMLS_CC);
174194
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_FUNCTION"), BSON_SUBTYPE_FUNCTION TSRMLS_CC);
175195
zend_declare_class_constant_long(php_phongo_binary_ce, ZEND_STRL("TYPE_OLD_BINARY"), BSON_SUBTYPE_BINARY_DEPRECATED TSRMLS_CC);

tests/bson/bson-encode-003.phpt

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ object(stdClass)#%d (1) {
5959
["props"]=>
6060
array(3) {
6161
["__pclass"]=>
62-
object(%sBSON\Binary)#%d (0) {
62+
object(%sBSON\Binary)#%d (2) {
63+
["data"]=>
64+
string(7) "MyClass"
65+
["subtype"]=>
66+
int(128)
6367
}
6468
["random"]=>
6569
string(5) "class"
@@ -79,7 +83,11 @@ object(stdClass)#%d (1) {
7983
["props"]=>
8084
array(4) {
8185
["__pclass"]=>
82-
object(%sBSON\Binary)#%d (0) {
86+
object(%sBSON\Binary)#%d (2) {
87+
["data"]=>
88+
string(8) "MyClass2"
89+
["subtype"]=>
90+
int(128)
8391
}
8492
[0]=>
8593
int(1)
@@ -108,7 +116,11 @@ object(stdClass)#%d (1) {
108116
["props"]=>
109117
array(3) {
110118
["__pclass"]=>
111-
object(%sBSON\Binary)#%d (0) {
119+
object(%sBSON\Binary)#%d (2) {
120+
["data"]=>
121+
string(7) "MyClass"
122+
["subtype"]=>
123+
int(128)
112124
}
113125
["random"]=>
114126
string(5) "class"
@@ -121,7 +133,11 @@ object(stdClass)#%d (1) {
121133
["props"]=>
122134
array(4) {
123135
["__pclass"]=>
124-
object(%sBSON\Binary)#%d (0) {
136+
object(%sBSON\Binary)#%d (2) {
137+
["data"]=>
138+
string(8) "MyClass2"
139+
["subtype"]=>
140+
int(128)
125141
}
126142
[0]=>
127143
int(1)

0 commit comments

Comments
 (0)