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/simplexml - sxe.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 55 69 79.7 %
Date: 2015-07-26 Functions: 8 8 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: Marcus Boerger <helly@php.net>                              |
      16             :    +----------------------------------------------------------------------+
      17             :  */
      18             : 
      19             : /* $Id$ */
      20             : 
      21             : #ifdef HAVE_CONFIG_H
      22             : # include "config.h"
      23             : #endif
      24             : 
      25             : #include "php.h"
      26             : #include "php_ini.h"
      27             : #include "ext/standard/info.h"
      28             : #include "zend_interfaces.h"
      29             : 
      30             : #include "php_simplexml.h"
      31             : #include "ext/spl/php_spl.h"
      32             : #include "ext/spl/spl_iterators.h"
      33             : #include "sxe.h"
      34             : 
      35             : PHP_SXE_API zend_class_entry *ce_SimpleXMLIterator = NULL;
      36             : PHP_SXE_API zend_class_entry *ce_SimpleXMLElement;
      37             : 
      38             : #include "php_simplexml_exports.h"
      39             : 
      40             : /* {{{ proto void SimpleXMLIterator::rewind()
      41             :  Rewind to first element */
      42           6 : PHP_METHOD(ce_SimpleXMLIterator, rewind)
      43             : {
      44             :         php_sxe_iterator iter;
      45             : 
      46           6 :         if (zend_parse_parameters_none() == FAILURE) {
      47           0 :                 return;
      48             :         }
      49             : 
      50           6 :         iter.sxe = Z_SXEOBJ_P(getThis());
      51           6 :         ce_SimpleXMLElement->iterator_funcs.funcs->rewind((zend_object_iterator*)&iter);
      52             : }
      53             : /* }}} */
      54             : 
      55             : /* {{{ proto bool SimpleXMLIterator::valid()
      56             :  Check whether iteration is valid */
      57          21 : PHP_METHOD(ce_SimpleXMLIterator, valid)
      58             : {
      59          21 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
      60             : 
      61          21 :         if (zend_parse_parameters_none() == FAILURE) {
      62           0 :                 return;
      63             :         }
      64             : 
      65          42 :         RETURN_BOOL(!Z_ISUNDEF(sxe->iter.data));
      66             : }
      67             : /* }}} */
      68             : 
      69             : /* {{{ proto SimpleXMLIterator SimpleXMLIterator::current()
      70             :  Get current element */
      71           8 : PHP_METHOD(ce_SimpleXMLIterator, current)
      72             : {
      73           8 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
      74             :         zval *data;
      75             : 
      76           8 :         if (zend_parse_parameters_none() == FAILURE) {
      77           0 :                 return;
      78             :         }
      79             : 
      80          16 :         if (Z_ISUNDEF(sxe->iter.data)) {
      81           0 :                 return; /* return NULL */
      82             :         }
      83             : 
      84           8 :         data = &sxe->iter.data;
      85           8 :         ZVAL_DEREF(data);
      86           8 :         ZVAL_COPY(return_value, data);
      87             : }
      88             : /* }}} */
      89             : 
      90             : /* {{{ proto string SimpleXMLIterator::key()
      91             :  Get name of current child element */
      92           2 : PHP_METHOD(ce_SimpleXMLIterator, key)
      93             : {
      94             :         xmlNodePtr curnode;
      95             :         php_sxe_object *intern;
      96           2 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
      97             : 
      98           2 :         if (zend_parse_parameters_none() == FAILURE) {
      99           0 :                 return;
     100             :         }
     101             : 
     102           4 :         if (Z_ISUNDEF(sxe->iter.data)) {
     103           0 :                 RETURN_FALSE;
     104             :         }
     105             : 
     106           2 :         intern = Z_SXEOBJ_P(&sxe->iter.data);
     107           2 :         if (intern != NULL && intern->node != NULL) {
     108           2 :                 curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
     109           4 :                 RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name));
     110             :         }
     111             : 
     112           0 :         RETURN_FALSE;
     113             : }
     114             : /* }}} */
     115             : 
     116             : /* {{{ proto void SimpleXMLIterator::next()
     117             :  Move to next element */
     118           8 : PHP_METHOD(ce_SimpleXMLIterator, next)
     119             : {
     120             :         php_sxe_iterator iter;
     121             : 
     122           8 :         if (zend_parse_parameters_none() == FAILURE) {
     123           0 :                 return;
     124             :         }
     125             : 
     126           8 :         iter.sxe = Z_SXEOBJ_P(getThis());
     127           8 :         ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter);
     128             : }
     129             : /* }}} */
     130             : 
     131             : /* {{{ proto bool SimpleXMLIterator::hasChildren()
     132             :  Check whether element has children (elements) */
     133          24 : PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
     134             : {
     135          24 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
     136             :         php_sxe_object *child;
     137             :         xmlNodePtr      node;
     138             : 
     139          24 :         if (zend_parse_parameters_none() == FAILURE) {
     140           0 :                 return;
     141             :         }
     142             : 
     143          48 :         if (Z_ISUNDEF(sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
     144           0 :                 RETURN_FALSE;
     145             :         }
     146          24 :         child = Z_SXEOBJ_P(&sxe->iter.data);
     147             : 
     148          24 :         GET_NODE(child, node);
     149          24 :         if (node) {
     150          24 :                 node = node->children;
     151             :         }
     152          71 :         while (node && node->type != XML_ELEMENT_NODE) {
     153          23 :                 node = node->next;
     154             :         }
     155          24 :         RETURN_BOOL(node ? 1 : 0);
     156             : }
     157             : /* }}} */
     158             : 
     159             : /* {{{ proto SimpleXMLIterator SimpleXMLIterator::getChildren()
     160             :  Get child element iterator */
     161          14 : PHP_METHOD(ce_SimpleXMLIterator, getChildren)
     162             : {
     163          14 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
     164             :         zval *data;
     165             : 
     166          14 :         if (zend_parse_parameters_none() == FAILURE) {
     167           0 :                 return;
     168             :         }
     169             : 
     170          28 :         if (Z_ISUNDEF(sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
     171           1 :                 return; /* return NULL */
     172             :         }
     173             : 
     174          13 :         data = &sxe->iter.data;
     175          13 :         ZVAL_DEREF(data);
     176          13 :         ZVAL_COPY(return_value, data);
     177             : }
     178             : 
     179             : /* {{{ arginfo */
     180             : ZEND_BEGIN_ARG_INFO(arginfo_simplexmliterator__void, 0)
     181             : ZEND_END_ARG_INFO()
     182             : /* }}} */
     183             : 
     184             : static const zend_function_entry funcs_SimpleXMLIterator[] = {
     185             :         PHP_ME(ce_SimpleXMLIterator, rewind,                 arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     186             :         PHP_ME(ce_SimpleXMLIterator, valid,                  arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     187             :         PHP_ME(ce_SimpleXMLIterator, current,                arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     188             :         PHP_ME(ce_SimpleXMLIterator, key,                    arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     189             :         PHP_ME(ce_SimpleXMLIterator, next,                   arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     190             :         PHP_ME(ce_SimpleXMLIterator, hasChildren,            arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     191             :         PHP_ME(ce_SimpleXMLIterator, getChildren,            arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     192             :         {NULL, NULL, NULL}
     193             : };
     194             : /* }}} */
     195             : 
     196       21049 : PHP_MINIT_FUNCTION(sxe) /* {{{ */
     197             : {
     198             :         zend_class_entry *pce;
     199             :         zend_class_entry sxi;
     200             : 
     201       42098 :         if ((pce = zend_hash_str_find_ptr(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement") - 1)) == NULL) {
     202           0 :                 ce_SimpleXMLElement  = NULL;
     203           0 :                 ce_SimpleXMLIterator = NULL;
     204           0 :                 return SUCCESS; /* SimpleXML must be initialized before */
     205             :         }
     206             : 
     207       21049 :         ce_SimpleXMLElement = pce;
     208             : 
     209       21049 :         INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", sizeof("SimpleXMLIterator") - 1, funcs_SimpleXMLIterator);
     210       21049 :         ce_SimpleXMLIterator = zend_register_internal_class_ex(&sxi, ce_SimpleXMLElement);
     211       21049 :         ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;
     212             : 
     213       21049 :         zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_RecursiveIterator);
     214       21049 :         zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_Countable);
     215             : 
     216       21049 :         return SUCCESS;
     217             : }
     218             : /* }}} */
     219             : 
     220             : /*
     221             :  * Local variables:
     222             :  * tab-width: 4
     223             :  * c-basic-offset: 4
     224             :  * End:
     225             :  * vim600: fdm=marker
     226             :  * vim: noet sw=4 ts=4
     227             :  */

Generated by: LCOV version 1.10

Generated at Mon, 27 Jul 2015 02:32:25 +0000 (29 hours ago)

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