summaryrefslogtreecommitdiff
path: root/ext/dom/php_dom.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/dom/php_dom.c')
-rw-r--r--ext/dom/php_dom.c222
1 files changed, 102 insertions, 120 deletions
diff --git a/ext/dom/php_dom.c b/ext/dom/php_dom.c
index 726b74b934..dae52faeeb 100644
--- a/ext/dom/php_dom.c
+++ b/ext/dom/php_dom.c
@@ -1,7 +1,5 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 7 |
- +----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
@@ -26,6 +24,7 @@
#if HAVE_LIBXML && HAVE_DOM
#include "ext/standard/php_rand.h"
#include "php_dom.h"
+#include "dom_arginfo.h"
#include "dom_properties.h"
#include "zend_interfaces.h"
@@ -36,10 +35,8 @@
/* {{{ class entries */
PHP_DOM_EXPORT zend_class_entry *dom_node_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_domexception_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domstringlist_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_namelist_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domimplementationlist_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domimplementationsource_class_entry;
+PHP_DOM_EXPORT zend_class_entry *dom_parentnode_class_entry;
+PHP_DOM_EXPORT zend_class_entry *dom_childnode_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_domimplementation_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_documentfragment_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_document_class_entry;
@@ -50,19 +47,12 @@ PHP_DOM_EXPORT zend_class_entry *dom_attr_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_element_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_text_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_comment_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_typeinfo_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_userdatahandler_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domerror_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domerrorhandler_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domlocator_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_domconfiguration_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_cdatasection_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_documenttype_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_notation_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_entity_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_entityreference_class_entry;
PHP_DOM_EXPORT zend_class_entry *dom_processinginstruction_class_entry;
-PHP_DOM_EXPORT zend_class_entry *dom_string_extend_class_entry;
#if defined(LIBXML_XPATH_ENABLED)
PHP_DOM_EXPORT zend_class_entry *dom_xpath_class_entry;
#endif
@@ -77,10 +67,8 @@ zend_object_handlers dom_xpath_object_handlers;
static HashTable classes;
/* {{{ prop handler tables */
-static HashTable dom_domstringlist_prop_handlers;
-static HashTable dom_namelist_prop_handlers;
-static HashTable dom_domimplementationlist_prop_handlers;
static HashTable dom_document_prop_handlers;
+static HashTable dom_documentfragment_prop_handlers;
static HashTable dom_node_prop_handlers;
static HashTable dom_nodelist_prop_handlers;
static HashTable dom_namednodemap_prop_handlers;
@@ -88,9 +76,6 @@ static HashTable dom_characterdata_prop_handlers;
static HashTable dom_attr_prop_handlers;
static HashTable dom_element_prop_handlers;
static HashTable dom_text_prop_handlers;
-static HashTable dom_typeinfo_prop_handlers;
-static HashTable dom_domerror_prop_handlers;
-static HashTable dom_domlocator_prop_handlers;
static HashTable dom_documenttype_prop_handlers;
static HashTable dom_notation_prop_handlers;
static HashTable dom_entity_prop_handlers;
@@ -310,31 +295,27 @@ static void dom_register_prop_handler(HashTable *prop_handler, char *name, size_
}
/* }}} */
-static zval *dom_get_property_ptr_ptr(zval *object, zval *member, int type, void **cache_slot) /* {{{ */
+static zval *dom_get_property_ptr_ptr(zend_object *object, zend_string *name, int type, void **cache_slot) /* {{{ */
{
- dom_object *obj = Z_DOMOBJ_P(object);
- zend_string *member_str = zval_get_string(member);
+ dom_object *obj = php_dom_obj_from_obj(object);
zval *retval = NULL;
- if (!obj->prop_handler || !zend_hash_exists(obj->prop_handler, member_str)) {
- retval = zend_std_get_property_ptr_ptr(object, member, type, cache_slot);
+ if (!obj->prop_handler || !zend_hash_exists(obj->prop_handler, name)) {
+ retval = zend_std_get_property_ptr_ptr(object, name, type, cache_slot);
}
-
- zend_string_release_ex(member_str, 0);
return retval;
}
/* }}} */
/* {{{ dom_read_property */
-zval *dom_read_property(zval *object, zval *member, int type, void **cache_slot, zval *rv)
+zval *dom_read_property(zend_object *object, zend_string *name, int type, void **cache_slot, zval *rv)
{
- dom_object *obj = Z_DOMOBJ_P(object);
- zend_string *member_str = zval_get_string(member);
+ dom_object *obj = php_dom_obj_from_obj(object);
zval *retval;
dom_prop_handler *hnd = NULL;
if (obj->prop_handler != NULL) {
- hnd = zend_hash_find_ptr(obj->prop_handler, member_str);
+ hnd = zend_hash_find_ptr(obj->prop_handler, name);
} else if (instanceof_function(obj->std.ce, dom_node_class_entry)) {
php_error(E_WARNING, "Couldn't fetch %s. Node no longer exists", ZSTR_VAL(obj->std.ce->name));
}
@@ -347,46 +328,41 @@ zval *dom_read_property(zval *object, zval *member, int type, void **cache_slot,
retval = &EG(uninitialized_zval);
}
} else {
- retval = zend_std_read_property(object, member, type, cache_slot, rv);
+ retval = zend_std_read_property(object, name, type, cache_slot, rv);
}
- zend_string_release_ex(member_str, 0);
return retval;
}
/* }}} */
/* {{{ dom_write_property */
-zval *dom_write_property(zval *object, zval *member, zval *value, void **cache_slot)
+zval *dom_write_property(zend_object *object, zend_string *name, zval *value, void **cache_slot)
{
- dom_object *obj = Z_DOMOBJ_P(object);
- zend_string *member_str = zval_get_string(member);
+ dom_object *obj = php_dom_obj_from_obj(object);
dom_prop_handler *hnd = NULL;
if (obj->prop_handler != NULL) {
- hnd = zend_hash_find_ptr(obj->prop_handler, member_str);
+ hnd = zend_hash_find_ptr(obj->prop_handler, name);
}
if (hnd) {
hnd->write_func(obj, value);
} else {
- value = zend_std_write_property(object, member, value, cache_slot);
+ value = zend_std_write_property(object, name, value, cache_slot);
}
- zend_string_release_ex(member_str, 0);
-
return value;
}
/* }}} */
/* {{{ dom_property_exists */
-static int dom_property_exists(zval *object, zval *member, int check_empty, void **cache_slot)
+static int dom_property_exists(zend_object *object, zend_string *name, int check_empty, void **cache_slot)
{
- dom_object *obj = Z_DOMOBJ_P(object);
- zend_string *member_str = zval_get_string(member);
+ dom_object *obj = php_dom_obj_from_obj(object);
dom_prop_handler *hnd = NULL;
int retval = 0;
if (obj->prop_handler != NULL) {
- hnd = zend_hash_find_ptr(obj->prop_handler, member_str);
+ hnd = zend_hash_find_ptr(obj->prop_handler, name);
}
if (hnd) {
zval tmp;
@@ -402,17 +378,16 @@ static int dom_property_exists(zval *object, zval *member, int check_empty, void
zval_ptr_dtor(&tmp);
}
} else {
- retval = zend_std_has_property(object, member, check_empty, cache_slot);
+ retval = zend_std_has_property(object, name, check_empty, cache_slot);
}
- zend_string_release_ex(member_str, 0);
return retval;
}
/* }}} */
-static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp) /* {{{ */
+static HashTable* dom_get_debug_info_helper(zend_object *object, int *is_temp) /* {{{ */
{
- dom_object *obj = Z_DOMOBJ_P(object);
+ dom_object *obj = php_dom_obj_from_obj(object);
HashTable *debug_info,
*prop_handlers = obj->prop_handler,
*std_props;
@@ -453,7 +428,7 @@ static HashTable* dom_get_debug_info_helper(zval *object, int *is_temp) /* {{{ *
}
/* }}} */
-static HashTable* dom_get_debug_info(zval *object, int *is_temp) /* {{{ */
+static HashTable* dom_get_debug_info(zend_object *object, int *is_temp) /* {{{ */
{
return dom_get_debug_info_helper(object, is_temp);
}
@@ -483,7 +458,7 @@ PHP_FUNCTION(dom_import_simplexml)
int ret;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &node) == FAILURE) {
- return;
+ RETURN_THROWS();
}
nodeobj = (php_libxml_node_object *) ((char *) Z_OBJ_P(node) - Z_OBJ_HT_P(node)->offset);
@@ -500,9 +475,9 @@ PHP_FUNCTION(dom_import_simplexml)
static dom_object* dom_objects_set_class(zend_class_entry *class_type);
-static zend_object *dom_objects_store_clone_obj(zval *zobject) /* {{{ */
+static zend_object *dom_objects_store_clone_obj(zend_object *zobject) /* {{{ */
{
- dom_object *intern = Z_DOMOBJ_P(zobject);
+ dom_object *intern = php_dom_obj_from_obj(zobject);
dom_object *clone = dom_objects_set_class(intern->std.ce);
clone->std.handlers = dom_get_obj_handlers();
@@ -545,12 +520,6 @@ static void dom_dtor_prop_handler(zval *zv) /* {{{ */
free(Z_PTR_P(zv));
}
-/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_import_simplexml, 0, 0, 1)
- ZEND_ARG_INFO(0, node)
-ZEND_END_ARG_INFO()
-/* }}} */
-
static const zend_function_entry dom_functions[] = {
PHP_FE(dom_import_simplexml, arginfo_dom_import_simplexml)
PHP_FE_END
@@ -583,7 +552,9 @@ ZEND_GET_MODULE(dom)
void dom_objects_free_storage(zend_object *object);
void dom_nnodemap_objects_free_storage(zend_object *object);
-static zend_object *dom_objects_store_clone_obj(zval *zobject);
+static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int type, zval *rv);
+static int dom_nodelist_has_dimension(zend_object *object, zval *member, int check_empty);
+static zend_object *dom_objects_store_clone_obj(zend_object *zobject);
static void dom_nnodemap_object_dtor(zend_object *object);
#if defined(LIBXML_XPATH_ENABLED)
void dom_xpath_objects_free_storage(zend_object *object);
@@ -617,25 +588,12 @@ PHP_MINIT_FUNCTION(dom)
dom_domexception_class_entry->ce_flags |= ZEND_ACC_FINAL;
zend_declare_property_long(dom_domexception_class_entry, "code", sizeof("code")-1, 0, ZEND_ACC_PUBLIC);
- REGISTER_DOM_CLASS(ce, "DOMStringList", NULL, php_dom_domstringlist_class_functions, dom_domstringlist_class_entry);
-
- zend_hash_init(&dom_domstringlist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
- dom_register_prop_handler(&dom_domstringlist_prop_handlers, "length", sizeof("length")-1, dom_domstringlist_length_read, NULL);
- zend_hash_add_ptr(&classes, ce.name, &dom_domstringlist_prop_handlers);
+ INIT_CLASS_ENTRY(ce, "DOMParentNode", php_dom_parent_node_class_functions);
+ dom_parentnode_class_entry = zend_register_internal_interface(&ce);
- REGISTER_DOM_CLASS(ce, "DOMNameList", NULL, php_dom_namelist_class_functions, dom_namelist_class_entry);
+ INIT_CLASS_ENTRY(ce, "DOMChildNode", php_dom_child_node_class_functions);
+ dom_childnode_class_entry = zend_register_internal_interface(&ce);
- zend_hash_init(&dom_namelist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
- dom_register_prop_handler(&dom_namelist_prop_handlers, "length", sizeof("length")-1, dom_namelist_length_read, NULL);
- zend_hash_add_ptr(&classes, ce.name, &dom_namelist_prop_handlers);
-
- REGISTER_DOM_CLASS(ce, "DOMImplementationList", NULL, php_dom_domimplementationlist_class_functions, dom_domimplementationlist_class_entry);
-
- zend_hash_init(&dom_domimplementationlist_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
- dom_register_prop_handler(&dom_domimplementationlist_prop_handlers, "length", sizeof("length")-1, dom_domimplementationlist_length_read, NULL);
- zend_hash_add_ptr(&classes, ce.name, &dom_domimplementationlist_prop_handlers);
-
- REGISTER_DOM_CLASS(ce, "DOMImplementationSource", NULL, php_dom_domimplementationsource_class_functions, dom_domimplementationsource_class_entry);
REGISTER_DOM_CLASS(ce, "DOMImplementation", NULL, php_dom_domimplementation_class_functions, dom_domimplementation_class_entry);
REGISTER_DOM_CLASS(ce, "DOMNode", NULL, php_dom_node_class_functions, dom_node_class_entry);
@@ -673,7 +631,15 @@ PHP_MINIT_FUNCTION(dom)
zend_hash_add_ptr(&classes, ce.name, &dom_namespace_node_prop_handlers);
REGISTER_DOM_CLASS(ce, "DOMDocumentFragment", dom_node_class_entry, php_dom_documentfragment_class_functions, dom_documentfragment_class_entry);
- zend_hash_add_ptr(&classes, ce.name, &dom_node_prop_handlers);
+ zend_hash_init(&dom_documentfragment_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
+
+ dom_register_prop_handler(&dom_documentfragment_prop_handlers, "firstElementChild", sizeof("firstElementChild")-1, dom_parent_node_first_element_child_read, NULL);
+ dom_register_prop_handler(&dom_documentfragment_prop_handlers, "lastElementChild", sizeof("lastElementChild")-1, dom_parent_node_last_element_child_read, NULL);
+ dom_register_prop_handler(&dom_documentfragment_prop_handlers, "childElementCount", sizeof("childElementCount")-1, dom_parent_node_child_element_count, NULL);
+
+ zend_hash_merge(&dom_documentfragment_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
+ zend_hash_add_ptr(&classes, ce.name, &dom_documentfragment_prop_handlers);
+ zend_class_implements(dom_documentfragment_class_entry, 1, dom_parentnode_class_entry);
REGISTER_DOM_CLASS(ce, "DOMDocument", dom_node_class_entry, php_dom_document_class_functions, dom_document_class_entry);
zend_hash_init(&dom_document_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
@@ -697,8 +663,13 @@ PHP_MINIT_FUNCTION(dom)
dom_register_prop_handler(&dom_document_prop_handlers, "recover", sizeof("recover")-1, dom_document_recover_read, dom_document_recover_write);
dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", sizeof("substituteEntities")-1, dom_document_substitue_entities_read, dom_document_substitue_entities_write);
+ dom_register_prop_handler(&dom_document_prop_handlers, "firstElementChild", sizeof("firstElementChild")-1, dom_parent_node_first_element_child_read, NULL);
+ dom_register_prop_handler(&dom_document_prop_handlers, "lastElementChild", sizeof("lastElementChild")-1, dom_parent_node_last_element_child_read, NULL);
+ dom_register_prop_handler(&dom_document_prop_handlers, "childElementCount", sizeof("childElementCount")-1, dom_parent_node_child_element_count, NULL);
+
zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
zend_hash_add_ptr(&classes, ce.name, &dom_document_prop_handlers);
+ zend_class_implements(dom_document_class_entry, 1, dom_parentnode_class_entry);
INIT_CLASS_ENTRY(ce, "DOMNodeList", php_dom_nodelist_class_functions);
ce.create_object = dom_nnodemap_objects_new;
@@ -725,9 +696,13 @@ PHP_MINIT_FUNCTION(dom)
zend_hash_init(&dom_characterdata_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
dom_register_prop_handler(&dom_characterdata_prop_handlers, "data", sizeof("data")-1, dom_characterdata_data_read, dom_characterdata_data_write);
dom_register_prop_handler(&dom_characterdata_prop_handlers, "length", sizeof("length")-1, dom_characterdata_length_read, NULL);
+ dom_register_prop_handler(&dom_characterdata_prop_handlers, "previousElementSibling", sizeof("previousElementSibling")-1, dom_node_previous_element_sibling_read, NULL);
+ dom_register_prop_handler(&dom_characterdata_prop_handlers, "nextElementSibling", sizeof("nextElementSibling")-1, dom_node_next_element_sibling_read, NULL);
zend_hash_merge(&dom_characterdata_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
zend_hash_add_ptr(&classes, ce.name, &dom_characterdata_prop_handlers);
+ zend_class_implements(dom_characterdata_class_entry, 1, dom_childnode_class_entry);
+
REGISTER_DOM_CLASS(ce, "DOMAttr", dom_node_class_entry, php_dom_attr_class_functions, dom_attr_class_entry);
zend_hash_init(&dom_attr_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
@@ -744,9 +719,16 @@ PHP_MINIT_FUNCTION(dom)
zend_hash_init(&dom_element_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
dom_register_prop_handler(&dom_element_prop_handlers, "tagName", sizeof("tagName")-1, dom_element_tag_name_read, NULL);
dom_register_prop_handler(&dom_element_prop_handlers, "schemaTypeInfo", sizeof("schemaTypeInfo")-1, dom_element_schema_type_info_read, NULL);
+ dom_register_prop_handler(&dom_element_prop_handlers, "firstElementChild", sizeof("firstElementChild")-1, dom_parent_node_first_element_child_read, NULL);
+ dom_register_prop_handler(&dom_element_prop_handlers, "lastElementChild", sizeof("lastElementChild")-1, dom_parent_node_last_element_child_read, NULL);
+ dom_register_prop_handler(&dom_element_prop_handlers, "childElementCount", sizeof("childElementCount")-1, dom_parent_node_child_element_count, NULL);
+ dom_register_prop_handler(&dom_element_prop_handlers, "previousElementSibling", sizeof("previousElementSibling")-1, dom_node_previous_element_sibling_read, NULL);
+ dom_register_prop_handler(&dom_element_prop_handlers, "nextElementSibling", sizeof("nextElementSibling")-1, dom_node_next_element_sibling_read, NULL);
zend_hash_merge(&dom_element_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
zend_hash_add_ptr(&classes, ce.name, &dom_element_prop_handlers);
+ zend_class_implements(dom_element_class_entry, 2, dom_parentnode_class_entry, dom_childnode_class_entry);
+
REGISTER_DOM_CLASS(ce, "DOMText", dom_characterdata_class_entry, php_dom_text_class_functions, dom_text_class_entry);
zend_hash_init(&dom_text_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
@@ -757,37 +739,6 @@ PHP_MINIT_FUNCTION(dom)
REGISTER_DOM_CLASS(ce, "DOMComment", dom_characterdata_class_entry, php_dom_comment_class_functions, dom_comment_class_entry);
zend_hash_add_ptr(&classes, ce.name, &dom_characterdata_prop_handlers);
- REGISTER_DOM_CLASS(ce, "DOMTypeinfo", NULL, php_dom_typeinfo_class_functions, dom_typeinfo_class_entry);
-
- zend_hash_init(&dom_typeinfo_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
- dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeName", sizeof("typeName")-1, dom_typeinfo_type_name_read, NULL);
- dom_register_prop_handler(&dom_typeinfo_prop_handlers, "typeNamespace", sizeof("typeNamespace")-1, dom_typeinfo_type_namespace_read, NULL);
- zend_hash_add_ptr(&classes, ce.name, &dom_typeinfo_prop_handlers);
-
- REGISTER_DOM_CLASS(ce, "DOMUserDataHandler", NULL, php_dom_userdatahandler_class_functions, dom_userdatahandler_class_entry);
- REGISTER_DOM_CLASS(ce, "DOMDomError", NULL, php_dom_domerror_class_functions, dom_domerror_class_entry);
-
- zend_hash_init(&dom_domerror_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
- dom_register_prop_handler(&dom_domerror_prop_handlers, "severity", sizeof("severity")-1, dom_domerror_severity_read, NULL);
- dom_register_prop_handler(&dom_domerror_prop_handlers, "message", sizeof("message")-1, dom_domerror_message_read, NULL);
- dom_register_prop_handler(&dom_domerror_prop_handlers, "type", sizeof("type")-1, dom_domerror_type_read, NULL);
- dom_register_prop_handler(&dom_domerror_prop_handlers, "relatedException", sizeof("relatedException")-1, dom_domerror_related_exception_read, NULL);
- dom_register_prop_handler(&dom_domerror_prop_handlers, "related_data", sizeof("related_data")-1, dom_domerror_related_data_read, NULL);
- dom_register_prop_handler(&dom_domerror_prop_handlers, "location", sizeof("location")-1, dom_domerror_location_read, NULL);
- zend_hash_add_ptr(&classes, ce.name, &dom_domerror_prop_handlers);
-
- REGISTER_DOM_CLASS(ce, "DOMErrorHandler", NULL, php_dom_domerrorhandler_class_functions, dom_domerrorhandler_class_entry);
- REGISTER_DOM_CLASS(ce, "DOMLocator", NULL, php_dom_domlocator_class_functions, dom_domlocator_class_entry);
-
- zend_hash_init(&dom_domlocator_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
- dom_register_prop_handler(&dom_domlocator_prop_handlers, "lineNumber", sizeof("lineNumber")-1, dom_domlocator_line_number_read, NULL);
- dom_register_prop_handler(&dom_domlocator_prop_handlers, "columnNumber", sizeof("columnNumber")-1, dom_domlocator_column_number_read, NULL);
- dom_register_prop_handler(&dom_domlocator_prop_handlers, "offset", sizeof("offset")-1, dom_domlocator_offset_read, NULL);
- dom_register_prop_handler(&dom_domlocator_prop_handlers, "relatedNode", sizeof("relatedNode")-1, dom_domlocator_related_node_read, NULL);
- dom_register_prop_handler(&dom_domlocator_prop_handlers, "uri", sizeof("uri")-1, dom_domlocator_uri_read, NULL);
- zend_hash_add_ptr(&classes, ce.name, &dom_domlocator_prop_handlers);
-
- REGISTER_DOM_CLASS(ce, "DOMConfiguration", NULL, php_dom_domconfiguration_class_functions, dom_domconfiguration_class_entry);
REGISTER_DOM_CLASS(ce, "DOMCdataSection", dom_text_class_entry, php_dom_cdatasection_class_functions, dom_cdatasection_class_entry);
zend_hash_add_ptr(&classes, ce.name, &dom_text_prop_handlers);
@@ -834,8 +785,6 @@ PHP_MINIT_FUNCTION(dom)
zend_hash_merge(&dom_processinginstruction_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
zend_hash_add_ptr(&classes, ce.name, &dom_processinginstruction_prop_handlers);
- REGISTER_DOM_CLASS(ce, "DOMStringExtend", NULL, php_dom_string_extend_class_functions, dom_string_extend_class_entry);
-
#if defined(LIBXML_XPATH_ENABLED)
memcpy(&dom_xpath_object_handlers, &dom_object_handlers, sizeof(zend_object_handlers));
dom_xpath_object_handlers.offset = XtOffsetOf(dom_xpath_object, dom) + XtOffsetOf(dom_object, std);
@@ -847,6 +796,7 @@ PHP_MINIT_FUNCTION(dom)
zend_hash_init(&dom_xpath_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
dom_register_prop_handler(&dom_xpath_prop_handlers, "document", sizeof("document")-1, dom_xpath_document_read, NULL);
+ dom_register_prop_handler(&dom_xpath_prop_handlers, "registerNodeNamespaces", sizeof("registerNodeNamespaces")-1, dom_xpath_register_node_ns_read, dom_xpath_register_node_ns_write);
zend_hash_add_ptr(&classes, ce.name, &dom_xpath_prop_handlers);
#endif
@@ -933,10 +883,8 @@ PHP_MINFO_FUNCTION(dom)
PHP_MSHUTDOWN_FUNCTION(dom) /* {{{ */
{
- zend_hash_destroy(&dom_domstringlist_prop_handlers);
- zend_hash_destroy(&dom_namelist_prop_handlers);
- zend_hash_destroy(&dom_domimplementationlist_prop_handlers);
zend_hash_destroy(&dom_document_prop_handlers);
+ zend_hash_destroy(&dom_documentfragment_prop_handlers);
zend_hash_destroy(&dom_node_prop_handlers);
zend_hash_destroy(&dom_namespace_node_prop_handlers);
zend_hash_destroy(&dom_nodelist_prop_handlers);
@@ -945,9 +893,6 @@ PHP_MSHUTDOWN_FUNCTION(dom) /* {{{ */
zend_hash_destroy(&dom_attr_prop_handlers);
zend_hash_destroy(&dom_element_prop_handlers);
zend_hash_destroy(&dom_text_prop_handlers);
- zend_hash_destroy(&dom_typeinfo_prop_handlers);
- zend_hash_destroy(&dom_domerror_prop_handlers);
- zend_hash_destroy(&dom_domlocator_prop_handlers);
zend_hash_destroy(&dom_documenttype_prop_handlers);
zend_hash_destroy(&dom_notation_prop_handlers);
zend_hash_destroy(&dom_entity_prop_handlers);
@@ -1102,6 +1047,7 @@ zend_object *dom_xpath_objects_new(zend_class_entry *class_type)
dom_xpath_object *intern = zend_object_alloc(sizeof(dom_xpath_object), class_type);
intern->registered_phpfunctions = zend_new_array(0);
+ intern->register_node_ns = 1;
intern->dom.prop_handler = &dom_xpath_prop_handlers;
intern->dom.std.handlers = &dom_xpath_object_handlers;
@@ -1169,7 +1115,7 @@ zend_object *dom_nnodemap_objects_new(zend_class_entry *class_type) /* {{{ */
}
/* }}} */
-void php_dom_create_interator(zval *return_value, int ce_type) /* {{{ */
+void php_dom_create_iterator(zval *return_value, int ce_type) /* {{{ */
{
zend_class_entry *ce;
@@ -1432,6 +1378,38 @@ void dom_set_old_ns(xmlDoc *doc, xmlNs *ns) {
}
/* }}} end dom_set_old_ns */
+void dom_reconcile_ns(xmlDocPtr doc, xmlNodePtr nodep) /* {{{ */
+{
+ xmlNsPtr nsptr, nsdftptr, curns, prevns = NULL;
+
+ if (nodep->type == XML_ELEMENT_NODE) {
+ /* Following if block primarily used for inserting nodes created via createElementNS */
+ if (nodep->nsDef != NULL) {
+ curns = nodep->nsDef;
+ while (curns) {
+ nsdftptr = curns->next;
+ if (curns->href != NULL) {
+ if((nsptr = xmlSearchNsByHref(doc, nodep->parent, curns->href)) &&
+ (curns->prefix == NULL || xmlStrEqual(nsptr->prefix, curns->prefix))) {
+ curns->next = NULL;
+ if (prevns == NULL) {
+ nodep->nsDef = nsdftptr;
+ } else {
+ prevns->next = nsdftptr;
+ }
+ dom_set_old_ns(doc, curns);
+ curns = prevns;
+ }
+ }
+ prevns = curns;
+ curns = nsdftptr;
+ }
+ }
+ xmlReconciliateNs(doc, nodep);
+ }
+}
+/* }}} */
+
/*
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-DocCrElNS
@@ -1530,22 +1508,23 @@ xmlNsPtr dom_get_nsdecl(xmlNode *node, xmlChar *localName) {
}
/* }}} end dom_get_nsdecl */
-zval *dom_nodelist_read_dimension(zval *object, zval *offset, int type, zval *rv) /* {{{ */
+static zval *dom_nodelist_read_dimension(zend_object *object, zval *offset, int type, zval *rv) /* {{{ */
{
zval offset_copy;
if (!offset) {
+ zend_throw_error(NULL, "Cannot access node list without offset");
return NULL;
}
ZVAL_LONG(&offset_copy, zval_get_long(offset));
- zend_call_method_with_1_params(object, Z_OBJCE_P(object), NULL, "item", rv, &offset_copy);
+ zend_call_method_with_1_params(object, object->ce, NULL, "item", rv, &offset_copy);
return rv;
} /* }}} end dom_nodelist_read_dimension */
-int dom_nodelist_has_dimension(zval *object, zval *member, int check_empty)
+static int dom_nodelist_has_dimension(zend_object *object, zval *member, int check_empty)
{
zend_long offset = zval_get_long(member);
zval rv;
@@ -1553,8 +1532,11 @@ int dom_nodelist_has_dimension(zval *object, zval *member, int check_empty)
if (offset < 0) {
return 0;
} else {
- zval *length = zend_read_property(Z_OBJCE_P(object), object, "length", sizeof("length") - 1, 0, &rv);
+ zval obj;
+ zval *length;
+ ZVAL_OBJ(&obj, object);
+ length = zend_read_property(object->ce, &obj, "length", sizeof("length") - 1, 0, &rv);
return length && offset < Z_LVAL_P(length);
}
} /* }}} end dom_nodelist_has_dimension */