PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/dom - documentfragment.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 50 52 96.2 %
Date: 2014-07-13 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2013 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Christian Stocker <chregu@php.net>                          |
      16             :    |          Rob Richards <rrichards@php.net>                            |
      17             :    +----------------------------------------------------------------------+
      18             : */
      19             : 
      20             : /* $Id$ */
      21             : 
      22             : #ifdef HAVE_CONFIG_H
      23             : #include "config.h"
      24             : #endif
      25             : 
      26             : #include "php.h"
      27             : #if HAVE_LIBXML && HAVE_DOM
      28             : #include "php_dom.h"
      29             : 
      30             : /* {{{ arginfo */
      31             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_documentfragement_construct, 0, 0, 0)
      32             : ZEND_END_ARG_INFO();
      33             : 
      34             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_documentfragement_appendXML, 0, 0, 1)
      35             :         ZEND_ARG_INFO(0, data)
      36             : ZEND_END_ARG_INFO();
      37             : /* }}} */
      38             : 
      39             : /*
      40             : * class DOMDocumentFragment extends DOMNode 
      41             : *
      42             : * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-B63ED1A3
      43             : * Since: 
      44             : */
      45             : 
      46             : const zend_function_entry php_dom_documentfragment_class_functions[] = {
      47             :         PHP_ME(domdocumentfragment, __construct, arginfo_dom_documentfragement_construct, ZEND_ACC_PUBLIC)
      48             :         PHP_ME(domdocumentfragment, appendXML, arginfo_dom_documentfragement_appendXML, ZEND_ACC_PUBLIC)
      49             :         PHP_FE_END
      50             : };
      51             : 
      52             : /* {{{ proto void DOMDocumentFragment::__construct(); */
      53           6 : PHP_METHOD(domdocumentfragment, __construct)
      54             : {
      55             : 
      56             :         zval *id;
      57           6 :         xmlNodePtr nodep = NULL, oldnode = NULL;
      58             :         dom_object *intern;
      59             :         zend_error_handling error_handling;
      60             : 
      61           6 :         zend_replace_error_handling(EH_THROW, dom_domexception_class_entry, &error_handling TSRMLS_CC);
      62           6 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &id, dom_documentfragment_class_entry) == FAILURE) {
      63           1 :                 zend_restore_error_handling(&error_handling TSRMLS_CC);
      64           1 :                 return;
      65             :         }
      66             : 
      67           5 :         zend_restore_error_handling(&error_handling TSRMLS_CC);
      68           5 :         nodep = xmlNewDocFragment(NULL);
      69             : 
      70           5 :         if (!nodep) {
      71           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 1 TSRMLS_CC);
      72           0 :                 RETURN_FALSE;
      73             :         }
      74             : 
      75           5 :         intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
      76           5 :         if (intern != NULL) {
      77           5 :                 oldnode = dom_object_get_node(intern);
      78           5 :                 if (oldnode != NULL) {
      79           1 :                         php_libxml_node_free_resource(oldnode  TSRMLS_CC);
      80             :                 }
      81             :                 /* php_dom_set_object(intern, nodep TSRMLS_CC); */
      82           5 :                 php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern TSRMLS_CC);
      83             :         }
      84             : }
      85             : /* }}} end DOMDocumentFragment::__construct */
      86             : 
      87             : /* php_dom_xmlSetTreeDoc is a custom implementation of xmlSetTreeDoc
      88             :  needed for hack in appendXML due to libxml bug - no need to share this function */
      89           5 : static void php_dom_xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) /* {{{ */
      90             : {
      91             :     xmlAttrPtr prop;
      92             :         xmlNodePtr cur;
      93             : 
      94           5 :     if (tree) {
      95           5 :                 if(tree->type == XML_ELEMENT_NODE) {
      96           2 :                         prop = tree->properties;
      97           5 :                         while (prop != NULL) {
      98           1 :                                 prop->doc = doc;
      99           1 :                                 if (prop->children) {
     100           1 :                                         cur = prop->children;
     101           3 :                                         while (cur != NULL) {
     102           1 :                                                 php_dom_xmlSetTreeDoc(cur, doc);
     103           1 :                                                 cur = cur->next;
     104             :                                         }
     105             :                                 }
     106           1 :                                 prop = prop->next;
     107             :                         }
     108             :                 }
     109           5 :                 if (tree->children != NULL) {
     110           2 :                         cur = tree->children;
     111           6 :                         while (cur != NULL) {
     112           2 :                                 php_dom_xmlSetTreeDoc(cur, doc);
     113           2 :                                 cur = cur->next;
     114             :                         }
     115             :                 }
     116           5 :                 tree->doc = doc;
     117             :     }
     118           5 : }
     119             : /* }}} */
     120             : 
     121             : /* {{{ proto void DOMDocumentFragment::appendXML(string data); */
     122           5 : PHP_METHOD(domdocumentfragment, appendXML) {
     123             :         zval *id;
     124             :         xmlNode *nodep;
     125             :         dom_object *intern;
     126           5 :         char *data = NULL;
     127           5 :         int data_len = 0;
     128             :         int err;
     129             :         xmlNodePtr lst;
     130             : 
     131           5 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &id, dom_documentfragment_class_entry, &data, &data_len) == FAILURE) {
     132           1 :                 return;
     133             :         }
     134             : 
     135           4 :         DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
     136             : 
     137           4 :         if (dom_node_is_read_only(nodep) == SUCCESS) {
     138           1 :                 php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document) TSRMLS_CC);
     139           1 :                 RETURN_FALSE;
     140             :         }
     141             : 
     142           3 :         if (data) {
     143           3 :                 err = xmlParseBalancedChunkMemory(nodep->doc, NULL, NULL, 0, data, &lst);
     144           3 :                 if (err != 0) {
     145           1 :                         RETURN_FALSE;
     146             :                 }
     147             :                 /* Following needed due to bug in libxml2 <= 2.6.14 
     148             :                 ifdef after next libxml release as bug is fixed in their cvs */
     149           2 :                 php_dom_xmlSetTreeDoc(lst, nodep->doc);
     150             :                 /* End stupid hack */
     151             : 
     152           2 :                 xmlAddChildList(nodep,lst);
     153             :         }
     154             : 
     155           2 :         RETURN_TRUE;
     156             : }
     157             : /* }}} */
     158             : 
     159             : #endif
     160             : 
     161             : /*
     162             :  * Local variables:
     163             :  * tab-width: 4
     164             :  * c-basic-offset: 4
     165             :  * End:
     166             :  * vim600: noet sw=4 ts=4 fdm=marker
     167             :  * vim<600: noet sw=4 ts=4
     168             :  */

Generated by: LCOV version 1.10

Generated at Sun, 13 Jul 2014 23:57:48 +0000 (9 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.