rrichards               Tue Nov 22 21:56:42 2005 EDT

  Modified files:              
    /php-src/ext/dom    php_dom.c document.c php_dom.h dom_fe.h 
                        xml_common.h 
  Log:
  add registerNodeClass() method
   - methods can now natively return user classes registered with document
  
http://cvs.php.net/diff.php/php-src/ext/dom/php_dom.c?r1=1.84&r2=1.85&ty=u
Index: php-src/ext/dom/php_dom.c
diff -u php-src/ext/dom/php_dom.c:1.84 php-src/ext/dom/php_dom.c:1.85
--- php-src/ext/dom/php_dom.c:1.84      Tue Nov 22 19:55:34 2005
+++ php-src/ext/dom/php_dom.c   Tue Nov 22 21:56:41 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.c,v 1.84 2005/11/23 00:55:34 rrichards Exp $ */
+/* $Id: php_dom.c,v 1.85 2005/11/23 02:56:41 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -127,12 +127,12 @@
 /* {{{ dom_get_doc_props() */
 dom_doc_propsptr dom_get_doc_props(php_libxml_ref_obj *document)
 {
-       dom_doc_props *doc_props;
+       dom_doc_propsptr doc_props;
 
        if (document && document->doc_props) {
                return document->doc_props;
        } else {
-               doc_props = emalloc(sizeof(dom_doc_props));
+               doc_props = emalloc(sizeof(libxml_doc_props));
                doc_props->formatoutput = 0;
                doc_props->validateonparse = 0;
                doc_props->resolveexternals = 0;
@@ -140,18 +140,58 @@
                doc_props->substituteentities = 0;
                doc_props->stricterror = 1;
                doc_props->recover = 0;
+               doc_props->classmap = NULL;
                if (document) {
                        document->doc_props = doc_props;
                }
                return doc_props;
        }
 }
+
+int dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry 
*basece, zend_class_entry *ce TSRMLS_DC)
+{
+       dom_doc_propsptr doc_props;
+
+       if (document) {
+               doc_props = dom_get_doc_props(document);
+               if (doc_props->classmap == NULL) {
+                       if (ce == NULL) {
+                               return SUCCESS;
+                       }
+                       ALLOC_HASHTABLE(doc_props->classmap);
+                       zend_u_hash_init(doc_props->classmap, 0, NULL, NULL, 0, 
UG(unicode));
+               }
+               if (ce) {
+                       return zend_u_hash_add(doc_props->classmap, 
UG(unicode)?IS_UNICODE:IS_STRING, basece->name, basece->name_length + 1, &ce, 
sizeof(ce), NULL);
+               } else {
+                       return zend_u_hash_del(doc_props->classmap, 
UG(unicode)?IS_UNICODE:IS_STRING, basece->name, basece->name_length + 1);
+               }
+       }
+       return SUCCESS;
+}
+
+zend_class_entry *dom_get_doc_classmap(php_libxml_ref_obj *document, 
zend_class_entry *basece TSRMLS_DC)
+{
+       dom_doc_propsptr doc_props;
+       zend_class_entry **ce = NULL;
+       
+       if (document) {
+               doc_props = dom_get_doc_props(document);
+               if (doc_props->classmap) {
+                       if (zend_u_hash_find(doc_props->classmap, 
UG(unicode)?IS_UNICODE:IS_STRING, basece->name, basece->name_length + 1,  
(void**) &ce) == SUCCESS) {
+                               return *ce;
+                       }
+               }
+       }
+
+       return basece;
+}
 /* }}} */
 
 /* {{{ dom_get_strict_error() */
 int dom_get_strict_error(php_libxml_ref_obj *document) {
        int stricterror;
-       dom_doc_props *doc_props;
+       dom_doc_propsptr doc_props;
 
        doc_props = dom_get_doc_props(document);
        stricterror = doc_props->stricterror;
@@ -1240,6 +1280,9 @@
                        return wrapper;
        }
 
+       if (domobj && domobj->document) {
+               ce = dom_get_doc_classmap(domobj->document, ce TSRMLS_CC);
+       }
        object_init_ex(wrapper, ce);
 
        intern = (dom_object *)zend_objects_get_address(wrapper TSRMLS_CC);
http://cvs.php.net/diff.php/php-src/ext/dom/document.c?r1=1.71&r2=1.72&ty=u
Index: php-src/ext/dom/document.c
diff -u php-src/ext/dom/document.c:1.71 php-src/ext/dom/document.c:1.72
--- php-src/ext/dom/document.c:1.71     Thu Sep  8 06:34:37 2005
+++ php-src/ext/dom/document.c  Tue Nov 22 21:56:41 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: document.c,v 1.71 2005/09/08 10:34:37 rrichards Exp $ */
+/* $Id: document.c,v 1.72 2005/11/23 02:56:41 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -85,6 +85,7 @@
        PHP_FALIAS(relaxNGValidate, dom_document_relaxNG_validate_file, NULL)
        PHP_FALIAS(relaxNGValidateSource, dom_document_relaxNG_validate_xml, 
NULL)
 #endif
+       PHP_ME(domdocument, registerNodeClass, NULL, ZEND_ACC_PUBLIC)
        {NULL, NULL, NULL}
 };
 
@@ -384,7 +385,7 @@
 */
 int dom_document_strict_error_checking_read(dom_object *obj, zval **retval 
TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -399,7 +400,7 @@
 int dom_document_strict_error_checking_write(dom_object *obj, zval *newval 
TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -427,7 +428,7 @@
 */
 int dom_document_format_output_read(dom_object *obj, zval **retval TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -442,7 +443,7 @@
 int dom_document_format_output_write(dom_object *obj, zval *newval TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -469,7 +470,7 @@
 */
 int    dom_document_validate_on_parse_read(dom_object *obj, zval **retval 
TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -484,7 +485,7 @@
 int dom_document_validate_on_parse_write(dom_object *obj, zval *newval 
TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -512,7 +513,7 @@
 */
 int dom_document_resolve_externals_read(dom_object *obj, zval **retval 
TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -527,7 +528,7 @@
 int dom_document_resolve_externals_write(dom_object *obj, zval *newval 
TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -555,7 +556,7 @@
 */
 int dom_document_preserve_whitespace_read(dom_object *obj, zval **retval 
TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -570,7 +571,7 @@
 int dom_document_preserve_whitespace_write(dom_object *obj, zval *newval 
TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -597,7 +598,7 @@
 */
 int dom_document_recover_read(dom_object *obj, zval **retval TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -612,7 +613,7 @@
 int dom_document_recover_write(dom_object *obj, zval *newval TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -640,7 +641,7 @@
 */
 int dom_document_substitue_entities_read(dom_object *obj, zval **retval 
TSRMLS_DC)
 {
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        ALLOC_ZVAL(*retval);
        if (obj->document) {
@@ -655,7 +656,7 @@
 int dom_document_substitue_entities_write(dom_object *obj, zval *newval 
TSRMLS_DC)
 {
        zval value_copy;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
 
        if(newval->refcount > 1) {
                value_copy = *newval;
@@ -1410,7 +1411,7 @@
 static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
options TSRMLS_DC) {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt = NULL;
-       dom_doc_props *doc_props;
+       dom_doc_propsptr doc_props;
        dom_object *intern;
        php_libxml_ref_obj *document = NULL;
        int validate, recover, resolve_externals, keep_blanks, substitute_ent;
@@ -1436,10 +1437,6 @@
 
        xmlInitParser();
 
-#if LIBXML_VERSION < 20600
-       keep_blanks = xmlKeepBlanksDefault(keep_blanks);
-#endif
-
        if (mode == DOM_LOAD_FILE) {
                char *file_dest = _dom_get_valid_file_path(source, 
resolved_path, MAXPATHLEN  TSRMLS_CC);
                if (file_dest) {
@@ -1450,14 +1447,6 @@
                ctxt = xmlCreateDocParserCtxt(source);
        }
 
-#if LIBXML_VERSION < 20600
-       xmlKeepBlanksDefault(keep_blanks);
-       /* xmlIndentTreeOutput default is changed in xmlKeepBlanksDefault
-       reset back to 1 which is default value */
-
-       xmlIndentTreeOutput = 1;
-#endif
-
        if (ctxt == NULL) {
                return(NULL);
        }
@@ -1490,7 +1479,6 @@
                ctxt->sax->warning = php_libxml_ctx_warning;
        }
 
-#if LIBXML_VERSION >= 20600
        if (validate && ! (options & XML_PARSE_DTDVALID)) {
                options |= XML_PARSE_DTDVALID;
        }
@@ -1505,11 +1493,6 @@
        }
 
        xmlCtxtUseOptions(ctxt, options);
-#else
-       ctxt->validate = validate;
-    ctxt->loadsubset = (resolve_externals * XML_COMPLETE_ATTRS);
-       ctxt->replaceEntities = substitute_ent;
-#endif
 
        ctxt->recovery = recover;
        if (recover) {
@@ -1544,7 +1527,7 @@
 static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
        zval *id, *rv = NULL;
        xmlDoc *docp = NULL, *newdoc;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
        dom_object *intern;
        char *source;
        int source_len, refcount, ret;
@@ -1626,7 +1609,7 @@
        xmlDoc *docp;
        int file_len = 0, bytes, format, saveempty;
        dom_object *intern;
-       dom_doc_props *doc_props;
+       dom_doc_propsptr doc_props;
        char *file;
        long options = 0;
 
@@ -1672,7 +1655,7 @@
        xmlBufferPtr buf;
        xmlChar *mem;
        dom_object *intern, *nodeobj;
-       dom_doc_props *doc_props;
+       dom_doc_propsptr doc_props;
        int size, format, saveempty;
        long options = 0;
 
@@ -1781,11 +1764,7 @@
 
        DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
 
-#if LIBXML_VERSION >= 20607
        err = xmlXIncludeProcessFlags(docp, flags);
-#else
-       err = xmlXIncludeProcess (docp);
-#endif
 
        /* XML_XINCLUDE_START and XML_XINCLUDE_END nodes need to be removed as 
these
        are added via xmlXIncludeProcess to mark beginning and ending of 
xincluded document 
@@ -2034,7 +2013,7 @@
        zval *id, *rv = NULL;
        xmlDoc *docp = NULL, *newdoc;
        dom_object *intern;
-       dom_doc_props *doc_prop;
+       dom_doc_propsptr doc_prop;
        char *source;
        int source_len, refcount, ret;
        htmlParserCtxtPtr ctxt;
@@ -2128,7 +2107,7 @@
        xmlDoc *docp;
        int file_len, bytes, format;
        dom_object *intern;
-       dom_doc_props *doc_props;
+       dom_doc_propsptr doc_props;
        char *file;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Os", &id, U_CLASS_ENTRY(dom_document_class_entry), &file, &file_len) == 
FAILURE) {
@@ -2185,4 +2164,58 @@
 
 #endif  /* defined(LIBXML_HTML_ENABLED) */
 
+/* {{{ proto boolean DOMDocument::registerNodeClass(string baseclass, string 
extendedclass);
+   Register extended class used to create base node type */
+PHP_METHOD(domdocument, registerNodeClass)
+{
+       zval *id;
+       xmlDoc *docp;
+       char *baseclass = NULL, *extendedclass = NULL;
+       int baseclass_len = 0, extendedclass_len = 0;
+       zend_class_entry *basece = NULL, *ce = NULL;
+       dom_object *intern;
+       zend_uchar type1, type2;
+
+       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"Oss!", &id, U_CLASS_ENTRY(dom_document_class_entry), &baseclass, 
&baseclass_len, &extendedclass, &extendedclass_len) == FAILURE) {
+               return;
+       }
+
+       if (baseclass_len) {
+               zend_class_entry **pce;
+               if (zend_lookup_class(baseclass, baseclass_len, &pce TSRMLS_CC) 
== FAILURE) {
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s 
does not exist", baseclass);
+                       return;
+               }
+               basece = *pce;
+       }
+
+       if (basece == NULL || ! instanceof_function(basece, 
U_CLASS_ENTRY(dom_node_class_entry) TSRMLS_CC)) {
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s is not 
derived from DOMNode.", baseclass);
+               return;
+       }
+
+       if (extendedclass_len) {
+               zend_class_entry **pce;
+               if (zend_lookup_class(extendedclass, extendedclass_len, &pce 
TSRMLS_CC) == FAILURE) {
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s 
does not exist", extendedclass);
+               }
+               ce = *pce;
+       }
+
+       if (ce == NULL || instanceof_function(ce, basece TSRMLS_CC)) {
+
+               DOM_GET_OBJ(docp, id, xmlDocPtr, intern);
+
+               if (dom_set_doc_classmap(intern->document, basece, ce 
TSRMLS_CC) == FAILURE) {
+                       php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s 
could not be registered.", extendedclass);
+               }
+               RETURN_TRUE;
+       } else {
+               php_error_docref(NULL TSRMLS_CC, E_ERROR, "Class %s is not 
derived from %s.", extendedclass, baseclass);
+       }
+
+       RETURN_FALSE;
+}
+/* }}} */
+
 #endif  /* HAVE_LIBXML && HAVE_DOM */
http://cvs.php.net/diff.php/php-src/ext/dom/php_dom.h?r1=1.29&r2=1.30&ty=u
Index: php-src/ext/dom/php_dom.h
diff -u php-src/ext/dom/php_dom.h:1.29 php-src/ext/dom/php_dom.h:1.30
--- php-src/ext/dom/php_dom.h:1.29      Thu Aug 11 19:35:53 2005
+++ php-src/ext/dom/php_dom.h   Tue Nov 22 21:56:41 2005
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.h,v 1.29 2005/08/11 23:35:53 andrei Exp $ */
+/* $Id: php_dom.h,v 1.30 2005/11/23 02:56:41 rrichards Exp $ */
 
 #ifndef PHP_DOM_H
 #define PHP_DOM_H
@@ -110,6 +110,7 @@
 xmlNode *php_dom_libxml_hash_iter(xmlHashTable *ht, int index);
 xmlNode *php_dom_libxml_notation_iter(xmlHashTable *ht, int index);
 zend_object_iterator *php_dom_get_iterator(zend_class_entry *ce, zval *object 
TSRMLS_DC);
+int dom_set_doc_classmap(php_libxml_ref_obj *document, zend_class_entry 
*basece, zend_class_entry *ce TSRMLS_DC);
 
 #define REGISTER_DOM_CLASS(ce, name, parent_ce, funcs, entry) \
 INIT_CLASS_ENTRY(ce, name, funcs); \
http://cvs.php.net/diff.php/php-src/ext/dom/dom_fe.h?r1=1.14&r2=1.15&ty=u
Index: php-src/ext/dom/dom_fe.h
diff -u php-src/ext/dom/dom_fe.h:1.14 php-src/ext/dom/dom_fe.h:1.15
--- php-src/ext/dom/dom_fe.h:1.14       Wed Aug  3 10:07:01 2005
+++ php-src/ext/dom/dom_fe.h    Tue Nov 22 21:56:41 2005
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dom_fe.h,v 1.14 2005/08/03 14:07:01 sniper Exp $ */
+/* $Id: dom_fe.h,v 1.15 2005/11/23 02:56:41 rrichards Exp $ */
 #ifndef DOM_FE_H
 #define DOM_FE_H
 
@@ -130,6 +130,7 @@
 PHP_FUNCTION(dom_document_savexml);
 PHP_FUNCTION(dom_document_validate);
 PHP_FUNCTION(dom_document_xinclude);
+PHP_METHOD(domdocument, registerNodeClass);
 
 #if defined(LIBXML_HTML_ENABLED)
 PHP_METHOD(domdocument, loadHTML);
http://cvs.php.net/diff.php/php-src/ext/dom/xml_common.h?r1=1.23&r2=1.24&ty=u
Index: php-src/ext/dom/xml_common.h
diff -u php-src/ext/dom/xml_common.h:1.23 php-src/ext/dom/xml_common.h:1.24
--- php-src/ext/dom/xml_common.h:1.23   Wed Aug  3 10:07:06 2005
+++ php-src/ext/dom/xml_common.h        Tue Nov 22 21:56:41 2005
@@ -17,24 +17,14 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: xml_common.h,v 1.23 2005/08/03 14:07:06 sniper Exp $ */
+/* $Id: xml_common.h,v 1.24 2005/11/23 02:56:41 rrichards Exp $ */
 
 #ifndef PHP_XML_COMMON_H
 #define PHP_XML_COMMON_H
 
 #include "ext/libxml/php_libxml.h"
 
-typedef struct _dom_doc_props {
-       int formatoutput;
-       int validateonparse;
-       int resolveexternals;
-       int preservewhitespace;
-       int substituteentities;
-       int stricterror;
-       int recover;
-} dom_doc_props;
-
-typedef dom_doc_props *dom_doc_propsptr;
+typedef libxml_doc_props *dom_doc_propsptr;
 
 typedef struct _dom_object {
        zend_object  std;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to