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: 51 65 78.5 %
Date: 2015-05-21 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             : 
      75           8 :         if (zend_parse_parameters_none() == FAILURE) {
      76           0 :                 return;
      77             :         }
      78             : 
      79          16 :         if (Z_ISUNDEF(sxe->iter.data)) {
      80           0 :                 return; /* return NULL */
      81             :         }
      82             : 
      83          24 :         RETURN_ZVAL(&sxe->iter.data, 1, 0);
      84             : }
      85             : /* }}} */
      86             : 
      87             : /* {{{ proto string SimpleXMLIterator::key()
      88             :  Get name of current child element */
      89           2 : PHP_METHOD(ce_SimpleXMLIterator, key)
      90             : {
      91             :         xmlNodePtr curnode;
      92             :         php_sxe_object *intern;
      93           2 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
      94             : 
      95           2 :         if (zend_parse_parameters_none() == FAILURE) {
      96           0 :                 return;
      97             :         }
      98             : 
      99           4 :         if (Z_ISUNDEF(sxe->iter.data)) {
     100           0 :                 RETURN_FALSE;
     101             :         }
     102             : 
     103           2 :         intern = Z_SXEOBJ_P(&sxe->iter.data);
     104           2 :         if (intern != NULL && intern->node != NULL) {
     105           2 :                 curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node;
     106           4 :                 RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name));
     107             :         }
     108             : 
     109           0 :         RETURN_FALSE;
     110             : }
     111             : /* }}} */
     112             : 
     113             : /* {{{ proto void SimpleXMLIterator::next()
     114             :  Move to next element */
     115           8 : PHP_METHOD(ce_SimpleXMLIterator, next)
     116             : {
     117             :         php_sxe_iterator iter;
     118             : 
     119           8 :         if (zend_parse_parameters_none() == FAILURE) {
     120           0 :                 return;
     121             :         }
     122             : 
     123           8 :         iter.sxe = Z_SXEOBJ_P(getThis());
     124           8 :         ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter);
     125             : }
     126             : /* }}} */
     127             : 
     128             : /* {{{ proto bool SimpleXMLIterator::hasChildren()
     129             :  Check whether element has children (elements) */
     130          24 : PHP_METHOD(ce_SimpleXMLIterator, hasChildren)
     131             : {
     132          24 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
     133             :         php_sxe_object *child;
     134             :         xmlNodePtr      node;
     135             : 
     136          24 :         if (zend_parse_parameters_none() == FAILURE) {
     137           0 :                 return;
     138             :         }
     139             : 
     140          48 :         if (Z_ISUNDEF(sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
     141           0 :                 RETURN_FALSE;
     142             :         }
     143          24 :         child = Z_SXEOBJ_P(&sxe->iter.data);
     144             : 
     145          24 :         GET_NODE(child, node);
     146          24 :         if (node) {
     147          24 :                 node = node->children;
     148             :         }
     149          71 :         while (node && node->type != XML_ELEMENT_NODE) {
     150          23 :                 node = node->next;
     151             :         }
     152          24 :         RETURN_BOOL(node ? 1 : 0);
     153             : }
     154             : /* }}} */
     155             : 
     156             : /* {{{ proto SimpleXMLIterator SimpleXMLIterator::getChildren()
     157             :  Get child element iterator */
     158          14 : PHP_METHOD(ce_SimpleXMLIterator, getChildren)
     159             : {
     160          14 :         php_sxe_object *sxe = Z_SXEOBJ_P(getThis());
     161             : 
     162          14 :         if (zend_parse_parameters_none() == FAILURE) {
     163           0 :                 return;
     164             :         }
     165             : 
     166          28 :         if (Z_ISUNDEF(sxe->iter.data) || sxe->iter.type == SXE_ITER_ATTRLIST) {
     167           1 :                 return; /* return NULL */
     168             :         }
     169          39 :         RETURN_ZVAL(&sxe->iter.data, 1, 0);
     170             : }
     171             : 
     172             : /* {{{ arginfo */
     173             : ZEND_BEGIN_ARG_INFO(arginfo_simplexmliterator__void, 0)
     174             : ZEND_END_ARG_INFO()
     175             : /* }}} */
     176             : 
     177             : static const zend_function_entry funcs_SimpleXMLIterator[] = {
     178             :         PHP_ME(ce_SimpleXMLIterator, rewind,                 arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     179             :         PHP_ME(ce_SimpleXMLIterator, valid,                  arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     180             :         PHP_ME(ce_SimpleXMLIterator, current,                arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     181             :         PHP_ME(ce_SimpleXMLIterator, key,                    arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     182             :         PHP_ME(ce_SimpleXMLIterator, next,                   arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     183             :         PHP_ME(ce_SimpleXMLIterator, hasChildren,            arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     184             :         PHP_ME(ce_SimpleXMLIterator, getChildren,            arginfo_simplexmliterator__void, ZEND_ACC_PUBLIC)
     185             :         {NULL, NULL, NULL}
     186             : };
     187             : /* }}} */
     188             : 
     189       20916 : PHP_MINIT_FUNCTION(sxe) /* {{{ */
     190             : {
     191             :         zend_class_entry *pce;
     192             :         zend_class_entry sxi;
     193             : 
     194       41832 :         if ((pce = zend_hash_str_find_ptr(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement") - 1)) == NULL) {
     195           0 :                 ce_SimpleXMLElement  = NULL;
     196           0 :                 ce_SimpleXMLIterator = NULL;
     197           0 :                 return SUCCESS; /* SimpleXML must be initialized before */
     198             :         }
     199             : 
     200       20916 :         ce_SimpleXMLElement = pce;
     201             : 
     202       20916 :         INIT_CLASS_ENTRY_EX(sxi, "SimpleXMLIterator", sizeof("SimpleXMLIterator") - 1, funcs_SimpleXMLIterator);
     203       20916 :         ce_SimpleXMLIterator = zend_register_internal_class_ex(&sxi, ce_SimpleXMLElement);
     204       20916 :         ce_SimpleXMLIterator->create_object = ce_SimpleXMLElement->create_object;
     205             : 
     206       20916 :         zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_RecursiveIterator);
     207       20916 :         zend_class_implements(ce_SimpleXMLIterator, 1, spl_ce_Countable);
     208             : 
     209       20916 :         return SUCCESS;
     210             : }
     211             : /* }}} */
     212             : 
     213             : /*
     214             :  * Local variables:
     215             :  * tab-width: 4
     216             :  * c-basic-offset: 4
     217             :  * End:
     218             :  * vim600: fdm=marker
     219             :  * vim: noet sw=4 ts=4
     220             :  */

Generated by: LCOV version 1.10

Generated at Thu, 21 May 2015 19:59:02 +0000 (6 days ago)

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