Skip to content

Commit d046827

Browse files
tmlcataphract
authored andcommitted
Added DOM Debug handler
1 parent 3960def commit d046827

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

ext/dom/php_dom.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,69 @@ static int dom_property_exists(zval *object, zval *member, int check_empty TSRML
466466
}
467467
/* }}} */
468468

469+
static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
470+
{
471+
dom_object *obj = (dom_object *)zend_object_store_get_object(object TSRMLS_CC);
472+
HashTable *debug_info, *props;
473+
HashPosition pos;
474+
dom_prop_handler *entry;
475+
476+
*is_temp = 1;
477+
478+
ALLOC_HASHTABLE(debug_info);
479+
if (! obj->prop_handler) {
480+
return debug_info;
481+
}
482+
483+
props = obj->prop_handler;
484+
ZEND_INIT_SYMTABLE_EX(debug_info, zend_hash_num_elements(props) + 1, 0);
485+
486+
zend_hash_internal_pointer_reset_ex(props, &pos);
487+
while (zend_hash_get_current_data_ex(props, (void **)&entry, &pos) == SUCCESS) {
488+
zval member;
489+
zval *value;
490+
491+
char *string_key=NULL;
492+
uint string_length=0;
493+
ulong num_key;
494+
495+
zend_hash_get_current_key_ex(props, &string_key, &string_length, &num_key, 0, &pos);
496+
497+
INIT_ZVAL(member);
498+
ZVAL_STRINGL(&member, string_key, string_length, 0);
499+
value = zend_read_property(Z_OBJCE_P(object), object, Z_STRVAL(member), Z_STRLEN(member)-1, 1 TSRMLS_CC);
500+
if (value != EG(uninitialized_zval_ptr)) {
501+
switch(Z_TYPE_P(value)) {
502+
case IS_STRING:
503+
case IS_BOOL:
504+
case IS_LONG:
505+
case IS_DOUBLE:
506+
case IS_ARRAY:
507+
zend_hash_add(debug_info, string_key, string_length, &value, sizeof(zval *), NULL);
508+
break;
509+
510+
default:
511+
ZVAL_NULL(value);
512+
zend_hash_add(debug_info, string_key, string_length, &value, sizeof(zval *), NULL);
513+
break;
514+
}
515+
} else {
516+
ZVAL_NULL(value);
517+
zend_hash_add(debug_info, string_key, string_length, &value, sizeof(zval *), NULL);
518+
}
519+
zend_hash_move_forward_ex(props, &pos);
520+
}
521+
522+
return debug_info;
523+
}
524+
/* }}} */
525+
526+
static HashTable* dom_get_debug_info(zval *object, int *is_temp TSRMLS_DC) /* {{{ */
527+
{
528+
return dom_get_debug_info_helper(object, is_temp);
529+
}
530+
/* }}} */
531+
469532
void *php_dom_export_node(zval *object TSRMLS_DC) /* {{{ */
470533
{
471534
php_libxml_node_object *intern;
@@ -586,6 +649,7 @@ PHP_MINIT_FUNCTION(dom)
586649
dom_object_handlers.get_property_ptr_ptr = dom_get_property_ptr_ptr;
587650
dom_object_handlers.clone_obj = dom_objects_store_clone_obj;
588651
dom_object_handlers.has_property = dom_property_exists;
652+
dom_object_handlers.get_debug_info = dom_get_debug_info;
589653

590654
zend_hash_init(&classes, 0, NULL, NULL, 1);
591655

0 commit comments

Comments
 (0)