Skip to content

Commit 8f39e13

Browse files
committed
PHPC-338: BSON\Regex debug handler
1 parent c2472fc commit 8f39e13

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/BSON/Regex.c

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

4545
PHONGO_API zend_class_entry *php_phongo_regex_ce;
4646

47+
zend_object_handlers php_phongo_handler_regex;
48+
4749
/* {{{ proto BSON\Regex Regex::__construct(string $pattern, string $flags)
4850
Constructs a new regular expression. */
4951
PHP_METHOD(Regex, __construct)
@@ -185,10 +187,27 @@ zend_object_value php_phongo_regex_create_object(zend_class_entry *class_type TS
185187
object_properties_init(&intern->std, class_type);
186188

187189
retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, php_phongo_regex_free_object, NULL TSRMLS_CC);
188-
retval.handlers = phongo_get_std_object_handlers();
190+
retval.handlers = &php_phongo_handler_regex;
189191

190192
return retval;
191193
} /* }}} */
194+
195+
HashTable *php_phongo_regex_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
196+
{
197+
php_phongo_regex_t *intern;
198+
zval retval = zval_used_for_init;
199+
200+
201+
*is_temp = 1;
202+
intern = (php_phongo_regex_t *)zend_object_store_get_object(object TSRMLS_CC);
203+
204+
array_init(&retval);
205+
206+
add_assoc_stringl_ex(&retval, ZEND_STRS("pattern"), intern->pattern, intern->pattern_len, 1);
207+
add_assoc_stringl_ex(&retval, ZEND_STRS("flags"), intern->flags, intern->flags_len, 1);
208+
209+
return Z_ARRVAL(retval);
210+
} /* }}} */
192211
/* }}} */
193212

194213
/* {{{ PHP_MINIT_FUNCTION */
@@ -203,6 +222,8 @@ PHP_MINIT_FUNCTION(Regex)
203222

204223
zend_class_implements(php_phongo_regex_ce TSRMLS_CC, 1, php_phongo_type_ce);
205224

225+
memcpy(&php_phongo_handler_regex, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
226+
php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info;
206227

207228
return SUCCESS;
208229
}

tests/bson/bson-regex-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\Regex 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 . '\Regex';
10+
$regex = new $classname('regexp', 'i');
11+
12+
var_dump($regex);
13+
14+
?>
15+
===DONE===
16+
<?php exit(0); ?>
17+
--EXPECTF--
18+
object(%SBSON\Regex)#%d (%d) {
19+
["pattern"]=>
20+
string(6) "regexp"
21+
["flags"]=>
22+
string(1) "i"
23+
}
24+
===DONE===

0 commit comments

Comments
 (0)