Skip to content

Commit d861e01

Browse files
committed
Implement the new class hierarchy instead of HTML5Document extends DOMDocument
1 parent 4f1537d commit d861e01

File tree

125 files changed

+1468
-922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1468
-922
lines changed

ext/dom/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if test "$PHP_DOM" != "no"; then
2626
$LEXBOR_DIR/ns/ns.c \
2727
$LEXBOR_DIR/tag/tag.c"
2828
PHP_NEW_EXTENSION(dom, [php_dom.c attr.c document.c \
29-
html5_document.c html5_serializer.c html5_parser.c namespace_compat.c \
29+
xml_document.c html_document.c html5_serializer.c html5_parser.c namespace_compat.c \
3030
domexception.c parentnode.c \
3131
processinginstruction.c cdatasection.c \
3232
documentfragment.c domimplementation.c \

ext/dom/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (PHP_DOM == "yes") {
88
CHECK_HEADER_ADD_INCLUDE("libxml/parser.h", "CFLAGS_DOM", PHP_PHP_BUILD + "\\include\\libxml2")
99
) {
1010
EXTENSION("dom", "php_dom.c attr.c document.c \
11-
html5_document.c html5_serializer.c html5_parser.c namespace_compat.c \
11+
xml_document.c html_document.c html5_serializer.c html5_parser.c namespace_compat.c \
1212
domexception.c parentnode.c processinginstruction.c \
1313
cdatasection.c documentfragment.c domimplementation.c element.c \
1414
node.c characterdata.c documenttype.c \

ext/dom/document.c

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,8 @@ PHP_METHOD(DOM_Document, normalizeDocument)
10981098
}
10991099
/* }}} end dom_document_normalize_document */
11001100

1101-
void php_dom_document_constructor(INTERNAL_FUNCTION_PARAMETERS)
1101+
/* {{{ */
1102+
PHP_METHOD(DOMDocument, __construct)
11021103
{
11031104
xmlDoc *docp = NULL, *olddoc;
11041105
dom_object *intern;
@@ -1137,19 +1138,13 @@ void php_dom_document_constructor(INTERNAL_FUNCTION_PARAMETERS)
11371138
}
11381139
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)docp, (void *)intern);
11391140
}
1140-
1141-
/* {{{ */
1142-
PHP_METHOD(DOMDocument, __construct)
1143-
{
1144-
php_dom_document_constructor(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1145-
}
11461141
/* }}} end DOMDocument::__construct */
11471142

1148-
char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_path_len ) /* {{{ */
1143+
const char *_dom_get_valid_file_path(const char *source, char *resolved_path, int resolved_path_len ) /* {{{ */
11491144
{
11501145
xmlURI *uri;
11511146
xmlChar *escsource;
1152-
char *file_dest;
1147+
const char *file_dest;
11531148
int isFileUri = 0;
11541149

11551150
uri = xmlCreateURI();
@@ -1199,7 +1194,7 @@ char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_p
11991194
}
12001195
/* }}} */
12011196

1202-
static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t source_len, size_t options) /* {{{ */
1197+
xmlDocPtr dom_document_parser(zval *id, int mode, const char *source, size_t source_len, size_t options) /* {{{ */
12031198
{
12041199
xmlDocPtr ret;
12051200
xmlParserCtxtPtr ctxt = NULL;
@@ -1208,10 +1203,14 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
12081203
int old_error_reporting = 0;
12091204
char *directory=NULL, resolved_path[MAXPATHLEN + 1];
12101205

1211-
dom_object *intern = Z_DOMOBJ_P(id);
1212-
php_libxml_ref_obj *document = intern->document;
1213-
1214-
libxml_doc_props const* doc_props = dom_get_doc_props_read_only(document);
1206+
libxml_doc_props const* doc_props;
1207+
if (id == NULL) {
1208+
doc_props = dom_get_doc_props_read_only(NULL);
1209+
} else {
1210+
dom_object *intern = Z_DOMOBJ_P(id);
1211+
php_libxml_ref_obj *document = intern->document;
1212+
doc_props = dom_get_doc_props_read_only(document);
1213+
}
12151214
validate = doc_props->validateonparse;
12161215
resolve_externals = doc_props->resolveexternals;
12171216
keep_blanks = doc_props->preservewhitespace;
@@ -1221,12 +1220,11 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
12211220
xmlInitParser();
12221221

12231222
if (mode == DOM_LOAD_FILE) {
1224-
char *file_dest;
12251223
if (CHECK_NULL_PATH(source, source_len)) {
1226-
zend_value_error("Path to document must not contain any null bytes");
1224+
zend_argument_value_error(1, "must not contain any null bytes");
12271225
return NULL;
12281226
}
1229-
file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
1227+
const char *file_dest = _dom_get_valid_file_path(source, resolved_path, MAXPATHLEN);
12301228
if (file_dest) {
12311229
ctxt = xmlCreateFileParserCtxt(file_dest);
12321230
}
@@ -1312,15 +1310,15 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, size_t so
13121310
}
13131311
/* }}} */
13141312

1315-
void php_dom_finish_loading_document(zval *this, zval *return_value, xmlDocPtr newdoc)
1313+
static void php_dom_finish_loading_document(zval *this, zval *return_value, xmlDocPtr newdoc)
13161314
{
13171315
if (!newdoc)
13181316
RETURN_FALSE;
13191317

13201318
dom_object *intern = Z_DOMOBJ_P(this);
13211319
size_t old_modification_nr = 0;
13221320
if (intern != NULL) {
1323-
bool is_html5_class = intern->document->is_html5_class;
1321+
bool is_modern_api_class = intern->document->is_modern_api_class;
13241322
xmlDocPtr docp = (xmlDocPtr) dom_object_get_node(intern);
13251323
dom_doc_propsptr doc_prop = NULL;
13261324
if (docp != NULL) {
@@ -1340,7 +1338,7 @@ void php_dom_finish_loading_document(zval *this, zval *return_value, xmlDocPtr n
13401338
RETURN_FALSE;
13411339
}
13421340
intern->document->doc_props = doc_prop;
1343-
intern->document->is_html5_class = is_html5_class;
1341+
intern->document->is_modern_api_class = is_modern_api_class;
13441342
}
13451343

13461344
php_libxml_increment_node_ptr((php_libxml_node_object *)intern, (xmlNodePtr)newdoc, (void *)intern);
@@ -1354,7 +1352,8 @@ void php_dom_finish_loading_document(zval *this, zval *return_value, xmlDocPtr n
13541352
RETURN_TRUE;
13551353
}
13561354

1357-
void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode, xmlDocPtr *doc_out) {
1355+
static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode)
1356+
{
13581357
char *source;
13591358
size_t source_len;
13601359
zend_long options = 0;
@@ -1377,8 +1376,6 @@ void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode, xmlDocPtr *doc_o
13771376
}
13781377

13791378
xmlDocPtr newdoc = dom_document_parser(ZEND_THIS, mode, source, source_len, options);
1380-
*doc_out = newdoc;
1381-
13821379
php_dom_finish_loading_document(ZEND_THIS, return_value, newdoc);
13831380
}
13841381

@@ -1387,8 +1384,7 @@ Since: DOM Level 3
13871384
*/
13881385
PHP_METHOD(DOMDocument, load)
13891386
{
1390-
xmlDocPtr unused;
1391-
dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE, &unused);
1387+
dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_FILE);
13921388
}
13931389
/* }}} end dom_document_load */
13941390

@@ -1397,8 +1393,7 @@ Since: DOM Level 3
13971393
*/
13981394
PHP_METHOD(DOMDocument, loadXML)
13991395
{
1400-
xmlDocPtr unused;
1401-
dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING, &unused);
1396+
dom_parse_document(INTERNAL_FUNCTION_PARAM_PASSTHRU, DOM_LOAD_STRING);
14021397
}
14031398
/* }}} end dom_document_loadxml */
14041399

@@ -1661,7 +1656,8 @@ static void _dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type
16611656
zval *id;
16621657
xmlDoc *docp;
16631658
dom_object *intern;
1664-
char *source = NULL, *valid_file = NULL;
1659+
char *source = NULL;
1660+
const char *valid_file = NULL;
16651661
size_t source_len = 0;
16661662
int valid_opts = 0;
16671663
zend_long flags = 0;
@@ -1771,7 +1767,8 @@ static void _dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int typ
17711767
zval *id;
17721768
xmlDoc *docp;
17731769
dom_object *intern;
1774-
char *source = NULL, *valid_file = NULL;
1770+
char *source = NULL;
1771+
const char *valid_file = NULL;
17751772
size_t source_len = 0;
17761773
xmlRelaxNGParserCtxtPtr parser;
17771774
xmlRelaxNGPtr sptr;
@@ -2071,6 +2068,11 @@ PHP_METHOD(DOM_Document, registerNodeClass)
20712068
RETURN_THROWS();
20722069
}
20732070

2071+
if (basece->ce_flags & ZEND_ACC_ABSTRACT) {
2072+
zend_argument_value_error(1, "must be a non-abstract class");
2073+
RETURN_THROWS();
2074+
}
2075+
20742076
if (ce == NULL || instanceof_function(ce, basece)) {
20752077
DOM_GET_THIS_INTERN(intern);
20762078
dom_set_doc_classmap(intern->document, basece, ce);

ext/dom/dom_ce.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ extern PHP_DOM_EXPORT zend_class_entry *dom_domexception_class_entry;
2323
extern PHP_DOM_EXPORT zend_class_entry *dom_domimplementation_class_entry;
2424
extern PHP_DOM_EXPORT zend_class_entry *dom_documentfragment_class_entry;
2525
extern PHP_DOM_EXPORT zend_class_entry *dom_document_class_entry;
26-
extern PHP_DOM_EXPORT zend_class_entry *dom_html5_document_class_entry;
26+
extern PHP_DOM_EXPORT zend_class_entry *dom_html_document_class_entry;
27+
extern PHP_DOM_EXPORT zend_class_entry *dom_xml_document_class_entry;
2728
extern PHP_DOM_EXPORT zend_class_entry *dom_nodelist_class_entry;
2829
extern PHP_DOM_EXPORT zend_class_entry *dom_namednodemap_class_entry;
2930
extern PHP_DOM_EXPORT zend_class_entry *dom_characterdata_class_entry;

ext/dom/dom_properties.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ zend_result dom_document_substitue_entities_read(dom_object *obj, zval *retval);
6262
zend_result dom_document_substitue_entities_write(dom_object *obj, zval *newval);
6363

6464
/* html5 document properties */
65-
zend_result dom_html5_document_encoding_write(dom_object *obj, zval *retval);
65+
zend_result dom_html_document_encoding_write(dom_object *obj, zval *retval);
6666

6767
/* documenttype properties */
6868
zend_result dom_documenttype_name_read(dom_object *obj, zval *retval);

0 commit comments

Comments
 (0)