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 - nodelist.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 63 69 91.3 %
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             : 
      29             : /* {{{ arginfo */
      30             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_nodelist_item, 0, 0, 1)
      31             :         ZEND_ARG_INFO(0, index)
      32             : ZEND_END_ARG_INFO();
      33             : /* }}} */
      34             : 
      35             : /* {{{ arginfo */
      36             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_nodelist_count, 0, 0, 0)
      37             : ZEND_END_ARG_INFO();
      38             : /* }}} */
      39             : 
      40             : /*
      41             : * class DOMNodeList
      42             : *
      43             : * URL: https://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-536297177
      44             : * Since:
      45             : */
      46             : 
      47             : const zend_function_entry php_dom_nodelist_class_functions[] = {
      48             :         PHP_FALIAS(item, dom_nodelist_item, arginfo_dom_nodelist_item)
      49             :         PHP_FALIAS(count, dom_nodelist_count, arginfo_dom_nodelist_count)
      50             :         PHP_FE_END
      51             : };
      52             : 
      53             : 
      54             : /* {{{ length   int
      55             : readonly=yes
      56             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
      57             : Since:
      58             : */
      59          74 : int dom_nodelist_length_read(dom_object *obj, zval *retval)
      60             : {
      61             :         dom_nnodemap_object *objmap;
      62             :         xmlNodePtr nodep, curnode;
      63          74 :         int count = 0;
      64             :         HashTable *nodeht;
      65             : 
      66          74 :         objmap = (dom_nnodemap_object *)obj->ptr;
      67          74 :         if (objmap != NULL) {
      68          74 :                 if (objmap->ht) {
      69           0 :                         count = xmlHashSize(objmap->ht);
      70             :                 } else {
      71          74 :                         if (objmap->nodetype == DOM_NODESET) {
      72          14 :                                 nodeht = HASH_OF(&objmap->baseobj_zv);
      73           7 :                                 count = zend_hash_num_elements(nodeht);
      74             :                         } else {
      75          67 :                                 nodep = dom_object_get_node(objmap->baseobj);
      76          67 :                                 if (nodep) {
      77          67 :                                         if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
      78          55 :                                                 curnode = nodep->children;
      79         110 :                                                 if (curnode) {
      80          55 :                                                         count++;
      81         226 :                                                         while (curnode->next != NULL) {
      82         116 :                                                                 count++;
      83         116 :                                                                 curnode = curnode->next;
      84             :                                                         }
      85             :                                                 }
      86             :                                         } else {
      87          12 :                                                 if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
      88          10 :                                                         nodep = xmlDocGetRootElement((xmlDoc *) nodep);
      89             :                                                 } else {
      90           2 :                                                         nodep = nodep->children;
      91             :                                                 }
      92          12 :                                                 curnode = dom_get_elements_by_tag_name_ns_raw(
      93          12 :                                                         nodep, (char *) objmap->ns, (char *) objmap->local, &count, -1);
      94             :                                         }
      95             :                                 }
      96             :                         }
      97             :                 }
      98             :         }
      99             : 
     100          74 :         ZVAL_LONG(retval, count);
     101          74 :         return SUCCESS;
     102             : }
     103             : 
     104             : 
     105             : /* {{{ proto int|bool dom_nodelist_count();
     106             : */
     107           2 : PHP_FUNCTION(dom_nodelist_count)
     108             : {
     109             :         zval *id;
     110             :         dom_object *intern;
     111             : 
     112           2 :         id = ZEND_THIS;
     113           2 :         if (zend_parse_parameters_none() == FAILURE) {
     114           0 :                 return;
     115             :         }
     116             : 
     117           2 :         intern = Z_DOMOBJ_P(id);
     118           2 :         if(dom_nodelist_length_read(intern, return_value) == FAILURE) {
     119           0 :                 RETURN_FALSE;
     120             :         }
     121             : }
     122             : /* }}} end dom_nodelist_count */
     123             : 
     124             : /* }}} */
     125             : 
     126             : /* {{{ proto DOMNode dom_nodelist_item(int index);
     127             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136
     128             : Since:
     129             : */
     130          67 : PHP_FUNCTION(dom_nodelist_item)
     131             : {
     132             :         zval *id;
     133             :         zend_long index;
     134             :         int ret;
     135             :         dom_object *intern;
     136          67 :         xmlNodePtr itemnode = NULL;
     137             : 
     138             :         dom_nnodemap_object *objmap;
     139             :         xmlNodePtr nodep, curnode;
     140          67 :         int count = 0;
     141             : 
     142          67 :         id = ZEND_THIS;
     143          67 :         if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
     144          64 :                 return;
     145             :         }
     146             : 
     147          67 :         if (index >= 0) {
     148          67 :                 intern = Z_DOMOBJ_P(id);
     149             : 
     150          67 :                 objmap = (dom_nnodemap_object *)intern->ptr;
     151          67 :                 if (objmap != NULL) {
     152          67 :                         if (objmap->ht) {
     153           0 :                                 if (objmap->nodetype == XML_ENTITY_NODE) {
     154           0 :                                         itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
     155             :                                 } else {
     156           0 :                                         itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
     157             :                                 }
     158             :                         } else {
     159          67 :                                 if (objmap->nodetype == DOM_NODESET) {
     160          14 :                                         HashTable *nodeht = HASH_OF(&objmap->baseobj_zv);
     161           7 :                                         zval *entry = zend_hash_index_find(nodeht, index);
     162           7 :                                         if (entry) {
     163           7 :                                                 ZVAL_COPY(return_value, entry);
     164           7 :                                                 return;
     165             :                                         }
     166          60 :                                 } else if (objmap->baseobj) {
     167          59 :                                         nodep = dom_object_get_node(objmap->baseobj);
     168          59 :                                         if (nodep) {
     169          59 :                                                 if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
     170          24 :                                                         curnode = nodep->children;
     171          82 :                                                         while (count < index && curnode != NULL) {
     172          34 :                                                                 count++;
     173          34 :                                                                 curnode = curnode->next;
     174             :                                                         }
     175          24 :                                                         itemnode = curnode;
     176             :                                                 } else {
     177          35 :                                                         if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
     178          27 :                                                                 nodep = xmlDocGetRootElement((xmlDoc *) nodep);
     179             :                                                         } else {
     180           8 :                                                                 nodep = nodep->children;
     181             :                                                         }
     182          35 :                                                         itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, (char *) objmap->ns, (char *) objmap->local, &count, index);
     183             :                                                 }
     184             :                                         }
     185             :                                 }
     186             :                         }
     187             :                 }
     188             : 
     189          60 :                 if (itemnode) {
     190          57 :                         DOM_RET_OBJ(itemnode, &ret, objmap->baseobj);
     191          57 :                         return;
     192             :                 }
     193             :         }
     194             : 
     195           3 :         RETVAL_NULL();
     196             : }
     197             : /* }}} end dom_nodelist_item */
     198             : 
     199             : 
     200             : #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.