Skip to content

Commit 02cb37f

Browse files
committed
PHPC-339: BSON\Timestamp debug handler
1 parent 57871d1 commit 02cb37f

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/BSON/Timestamp.c

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

4545
PHONGO_API zend_class_entry *php_phongo_timestamp_ce;
4646

47+
zend_object_handlers php_phongo_handler_timestamp;
48+
4749
/* {{{ proto BSON\Timestamp Timestamp::__construct(integer $increment, int $timestamp)
4850
Construct a new BSON Timestamp (4bytes increment, 4bytes timestamp) */
4951
PHP_METHOD(Timestamp, __construct)
@@ -129,10 +131,27 @@ zend_object_value php_phongo_timestamp_create_object(zend_class_entry *class_typ
129131
object_properties_init(&intern->std, class_type);
130132

131133
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_timestamp_free_object, NULL TSRMLS_CC);
132-
retval.handlers = phongo_get_std_object_handlers();
134+
retval.handlers = &php_phongo_handler_timestamp;
133135

134136
return retval;
135137
} /* }}} */
138+
139+
HashTable *php_phongo_timestamp_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
140+
{
141+
php_phongo_timestamp_t *intern;
142+
zval retval = zval_used_for_init;
143+
144+
145+
*is_temp = 1;
146+
intern = (php_phongo_timestamp_t *)zend_object_store_get_object(object TSRMLS_CC);
147+
148+
array_init(&retval);
149+
150+
add_assoc_long_ex(&retval, ZEND_STRS("increment"), intern->increment);
151+
add_assoc_long_ex(&retval, ZEND_STRS("timestamp"), intern->timestamp);
152+
153+
return Z_ARRVAL(retval);
154+
} /* }}} */
136155
/* }}} */
137156

138157
/* {{{ PHP_MINIT_FUNCTION */
@@ -147,6 +166,9 @@ PHP_MINIT_FUNCTION(Timestamp)
147166

148167
zend_class_implements(php_phongo_timestamp_ce TSRMLS_CC, 1, php_phongo_type_ce);
149168

169+
memcpy(&php_phongo_handler_timestamp, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
170+
php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info;
171+
150172

151173
return SUCCESS;
152174
}

tests/bson/bson-timestamp-002.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
BSON BSON\Timestamp debug handler
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$classname = BSON_NAMESPACE . '\Timestamp';
10+
$timestamp = new $classname(1234, 5678);
11+
12+
var_dump($timestamp);
13+
14+
?>
15+
===DONE===
16+
<?php exit(0); ?>
17+
--EXPECTF--
18+
object(%SBSON\Timestamp)#%d (%d) {
19+
["increment"]=>
20+
int(1234)
21+
["timestamp"]=>
22+
int(5678)
23+
}
24+
===DONE===

0 commit comments

Comments
 (0)