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: 46 49 93.9 %
Date: 2019-05-06 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 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             : #ifdef HAVE_CONFIG_H
      21             : #include "config.h"
      22             : #endif
      23             : 
      24             : #include "php.h"
      25             : #if HAVE_LIBXML && HAVE_DOM
      26             : #include "php_dom.h"
      27             : 
      28             : /* {{{ arginfo */
      29             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_documentfragement_construct, 0, 0, 0)
      30             : ZEND_END_ARG_INFO();
      31             : 
      32             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_documentfragement_appendXML, 0, 0, 1)
      33             :         ZEND_ARG_INFO(0, data)
      34             : ZEND_END_ARG_INFO();
      35             : /* }}} */
      36             : 
      37             : /*
      38             : * class DOMDocumentFragment extends DOMNode
      39             : *
      40             : * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-B63ED1A3
      41             : * Since:
      42             : */
      43             : 
      44             : const zend_function_entry php_dom_documentfragment_class_functions[] = {
      45             :         PHP_ME(domdocumentfragment, __construct, arginfo_dom_documentfragement_construct, ZEND_ACC_PUBLIC)
      46             :         PHP_ME(domdocumentfragment, appendXML, arginfo_dom_documentfragement_appendXML, ZEND_ACC_PUBLIC)
      47             :         PHP_FE_END
      48             : };
      49             : 
      50             : /* {{{ proto DOMDocumentFragment::__construct() */
      51           5 : PHP_METHOD(domdocumentfragment, __construct)
      52             : {
      53           5 :         xmlNodePtr nodep = NULL, oldnode = NULL;
      54             :         dom_object *intern;
      55             : 
      56           5 :         if (zend_parse_parameters_none_throw() == FAILURE) {
      57           1 :                 return;
      58             :         }
      59             : 
      60           4 :         nodep = xmlNewDocFragment(NULL);
      61             : 
      62           4 :         if (!nodep) {
      63           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 1);
      64           0 :                 RETURN_FALSE;
      65             :         }
      66             : 
      67           4 :         intern = Z_DOMOBJ_P(ZEND_THIS);
      68           4 :         oldnode = dom_object_get_node(intern);
      69           4 :         if (oldnode != NULL) {
      70           1 :                 php_libxml_node_free_resource(oldnode );
      71             :         }
      72             :         /* php_dom_set_object(intern, nodep); */
      73           4 :         php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
      74             : }
      75             : /* }}} end DOMDocumentFragment::__construct */
      76             : 
      77             : /* php_dom_xmlSetTreeDoc is a custom implementation of xmlSetTreeDoc
      78             :  needed for hack in appendXML due to libxml bug - no need to share this function */
      79           5 : static void php_dom_xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) /* {{{ */
      80             : {
      81             :     xmlAttrPtr prop;
      82             :         xmlNodePtr cur;
      83             : 
      84           5 :     if (tree) {
      85           5 :                 if(tree->type == XML_ELEMENT_NODE) {
      86           2 :                         prop = tree->properties;
      87           5 :                         while (prop != NULL) {
      88           1 :                                 prop->doc = doc;
      89           1 :                                 if (prop->children) {
      90           1 :                                         cur = prop->children;
      91           3 :                                         while (cur != NULL) {
      92           1 :                                                 php_dom_xmlSetTreeDoc(cur, doc);
      93           1 :                                                 cur = cur->next;
      94             :                                         }
      95             :                                 }
      96           1 :                                 prop = prop->next;
      97             :                         }
      98             :                 }
      99           5 :                 if (tree->children != NULL) {
     100           2 :                         cur = tree->children;
     101           6 :                         while (cur != NULL) {
     102           2 :                                 php_dom_xmlSetTreeDoc(cur, doc);
     103           2 :                                 cur = cur->next;
     104             :                         }
     105             :                 }
     106           5 :                 tree->doc = doc;
     107             :     }
     108           5 : }
     109             : /* }}} */
     110             : 
     111             : /* {{{ proto void DOMDocumentFragment::appendXML(string data) */
     112           4 : PHP_METHOD(domdocumentfragment, appendXML) {
     113             :         zval *id;
     114             :         xmlNode *nodep;
     115             :         dom_object *intern;
     116           4 :         char *data = NULL;
     117           4 :         size_t data_len = 0;
     118             :         int err;
     119             :         xmlNodePtr lst;
     120             : 
     121           4 :         id = ZEND_THIS;
     122           4 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data, &data_len) == FAILURE) {
     123           0 :                 return;
     124             :         }
     125             : 
     126           4 :         DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
     127             : 
     128           4 :         if (dom_node_is_read_only(nodep) == SUCCESS) {
     129           1 :                 php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
     130           1 :                 RETURN_FALSE;
     131             :         }
     132             : 
     133           3 :         if (data) {
     134           3 :                 err = xmlParseBalancedChunkMemory(nodep->doc, NULL, NULL, 0, (xmlChar *) data, &lst);
     135           3 :                 if (err != 0) {
     136           1 :                         RETURN_FALSE;
     137             :                 }
     138             :                 /* Following needed due to bug in libxml2 <= 2.6.14
     139             :                 ifdef after next libxml release as bug is fixed in their cvs */
     140           2 :                 php_dom_xmlSetTreeDoc(lst, nodep->doc);
     141             :                 /* End stupid hack */
     142             : 
     143           2 :                 xmlAddChildList(nodep,lst);
     144             :         }
     145             : 
     146           2 :         RETURN_TRUE;
     147             : }
     148             : /* }}} */
     149             : 
     150             : #endif

Generated by: LCOV version 1.10

Generated at Mon, 06 May 2019 17:58:13 +0000 (998 days ago)

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