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: 57 62 91.9 %
Date: 2014-04-18 Functions: 2 2 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             : 
      31             : /* {{{ arginfo */
      32             : ZEND_BEGIN_ARG_INFO_EX(arginfo_dom_nodelist_item, 0, 0, 1)
      33             :         ZEND_ARG_INFO(0, index)
      34             : ZEND_END_ARG_INFO();
      35             : /* }}} */
      36             : 
      37             : /*
      38             : * class DOMNodeList 
      39             : *
      40             : * URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-536297177
      41             : * Since: 
      42             : */
      43             : 
      44             : const zend_function_entry php_dom_nodelist_class_functions[] = {
      45             :         PHP_FALIAS(item, dom_nodelist_item, arginfo_dom_nodelist_item)
      46             :         PHP_FE_END
      47             : };
      48             : 
      49             : /* {{{ length   int     
      50             : readonly=yes 
      51             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-203510337
      52             : Since: 
      53             : */
      54          63 : int dom_nodelist_length_read(dom_object *obj, zval **retval TSRMLS_DC)
      55             : {
      56             :         dom_nnodemap_object *objmap;
      57             :         xmlNodePtr nodep, curnode;
      58          63 :         int count = 0;
      59             :         HashTable *nodeht;
      60             : 
      61          63 :         objmap = (dom_nnodemap_object *)obj->ptr;
      62          63 :         if (objmap != NULL) {
      63          63 :                 if (objmap->ht) {
      64           0 :                         count = xmlHashSize(objmap->ht);
      65             :                 } else {
      66          63 :                         if (objmap->nodetype == DOM_NODESET) {
      67           7 :                                 nodeht = HASH_OF(objmap->baseobjptr);
      68           7 :                                 count = zend_hash_num_elements(nodeht);
      69             :                         } else {
      70          56 :                                 nodep = dom_object_get_node(objmap->baseobj);
      71          56 :                                 if (nodep) {
      72         107 :                                         if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
      73          51 :                                                 curnode = nodep->children;
      74          51 :                                                 if (curnode) {
      75          51 :                                                         count++;
      76         198 :                                                         while (curnode->next != NULL) {
      77          96 :                                                                 count++;
      78          96 :                                                                 curnode = curnode->next;
      79             :                                                         }
      80             :                                                 }
      81             :                                         } else {
      82           8 :                                                 if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
      83           3 :                                                         nodep = xmlDocGetRootElement((xmlDoc *) nodep);
      84             :                                                 } else {
      85           2 :                                                         nodep = nodep->children;
      86             :                                                 }
      87           5 :                                                 curnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, -1);
      88             :                                         }
      89             :                                 }
      90             :                         }
      91             :                 }
      92             :         }
      93             : 
      94          63 :         MAKE_STD_ZVAL(*retval);
      95          63 :         ZVAL_LONG(*retval, count);
      96          63 :         return SUCCESS;
      97             : }
      98             : 
      99             : /* }}} */
     100             : 
     101             : /* {{{ proto DOMNode dom_nodelist_item(int index);
     102             : URL: http://www.w3.org/TR/2003/WD-DOM-Level-3-Core-20030226/DOM3-Core.html#ID-844377136
     103             : Since: 
     104             : */
     105          49 : PHP_FUNCTION(dom_nodelist_item)
     106             : {
     107          49 :         zval *id, *rv = NULL;
     108             :         long index;
     109             :         int ret;
     110             :         dom_object *intern;
     111          49 :         xmlNodePtr itemnode = NULL;
     112             : 
     113             :         dom_nnodemap_object *objmap;
     114             :         xmlNodePtr nodep, curnode;
     115          49 :         int count = 0;
     116             :         HashTable *nodeht;
     117             :         zval **entry;
     118             : 
     119          49 :         if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol", &id, dom_nodelist_class_entry, &index) == FAILURE) {
     120           0 :                 return;
     121             :         }
     122             : 
     123          49 :         if (index >= 0) {
     124          49 :                 intern = (dom_object *)zend_object_store_get_object(id TSRMLS_CC);
     125             : 
     126          49 :                 objmap = (dom_nnodemap_object *)intern->ptr;
     127          49 :                 if (objmap != NULL) {
     128          49 :                         if (objmap->ht) {
     129           0 :                                 if (objmap->nodetype == XML_ENTITY_NODE) {
     130           0 :                                         itemnode = php_dom_libxml_hash_iter(objmap->ht, index);
     131             :                                 } else {
     132           0 :                                         itemnode = php_dom_libxml_notation_iter(objmap->ht, index);
     133             :                                 }
     134             :                         } else {
     135          49 :                                 if (objmap->nodetype == DOM_NODESET) {
     136           7 :                                         nodeht = HASH_OF(objmap->baseobjptr);
     137           7 :                                         if (zend_hash_index_find(nodeht, index, (void **) &entry)==SUCCESS) {
     138           7 :                                                 *return_value = **entry;
     139           7 :                                                 zval_copy_ctor(return_value);
     140           7 :                                                 return;
     141             :                                         }
     142          42 :                                 } else if (objmap->baseobj) {
     143          41 :                                         nodep = dom_object_get_node(objmap->baseobj);
     144          41 :                                         if (nodep) {
     145          63 :                                                 if (objmap->nodetype == XML_ATTRIBUTE_NODE || objmap->nodetype == XML_ELEMENT_NODE) {
     146          22 :                                                         curnode = nodep->children;
     147          78 :                                                         while (count < index && curnode != NULL) {
     148          34 :                                                                 count++;
     149          34 :                                                                 curnode = curnode->next;
     150             :                                                         }
     151          22 :                                                         itemnode = curnode;
     152             :                                                 } else {
     153          30 :                                                         if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
     154          11 :                                                                 nodep = xmlDocGetRootElement((xmlDoc *) nodep);
     155             :                                                         } else {
     156           8 :                                                                 nodep = nodep->children;
     157             :                                                         }
     158          19 :                                                         itemnode = dom_get_elements_by_tag_name_ns_raw(nodep, objmap->ns, objmap->local, &count, index);
     159             :                                                 }
     160             :                                         }
     161             :                                 }
     162             :                         }
     163             :                 }
     164             : 
     165          42 :                 if (itemnode) {
     166          41 :                         DOM_RET_OBJ(rv, itemnode, &ret, objmap->baseobj);
     167          41 :                         return;
     168             :                 }
     169             :         }
     170             : 
     171           1 :         RETVAL_NULL();
     172             : }
     173             : /* }}} end dom_nodelist_item */
     174             : 
     175             : #endif
     176             : 
     177             : /*
     178             :  * Local variables:
     179             :  * tab-width: 4
     180             :  * c-basic-offset: 4
     181             :  * End:
     182             :  * vim600: noet sw=4 ts=4 fdm=marker
     183             :  * vim<600: noet sw=4 ts=4
     184             :  */

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:26 +0000 (5 days ago)

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