]> granicus.if.org Git - php/commitdiff
constructors throw DOMException
authorRob Richards <rrichards@php.net>
Sun, 16 May 2004 10:30:16 +0000 (10:30 +0000)
committerRob Richards <rrichards@php.net>
Sun, 16 May 2004 10:30:16 +0000 (10:30 +0000)
add DOM_PHP_ERR DomException code
validate tagnames in constructors
use C style comments
update TODO

13 files changed:
ext/dom/TODO
ext/dom/attr.c
ext/dom/cdatasection.c
ext/dom/comment.c
ext/dom/document.c
ext/dom/documentfragment.c
ext/dom/dom_fe.h
ext/dom/element.c
ext/dom/entityreference.c
ext/dom/php_dom.c
ext/dom/processinginstruction.c
ext/dom/text.c
ext/dom/xpath.c

index f6b7fe2e61e311de4a426659fb4e8c40a372c449..52afb18216e10501f0e0c0d9b678219733e0f148 100644 (file)
@@ -1,12 +1,4 @@
-1) Change _node_list_pointer to something faster than just a linked list.
-       Currently there to test that unlinked node tracking works
-2) Possible create new object type for documents as these are the only types which need to track nodes
-       - Would also require its own dtor functionality
-3) Define correct behavior. When certain types of nodes are destroyed, 
-       do we unlink children (if referenced) or just destroy them. (Element/Attribute nodes)
-4) Find out where XPath goes (this extension or its own)
-5) What DOM object types are really needed (i.e. not currently using DOMString)
-6) Determine how to handle non speced functionality.
-       i.e validation (add method or implement as property for processing)
-
-
+For 5.1
+1) enhance XPath functionality
+2) look at auto encoding support for in/output
+3) What DOM object types are really needed (i.e. not currently using DOMString)
index aa9f158e563b8ff45f1d4674228ecbbd610886c7..b574b1abec9ba1a80e1c403b52e6c41d7340865b 100644 (file)
@@ -52,23 +52,29 @@ PHP_METHOD(domattr, __construct)
        xmlNodePtr oldnode = NULL;
        dom_object *intern;
        char *name, *value = NULL;
-       int name_len, value_len;
+       int name_len, value_len, name_valid;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_attr_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
 
-       if (name_len == 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attribute name is required");
+       name_valid = xmlValidateName((xmlChar *) name, 0);
+       if (name_valid != 0) {
+               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
        }
 
        nodep = xmlNewProp(NULL, (xmlChar *) name, value);
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        if (intern != NULL) {
                oldnode = (xmlNodePtr)intern->ptr;
index 0dc18a935834f887c7f625af6b3d7cb77a27ee98..fde9ea5670951864b230506900b53ce8bbed17cc 100644 (file)
@@ -50,14 +50,19 @@ PHP_METHOD(domcdatasection, __construct)
        char *value = NULL;
        int value_len;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_cdatasection_class_entry, &value, &value_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        nodep = xmlNewCDataBlock(NULL, (xmlChar *) value, value_len);
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL) {
index a5d3b9c55bacd153437386f83047cf6eb9d61302..be921a8fad5816cb2618cb86bff8481472770a25 100644 (file)
@@ -50,14 +50,19 @@ PHP_METHOD(domcomment, __construct)
        char *value = NULL;
        int value_len;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|s", &id, dom_comment_class_entry, &value, &value_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        nodep = xmlNewComment((xmlChar *) value);
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL) {
index 427e7114477929d9b0d925c5863138dabebaef7c..5dbfaa8f3c1c254a7592de9ac6ec2df515a6702b 100644 (file)
@@ -740,7 +740,7 @@ int dom_document_config_read(dom_object *obj, zval **retval TSRMLS_DC)
 
 
 
-/* {{{ proto domelement dom_document_create_element(string tagName);
+/* {{{ proto domelement dom_document_create_element(string tagName [, string value]);
 URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#core-ID-2141741547
 Since: 
 */
@@ -1296,13 +1296,19 @@ PHP_METHOD(domdocument, __construct)
        char *encoding, *version = NULL;
        int encoding_len = 0, version_len = 0, refcount;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|ss", &id, dom_document_class_entry, &version, &version_len, &encoding, &encoding_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        docp = xmlNewDoc(version);
-       if (!docp)
+
+       if (!docp) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        if (encoding_len > 0) {
                docp->encoding = (const xmlChar*)xmlStrdup(encoding);
index 3b565c4efd2f994745911ce3d3beb5a0006eab79..d47fd725e698d0f4f4159986af58599592b58f5d 100644 (file)
@@ -48,14 +48,19 @@ PHP_METHOD(domdocumentfragment, __construct)
        xmlNodePtr nodep = NULL, oldnode = NULL;
        dom_object *intern;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_documentfragment_class_entry) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        nodep = xmlNewDocFragment(NULL);
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL) {
index 511708a0a143b5d75b2baa586a9a71eb37729b04..3d860a54bea16a0d012db80e4233b22997cebf06 100644 (file)
@@ -54,6 +54,8 @@ extern zend_function_entry php_dom_xpath_class_functions[];
 
 /* domexception errors */
 typedef enum {
+/* PHP_ERR is non-spec code for PHP errors: */
+       PHP_ERR                        = 0,
        INDEX_SIZE_ERR                 = 1,
        DOMSTRING_SIZE_ERR             = 2,
        HIERARCHY_REQUEST_ERR          = 3,
@@ -64,17 +66,17 @@ typedef enum {
        NOT_FOUND_ERR                  = 8,
        NOT_SUPPORTED_ERR              = 9,
        INUSE_ATTRIBUTE_ERR            = 10,
-// Introduced in DOM Level 2:
+/* Introduced in DOM Level 2: */
        INVALID_STATE_ERR              = 11,
-// Introduced in DOM Level 2:
+/* Introduced in DOM Level 2: */
        SYNTAX_ERR                     = 12,
-// Introduced in DOM Level 2:
+/* Introduced in DOM Level 2: */
        INVALID_MODIFICATION_ERR       = 13,
-// Introduced in DOM Level 2:
+/* Introduced in DOM Level 2: */
        NAMESPACE_ERR                  = 14,
-// Introduced in DOM Level 2:
+/* Introduced in DOM Level 2: */
        INVALID_ACCESS_ERR             = 15,
-// Introduced in DOM Level 3:
+/* Introduced in DOM Level 3: */
        VALIDATION_ERR                 = 16
 } dom_exception_code;
 
index 944c9c946e7c61fa5b532b72bfba792cb571880d..c817a3c01e20cde43370acfa5733e1b9efaa17fa 100644 (file)
@@ -68,15 +68,19 @@ PHP_METHOD(domelement, __construct)
        char *name, *value = NULL, *uri = NULL;
        char *localname = NULL, *prefix = NULL;
        int errorcode = 0, uri_len = 0;
-       int name_len, value_len = 0;
+       int name_len, value_len = 0, name_valid;
        xmlNsPtr nsptr = NULL;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s!s", &id, dom_element_class_entry, &name, &name_len, &value, &value_len, &uri, &uri_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
-       if (name_len == 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Element name is required");
+       php_std_error_handling();
+       name_valid = xmlValidateName((xmlChar *) name, 0);
+       if (name_valid != 0) {
+               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
        }
 
@@ -98,15 +102,17 @@ PHP_METHOD(domelement, __construct)
                        if (nodep != NULL) {
                                xmlFree(nodep);
                        }
-                       php_dom_throw_error(errorcode, 0 TSRMLS_CC);
+                       php_dom_throw_error(errorcode, 1 TSRMLS_CC);
                        RETURN_FALSE;
                }
        } else {
                nodep = xmlNewNode(NULL, (xmlChar *) name);
        }
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        if (value_len > 0) {
                xmlNodeSetContentLen(nodep, value, value_len);
index b44da01a8e5ceaf5636c33809b933a60e3739e72..4ac617d27750c137211ea3997ecd5db7b10ddd65 100644 (file)
@@ -50,19 +50,24 @@ PHP_METHOD(domentityreference, __construct)
        char *name;
        int name_len;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_entityreference_class_entry, &name, &name_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        if (name_len == 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Entity Reference name is required");
+               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
        }
 
        node = xmlNewReference(NULL, name);
 
-       if (!node)
+       if (!node) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL) {
index d11e2d67f81b94eeee60a3bc2aa8011e4aa5848c..8e60238af3435a38971597ee1f74536788239132 100644 (file)
@@ -624,7 +624,8 @@ PHP_MINIT_FUNCTION(dom)
        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_ENUMERATION",     XML_ATTRIBUTE_ENUMERATION,      CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("XML_ATTRIBUTE_NOTATION",        XML_ATTRIBUTE_NOTATION,         CONST_CS | CONST_PERSISTENT);
 
-       /* domException Codes */
+       /* DOMException Codes */
+       REGISTER_LONG_CONSTANT("DOM_PHP_ERR",                           PHP_ERR,                                CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DOM_INDEX_SIZE_ERR",            INDEX_SIZE_ERR,                 CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DOMSTRING_SIZE_ERR",            DOMSTRING_SIZE_ERR,             CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DOM_HIERARCHY_REQUEST_ERR",     HIERARCHY_REQUEST_ERR,  CONST_CS | CONST_PERSISTENT);
index 70cf83035c5f7738570d9640c69e600475406adc..b0b4cb275b41f127863628de4c55ba0eebe6d182 100644 (file)
@@ -50,19 +50,24 @@ PHP_METHOD(domprocessinginstruction, __construct)
        char *name, *value = NULL;
        int name_len, value_len;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|s", &id, dom_processinginstruction_class_entry, &name, &name_len, &value, &value_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        if (name_len == 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "PI name is required");
+               php_dom_throw_error(INVALID_CHARACTER_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
        }
 
        nodep = xmlNewPI((xmlChar *) name, (xmlChar *) value);
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL) {
index 78fd7feafe3fd3951b2c939bf5379f4685b7de6b..e3c4f05a3c82acacc50789a4dd89c7cd9d640f21 100644 (file)
@@ -53,14 +53,19 @@ PHP_METHOD(domtext, __construct)
        char *value = NULL;
        int value_len;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|s", &id, dom_text_class_entry, &value, &value_len) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        nodep = xmlNewText((xmlChar *) value);
 
-       if (!nodep)
+       if (!nodep) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
+       }
 
        intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
        if (intern != NULL) {
index e4e22c0a41cc473b6f42c837c114dbdf0fbfb9da..9f0f59cc0df67086bd228ead99f609c34432d469 100644 (file)
@@ -49,14 +49,18 @@ PHP_METHOD(domxpath, __construct)
        dom_object *docobj, *intern;
        xmlXPathContextPtr ctx, oldctx;
 
+       php_set_error_handling(EH_THROW, dom_domexception_class_entry TSRMLS_CC);
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "OO", &id, dom_xpath_class_entry, &doc, dom_document_class_entry) == FAILURE) {
+               php_std_error_handling();
                return;
        }
 
+       php_std_error_handling();
        DOM_GET_OBJ(docp, doc, xmlDocPtr, docobj);
 
        ctx = xmlXPathNewContext(docp);
        if (ctx == NULL) {
+               php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
                RETURN_FALSE;
        }