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: 47 49 95.9 %
Date: 2015-07-26 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2015 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           6 :         zval *id = getThis();
      57           6 :         xmlNodePtr nodep = NULL, oldnode = NULL;
      58             :         dom_object *intern;
      59             : 
      60           6 :         if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "") == FAILURE) {
      61           1 :                 return;
      62             :         }
      63             : 
      64           5 :         nodep = xmlNewDocFragment(NULL);
      65             : 
      66           5 :         if (!nodep) {
      67           0 :                 php_dom_throw_error(INVALID_STATE_ERR, 1);
      68           0 :                 RETURN_FALSE;
      69             :         }
      70             : 
      71           5 :         intern = Z_DOMOBJ_P(id);
      72           5 :         oldnode = dom_object_get_node(intern);
      73           5 :         if (oldnode != NULL) {
      74           1 :                 php_libxml_node_free_resource(oldnode );
      75             :         }
      76             :         /* php_dom_set_object(intern, nodep); */
      77           5 :         php_libxml_increment_node_ptr((php_libxml_node_object *)intern, nodep, (void *)intern);
      78             : }
      79             : /* }}} end DOMDocumentFragment::__construct */
      80             : 
      81             : /* php_dom_xmlSetTreeDoc is a custom implementation of xmlSetTreeDoc
      82             :  needed for hack in appendXML due to libxml bug - no need to share this function */
      83           5 : static void php_dom_xmlSetTreeDoc(xmlNodePtr tree, xmlDocPtr doc) /* {{{ */
      84             : {
      85             :     xmlAttrPtr prop;
      86             :         xmlNodePtr cur;
      87             : 
      88           5 :     if (tree) {
      89           5 :                 if(tree->type == XML_ELEMENT_NODE) {
      90           2 :                         prop = tree->properties;
      91           5 :                         while (prop != NULL) {
      92           1 :                                 prop->doc = doc;
      93           1 :                                 if (prop->children) {
      94           1 :                                         cur = prop->children;
      95           3 :                                         while (cur != NULL) {
      96           1 :                                                 php_dom_xmlSetTreeDoc(cur, doc);
      97           1 :                                                 cur = cur->next;
      98             :                                         }
      99             :                                 }
     100           1 :                                 prop = prop->next;
     101             :                         }
     102             :                 }
     103           5 :                 if (tree->children != NULL) {
     104           2 :                         cur = tree->children;
     105           6 :                         while (cur != NULL) {
     106           2 :                                 php_dom_xmlSetTreeDoc(cur, doc);
     107           2 :                                 cur = cur->next;
     108             :                         }
     109             :                 }
     110           5 :                 tree->doc = doc;
     111             :     }
     112           5 : }
     113             : /* }}} */
     114             : 
     115             : /* {{{ proto void DOMDocumentFragment::appendXML(string data) */
     116           5 : PHP_METHOD(domdocumentfragment, appendXML) {
     117             :         zval *id;
     118             :         xmlNode *nodep;
     119             :         dom_object *intern;
     120           5 :         char *data = NULL;
     121           5 :         size_t data_len = 0;
     122             :         int err;
     123             :         xmlNodePtr lst;
     124             : 
     125           5 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Os", &id, dom_documentfragment_class_entry, &data, &data_len) == FAILURE) {
     126           1 :                 return;
     127             :         }
     128             : 
     129           4 :         DOM_GET_OBJ(nodep, id, xmlNodePtr, intern);
     130             : 
     131           4 :         if (dom_node_is_read_only(nodep) == SUCCESS) {
     132           1 :                 php_dom_throw_error(NO_MODIFICATION_ALLOWED_ERR, dom_get_strict_error(intern->document));
     133           1 :                 RETURN_FALSE;
     134             :         }
     135             : 
     136           3 :         if (data) {
     137           3 :                 err = xmlParseBalancedChunkMemory(nodep->doc, NULL, NULL, 0, (xmlChar *) data, &lst);
     138           3 :                 if (err != 0) {
     139           1 :                         RETURN_FALSE;
     140             :                 }
     141             :                 /* Following needed due to bug in libxml2 <= 2.6.14
     142             :                 ifdef after next libxml release as bug is fixed in their cvs */
     143           2 :                 php_dom_xmlSetTreeDoc(lst, nodep->doc);
     144             :                 /* End stupid hack */
     145             : 
     146           2 :                 xmlAddChildList(nodep,lst);
     147             :         }
     148             : 
     149           2 :         RETURN_TRUE;
     150             : }
     151             : /* }}} */
     152             : 
     153             : #endif
     154             : 
     155             : /*
     156             :  * Local variables:
     157             :  * tab-width: 4
     158             :  * c-basic-offset: 4
     159             :  * End:
     160             :  * vim600: noet sw=4 ts=4 fdm=marker
     161             :  * vim<600: noet sw=4 ts=4
     162             :  */

Generated by: LCOV version 1.10

Generated at Mon, 27 Jul 2015 02:32:17 +0000 (3 days ago)

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