rrichards               Mon May 22 17:12:26 2006 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/dom/tests      regsiter_node_class.phpt 

  Modified files:              
    /php-src/ext/dom    attr.c document.c dom_fe.h php_dom.c php_dom.h 
                        xml_common.h 
  Log:
  MFH: add registerNodeClass() method
   - update attribute isID functionality
   - add test
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/dom/attr.c?r1=1.18.2.2&r2=1.18.2.2.2.1&diff_format=u
Index: php-src/ext/dom/attr.c
diff -u php-src/ext/dom/attr.c:1.18.2.2 php-src/ext/dom/attr.c:1.18.2.2.2.1
--- php-src/ext/dom/attr.c:1.18.2.2     Wed May  3 08:43:04 2006
+++ php-src/ext/dom/attr.c      Mon May 22 17:12:25 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: attr.c,v 1.18.2.2 2006/05/03 08:43:04 rrichards Exp $ */
+/* $Id: attr.c,v 1.18.2.2.2.1 2006/05/22 17:12:25 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -262,7 +262,6 @@
        zval *id;
        dom_object *intern;
        xmlAttrPtr attrp;
-       xmlNodePtr nodep;
 
        if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), 
"O", &id, dom_attr_class_entry) == FAILURE) {
                return;
@@ -270,9 +269,7 @@
 
        DOM_GET_OBJ(attrp, id, xmlAttrPtr, intern);
 
-       nodep = attrp->parent;
-
-       if (xmlIsID(attrp->doc, nodep, attrp)) {
+       if (attrp->atype == XML_ATTRIBUTE_ID) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;
http://cvs.php.net/viewcvs.cgi/php-src/ext/dom/document.c?r1=1.68.2.3&r2=1.68.2.3.2.1&diff_format=u
Index: php-src/ext/dom/document.c
diff -u php-src/ext/dom/document.c:1.68.2.3 
php-src/ext/dom/document.c:1.68.2.3.2.1
--- php-src/ext/dom/document.c:1.68.2.3 Sun Jan  1 12:50:06 2006
+++ php-src/ext/dom/document.c  Mon May 22 17:12:25 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: document.c,v 1.68.2.3 2006/01/01 12:50:06 sniper Exp $ */
+/* $Id: document.c,v 1.68.2.3.2.1 2006/05/22 17:12:25 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, 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, 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, 
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/viewcvs.cgi/php-src/ext/dom/dom_fe.h?r1=1.14.2.1&r2=1.14.2.1.2.1&diff_format=u
Index: php-src/ext/dom/dom_fe.h
diff -u php-src/ext/dom/dom_fe.h:1.14.2.1 php-src/ext/dom/dom_fe.h:1.14.2.1.2.1
--- php-src/ext/dom/dom_fe.h:1.14.2.1   Sun Jan  1 12:50:06 2006
+++ php-src/ext/dom/dom_fe.h    Mon May 22 17:12:25 2006
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dom_fe.h,v 1.14.2.1 2006/01/01 12:50:06 sniper Exp $ */
+/* $Id: dom_fe.h,v 1.14.2.1.2.1 2006/05/22 17:12:25 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/viewcvs.cgi/php-src/ext/dom/php_dom.c?r1=1.73.2.12.2.3&r2=1.73.2.12.2.4&diff_format=u
Index: php-src/ext/dom/php_dom.c
diff -u php-src/ext/dom/php_dom.c:1.73.2.12.2.3 
php-src/ext/dom/php_dom.c:1.73.2.12.2.4
--- php-src/ext/dom/php_dom.c:1.73.2.12.2.3     Wed May 17 16:35:50 2006
+++ php-src/ext/dom/php_dom.c   Mon May 22 17:12:25 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.c,v 1.73.2.12.2.3 2006/05/17 16:35:50 rrichards Exp $ */
+/* $Id: php_dom.c,v 1.73.2.12.2.4 2006/05/22 17:12:25 rrichards Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -148,12 +148,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;
@@ -161,18 +161,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_hash_init(doc_props->classmap, 0, NULL, NULL, 0);
+               }
+               if (ce) {
+                       return zend_hash_add(doc_props->classmap, basece->name, 
basece->name_length + 1, &ce, sizeof(ce), NULL);
+               } else {
+                       return zend_hash_del(doc_props->classmap, 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_hash_find(doc_props->classmap, 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;
@@ -1212,6 +1252,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/viewcvs.cgi/php-src/ext/dom/php_dom.h?r1=1.28.2.1.2.1&r2=1.28.2.1.2.2&diff_format=u
Index: php-src/ext/dom/php_dom.h
diff -u php-src/ext/dom/php_dom.h:1.28.2.1.2.1 
php-src/ext/dom/php_dom.h:1.28.2.1.2.2
--- php-src/ext/dom/php_dom.h:1.28.2.1.2.1      Tue May  9 23:55:24 2006
+++ php-src/ext/dom/php_dom.h   Mon May 22 17:12:25 2006
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dom.h,v 1.28.2.1.2.1 2006/05/09 23:55:24 helly Exp $ */
+/* $Id: php_dom.h,v 1.28.2.1.2.2 2006/05/22 17:12:25 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, 
int by_ref 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/viewcvs.cgi/php-src/ext/dom/xml_common.h?r1=1.23.2.1&r2=1.23.2.1.2.1&diff_format=u
Index: php-src/ext/dom/xml_common.h
diff -u php-src/ext/dom/xml_common.h:1.23.2.1 
php-src/ext/dom/xml_common.h:1.23.2.1.2.1
--- php-src/ext/dom/xml_common.h:1.23.2.1       Sun Jan  1 12:50:06 2006
+++ php-src/ext/dom/xml_common.h        Mon May 22 17:12:25 2006
@@ -17,24 +17,14 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: xml_common.h,v 1.23.2.1 2006/01/01 12:50:06 sniper Exp $ */
+/* $Id: xml_common.h,v 1.23.2.1.2.1 2006/05/22 17:12:25 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;

http://cvs.php.net/viewcvs.cgi/php-src/ext/dom/tests/regsiter_node_class.phpt?view=markup&rev=1.1
Index: php-src/ext/dom/tests/regsiter_node_class.phpt
+++ php-src/ext/dom/tests/regsiter_node_class.phpt
--TEST--
Test: registerNodeClass()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
class myAttribute extends DOMAttr {
   function testit() { return "HELLO Attribute"; }
}

class myElement extends DOMElement {
   function testit() { return "HELLO Element"; }
}

$doc = new DOMDocument();
$doc->registerNodeClass('DOMAttr', 'myAttribute');
$doc->registerNodeClass('DOMElement', 'myElement');
$doc->appendChild(new DOMElement('root'));
$root = $doc->documentElement;
$root->setAttribute('a', 'a1');
var_dump($root);
print $root->testit()."\n";
$attr = $root->getAttributeNode('a');
var_dump($attr);
print $attr->testit()."\n";
unset($attr);
$doc->registerNodeClass('DOMAttr', NULL);
$attr = $root->getAttributeNode('a');
var_dump($attr);
print $attr->testit()."\n";
?>
--EXPECTF--

object(myElement)#%d (0) {
}
HELLO Element
object(myAttribute)#%d (0) {
}
HELLO Attribute
object(DOMAttr)#%d (0) {
}

Fatal error: Call to undefined method DOMAttr::testit() in %s on line 25

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

Reply via email to