Skip to content

Commit 26c9dc3

Browse files
committed
Register prop handlers in common base class
1 parent cdaf7b8 commit 26c9dc3

File tree

5 files changed

+56
-51
lines changed

5 files changed

+56
-51
lines changed

ext/dom/php_dom.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -698,23 +698,30 @@ PHP_MINIT_FUNCTION(dom)
698698
zend_hash_add_ptr(&classes, dom_documentfragment_class_entry->name, &dom_documentfragment_prop_handlers);
699699

700700
dom_abstract_base_document_class_entry = register_class_DOM_Document(dom_node_class_entry, dom_parentnode_class_entry);
701-
// TODO: prop handlers
701+
/* No need to set create_object as it's abstract. */
702+
HashTable dom_abstract_base_document_prop_handlers;
703+
zend_hash_init(&dom_abstract_base_document_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
704+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "doctype", sizeof("doctype")-1, dom_document_doctype_read, NULL);
705+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "implementation", sizeof("implementation")-1, dom_document_implementation_read, NULL);
706+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "documentElement", sizeof("documentElement")-1, dom_document_document_element_read, NULL);
707+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "strictErrorChecking", sizeof("strictErrorChecking")-1, dom_document_strict_error_checking_read, dom_document_strict_error_checking_write);
708+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "documentURI", sizeof("documentURI")-1, dom_document_document_uri_read, dom_document_document_uri_write);
709+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "firstElementChild", sizeof("firstElementChild")-1, dom_parent_node_first_element_child_read, NULL);
710+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "lastElementChild", sizeof("lastElementChild")-1, dom_parent_node_last_element_child_read, NULL);
711+
dom_register_prop_handler(&dom_abstract_base_document_prop_handlers, "childElementCount", sizeof("childElementCount")-1, dom_parent_node_child_element_count, NULL);
712+
zend_hash_merge(&dom_abstract_base_document_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
713+
/* No need to register in &classes, because this is only used for merging. This is destroyed down below. */
702714

703715
dom_document_class_entry = register_class_DOMDocument(dom_abstract_base_document_class_entry);
704716
dom_document_class_entry->create_object = dom_objects_new;
705717
zend_hash_init(&dom_document_prop_handlers, 0, NULL, dom_dtor_prop_handler, 1);
706-
dom_register_prop_handler(&dom_document_prop_handlers, "doctype", sizeof("doctype")-1, dom_document_doctype_read, NULL);
707-
dom_register_prop_handler(&dom_document_prop_handlers, "implementation", sizeof("implementation")-1, dom_document_implementation_read, NULL);
708-
dom_register_prop_handler(&dom_document_prop_handlers, "documentElement", sizeof("documentElement")-1, dom_document_document_element_read, NULL);
709718
dom_register_prop_handler(&dom_document_prop_handlers, "actualEncoding", sizeof("actualEncoding")-1, dom_document_encoding_read, NULL);
710719
dom_register_prop_handler(&dom_document_prop_handlers, "encoding", sizeof("encoding")-1, dom_document_encoding_read, dom_document_encoding_write);
711720
dom_register_prop_handler(&dom_document_prop_handlers, "xmlEncoding", sizeof("xmlEncoding")-1, dom_document_encoding_read, NULL);
712721
dom_register_prop_handler(&dom_document_prop_handlers, "standalone", sizeof("standalone")-1, dom_document_standalone_read, dom_document_standalone_write);
713722
dom_register_prop_handler(&dom_document_prop_handlers, "xmlStandalone", sizeof("xmlStandalone")-1, dom_document_standalone_read, dom_document_standalone_write);
714723
dom_register_prop_handler(&dom_document_prop_handlers, "version", sizeof("version")-1, dom_document_version_read, dom_document_version_write);
715724
dom_register_prop_handler(&dom_document_prop_handlers, "xmlVersion", sizeof("xmlVersion")-1, dom_document_version_read, dom_document_version_write);
716-
dom_register_prop_handler(&dom_document_prop_handlers, "strictErrorChecking", sizeof("strictErrorChecking")-1, dom_document_strict_error_checking_read, dom_document_strict_error_checking_write);
717-
dom_register_prop_handler(&dom_document_prop_handlers, "documentURI", sizeof("documentURI")-1, dom_document_document_uri_read, dom_document_document_uri_write);
718725
dom_register_prop_handler(&dom_document_prop_handlers, "config", sizeof("config")-1, dom_document_config_read, NULL);
719726
dom_register_prop_handler(&dom_document_prop_handlers, "formatOutput", sizeof("formatOutput")-1, dom_document_format_output_read, dom_document_format_output_write);
720727
dom_register_prop_handler(&dom_document_prop_handlers, "validateOnParse", sizeof("validateOnParse")-1, dom_document_validate_on_parse_read, dom_document_validate_on_parse_write);
@@ -723,11 +730,7 @@ PHP_MINIT_FUNCTION(dom)
723730
dom_register_prop_handler(&dom_document_prop_handlers, "recover", sizeof("recover")-1, dom_document_recover_read, dom_document_recover_write);
724731
dom_register_prop_handler(&dom_document_prop_handlers, "substituteEntities", sizeof("substituteEntities")-1, dom_document_substitue_entities_read, dom_document_substitue_entities_write);
725732

726-
dom_register_prop_handler(&dom_document_prop_handlers, "firstElementChild", sizeof("firstElementChild")-1, dom_parent_node_first_element_child_read, NULL);
727-
dom_register_prop_handler(&dom_document_prop_handlers, "lastElementChild", sizeof("lastElementChild")-1, dom_parent_node_last_element_child_read, NULL);
728-
dom_register_prop_handler(&dom_document_prop_handlers, "childElementCount", sizeof("childElementCount")-1, dom_parent_node_child_element_count, NULL);
729-
730-
zend_hash_merge(&dom_document_prop_handlers, &dom_node_prop_handlers, dom_copy_prop_handler, 0);
733+
zend_hash_merge(&dom_document_prop_handlers, &dom_abstract_base_document_prop_handlers, dom_copy_prop_handler, 0);
731734
zend_hash_add_ptr(&classes, dom_document_class_entry->name, &dom_document_prop_handlers);
732735

733736
dom_html5_document_class_entry = register_class_DOM_HTML5Document(dom_document_class_entry);
@@ -737,6 +740,8 @@ PHP_MINIT_FUNCTION(dom)
737740
zend_hash_merge(&dom_html5_document_prop_handlers, &dom_document_prop_handlers, dom_copy_prop_handler, 0);
738741
zend_hash_add_ptr(&classes, dom_html5_document_class_entry->name, &dom_html5_document_prop_handlers);
739742

743+
zend_hash_destroy(&dom_abstract_base_document_prop_handlers);
744+
740745
dom_nodelist_class_entry = register_class_DOMNodeList(zend_ce_aggregate, zend_ce_countable);
741746
dom_nodelist_class_entry->create_object = dom_nnodemap_objects_new;
742747
dom_nodelist_class_entry->default_object_handlers = &dom_nodelist_object_handlers;

ext/dom/tests/HTML5/interactions/Document_node_ownerDocument_for_XML.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ var_dump($element->ownerDocument);
1717
object(DOM\HTML5Document)#1 (40) {
1818
["encoding"]=>
1919
NULL
20-
["doctype"]=>
21-
NULL
22-
["implementation"]=>
23-
string(22) "(object value omitted)"
24-
["documentElement"]=>
25-
string(22) "(object value omitted)"
2620
["actualEncoding"]=>
2721
NULL
2822
["xmlEncoding"]=>
@@ -35,10 +29,6 @@ object(DOM\HTML5Document)#1 (40) {
3529
string(3) "1.0"
3630
["xmlVersion"]=>
3731
string(3) "1.0"
38-
["strictErrorChecking"]=>
39-
bool(true)
40-
["documentURI"]=>
41-
string(%d) %s
4232
["config"]=>
4333
NULL
4434
["formatOutput"]=>
@@ -53,6 +43,16 @@ object(DOM\HTML5Document)#1 (40) {
5343
bool(false)
5444
["substituteEntities"]=>
5545
bool(false)
46+
["doctype"]=>
47+
NULL
48+
["implementation"]=>
49+
string(22) "(object value omitted)"
50+
["documentElement"]=>
51+
string(22) "(object value omitted)"
52+
["strictErrorChecking"]=>
53+
bool(true)
54+
["documentURI"]=>
55+
string(%d) "%s"
5656
["firstElementChild"]=>
5757
string(22) "(object value omitted)"
5858
["lastElementChild"]=>

ext/dom/tests/HTML5/interactions/Document_should_retain_properties_and_owner_01.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ var_dump($dom->strictErrorChecking);
2525
object(DOM\HTML5Document)#1 (40) {
2626
["encoding"]=>
2727
string(5) "UTF-8"
28-
["doctype"]=>
29-
NULL
30-
["implementation"]=>
31-
string(22) "(object value omitted)"
32-
["documentElement"]=>
33-
string(22) "(object value omitted)"
3428
["actualEncoding"]=>
3529
string(5) "UTF-8"
3630
["xmlEncoding"]=>
@@ -43,10 +37,6 @@ object(DOM\HTML5Document)#1 (40) {
4337
NULL
4438
["xmlVersion"]=>
4539
NULL
46-
["strictErrorChecking"]=>
47-
bool(false)
48-
["documentURI"]=>
49-
NULL
5040
["config"]=>
5141
NULL
5242
["formatOutput"]=>
@@ -61,6 +51,16 @@ object(DOM\HTML5Document)#1 (40) {
6151
bool(false)
6252
["substituteEntities"]=>
6353
bool(false)
54+
["doctype"]=>
55+
NULL
56+
["implementation"]=>
57+
string(22) "(object value omitted)"
58+
["documentElement"]=>
59+
string(22) "(object value omitted)"
60+
["strictErrorChecking"]=>
61+
bool(false)
62+
["documentURI"]=>
63+
NULL
6464
["firstElementChild"]=>
6565
string(22) "(object value omitted)"
6666
["lastElementChild"]=>

ext/dom/tests/HTML5/interactions/Document_should_retain_properties_and_owner_02.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ var_dump($dom->strictErrorChecking);
2424
object(DOM\HTML5Document)#1 (40) {
2525
["encoding"]=>
2626
NULL
27-
["doctype"]=>
28-
NULL
29-
["implementation"]=>
30-
string(22) "(object value omitted)"
31-
["documentElement"]=>
32-
string(22) "(object value omitted)"
3327
["actualEncoding"]=>
3428
NULL
3529
["xmlEncoding"]=>
@@ -42,10 +36,6 @@ object(DOM\HTML5Document)#1 (40) {
4236
string(3) "1.0"
4337
["xmlVersion"]=>
4438
string(3) "1.0"
45-
["strictErrorChecking"]=>
46-
bool(false)
47-
["documentURI"]=>
48-
NULL
4939
["config"]=>
5040
NULL
5141
["formatOutput"]=>
@@ -60,6 +50,16 @@ object(DOM\HTML5Document)#1 (40) {
6050
bool(false)
6151
["substituteEntities"]=>
6252
bool(false)
53+
["doctype"]=>
54+
NULL
55+
["implementation"]=>
56+
string(22) "(object value omitted)"
57+
["documentElement"]=>
58+
string(22) "(object value omitted)"
59+
["strictErrorChecking"]=>
60+
bool(false)
61+
["documentURI"]=>
62+
NULL
6363
["firstElementChild"]=>
6464
string(22) "(object value omitted)"
6565
["lastElementChild"]=>

ext/dom/tests/domobject_debug_handler.phpt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ object(DOMDocument)#1 (41) {
2020
["dynamicProperty"]=>
2121
object(stdClass)#2 (0) {
2222
}
23-
["doctype"]=>
24-
NULL
25-
["implementation"]=>
26-
string(22) "(object value omitted)"
27-
["documentElement"]=>
28-
string(22) "(object value omitted)"
2923
["actualEncoding"]=>
3024
NULL
3125
["encoding"]=>
@@ -40,10 +34,6 @@ object(DOMDocument)#1 (41) {
4034
string(3) "1.0"
4135
["xmlVersion"]=>
4236
string(3) "1.0"
43-
["strictErrorChecking"]=>
44-
bool(true)
45-
["documentURI"]=>
46-
string(%d) %s
4737
["config"]=>
4838
NULL
4939
["formatOutput"]=>
@@ -58,6 +48,16 @@ object(DOMDocument)#1 (41) {
5848
bool(false)
5949
["substituteEntities"]=>
6050
bool(false)
51+
["doctype"]=>
52+
NULL
53+
["implementation"]=>
54+
string(22) "(object value omitted)"
55+
["documentElement"]=>
56+
string(22) "(object value omitted)"
57+
["strictErrorChecking"]=>
58+
bool(true)
59+
["documentURI"]=>
60+
string(%d) "%s"
6161
["firstElementChild"]=>
6262
string(22) "(object value omitted)"
6363
["lastElementChild"]=>

0 commit comments

Comments
 (0)