31
31
#include "simplexml_arginfo.h"
32
32
#include "zend_exceptions.h"
33
33
#include "zend_interfaces.h"
34
- #include "sxe .h"
34
+ #include "ext/spl/spl_iterators .h"
35
35
36
36
zend_class_entry * sxe_class_entry = NULL ;
37
+ PHP_SXE_API zend_class_entry * ce_SimpleXMLIterator ;
38
+ PHP_SXE_API zend_class_entry * ce_SimpleXMLElement ;
37
39
38
40
PHP_SXE_API zend_class_entry * sxe_get_element_class_entry () /* {{{ */
39
41
{
@@ -2016,6 +2018,138 @@ SXE_METHOD(count)
2016
2018
}
2017
2019
/* }}} */
2018
2020
2021
+
2022
+ /* {{{ proto void SimpleXMLElement::rewind()
2023
+ Rewind to first element */
2024
+ SXE_METHOD (rewind )
2025
+ {
2026
+ if (zend_parse_parameters_none () == FAILURE ) {
2027
+ RETURN_THROWS ();
2028
+ }
2029
+
2030
+ php_sxe_rewind_iterator (Z_SXEOBJ_P (ZEND_THIS ));
2031
+ }
2032
+ /* }}} */
2033
+
2034
+ /* {{{ proto bool SimpleXMLElement::valid()
2035
+ Check whether iteration is valid */
2036
+ SXE_METHOD (valid )
2037
+ {
2038
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2039
+
2040
+ if (zend_parse_parameters_none () == FAILURE ) {
2041
+ RETURN_THROWS ();
2042
+ }
2043
+
2044
+ RETURN_BOOL (!Z_ISUNDEF (sxe -> iter .data ));
2045
+ }
2046
+ /* }}} */
2047
+
2048
+ /* {{{ proto SimpleXMLElement SimpleXMLElement::current()
2049
+ Get current element */
2050
+ SXE_METHOD (current )
2051
+ {
2052
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2053
+ zval * data ;
2054
+
2055
+ if (zend_parse_parameters_none () == FAILURE ) {
2056
+ RETURN_THROWS ();
2057
+ }
2058
+
2059
+ if (Z_ISUNDEF (sxe -> iter .data )) {
2060
+ return ; /* return NULL */
2061
+ }
2062
+
2063
+ data = & sxe -> iter .data ;
2064
+ ZVAL_COPY_DEREF (return_value , data );
2065
+ }
2066
+ /* }}} */
2067
+
2068
+ /* {{{ proto string SimpleXMLElement::key()
2069
+ Get name of current child element */
2070
+ SXE_METHOD (key )
2071
+ {
2072
+ xmlNodePtr curnode ;
2073
+ php_sxe_object * intern ;
2074
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2075
+
2076
+ if (zend_parse_parameters_none () == FAILURE ) {
2077
+ RETURN_THROWS ();
2078
+ }
2079
+
2080
+ if (Z_ISUNDEF (sxe -> iter .data )) {
2081
+ RETURN_FALSE ;
2082
+ }
2083
+
2084
+ intern = Z_SXEOBJ_P (& sxe -> iter .data );
2085
+ if (intern != NULL && intern -> node != NULL ) {
2086
+ curnode = (xmlNodePtr )((php_libxml_node_ptr * )intern -> node )-> node ;
2087
+ RETURN_STRINGL ((char * )curnode -> name , xmlStrlen (curnode -> name ));
2088
+ }
2089
+
2090
+ RETURN_FALSE ;
2091
+ }
2092
+ /* }}} */
2093
+
2094
+ /* {{{ proto void SimpleXMLElement::next()
2095
+ Move to next element */
2096
+ SXE_METHOD (next )
2097
+ {
2098
+ if (zend_parse_parameters_none () == FAILURE ) {
2099
+ RETURN_THROWS ();
2100
+ }
2101
+
2102
+ php_sxe_move_forward_iterator (Z_SXEOBJ_P (ZEND_THIS ));
2103
+ }
2104
+ /* }}} */
2105
+
2106
+ /* {{{ proto bool SimpleXMLElement::hasChildren()
2107
+ Check whether element has children (elements) */
2108
+ SXE_METHOD (hasChildren )
2109
+ {
2110
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2111
+ php_sxe_object * child ;
2112
+ xmlNodePtr node ;
2113
+
2114
+ if (zend_parse_parameters_none () == FAILURE ) {
2115
+ RETURN_THROWS ();
2116
+ }
2117
+
2118
+ if (Z_ISUNDEF (sxe -> iter .data ) || sxe -> iter .type == SXE_ITER_ATTRLIST ) {
2119
+ RETURN_FALSE ;
2120
+ }
2121
+ child = Z_SXEOBJ_P (& sxe -> iter .data );
2122
+
2123
+ GET_NODE (child , node );
2124
+ if (node ) {
2125
+ node = node -> children ;
2126
+ }
2127
+ while (node && node -> type != XML_ELEMENT_NODE ) {
2128
+ node = node -> next ;
2129
+ }
2130
+ RETURN_BOOL (node ? 1 : 0 );
2131
+ }
2132
+ /* }}} */
2133
+
2134
+ /* {{{ proto SimpleXMLElement SimpleXMLElement::getChildren()
2135
+ Get child element iterator */
2136
+ SXE_METHOD (getChildren )
2137
+ {
2138
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2139
+ zval * data ;
2140
+
2141
+ if (zend_parse_parameters_none () == FAILURE ) {
2142
+ RETURN_THROWS ();
2143
+ }
2144
+
2145
+ if (Z_ISUNDEF (sxe -> iter .data ) || sxe -> iter .type == SXE_ITER_ATTRLIST ) {
2146
+ return ; /* return NULL */
2147
+ }
2148
+
2149
+ data = & sxe -> iter .data ;
2150
+ ZVAL_COPY_DEREF (return_value , data );
2151
+ }
2152
+
2019
2153
static zend_object_handlers sxe_object_handlers ;
2020
2154
2021
2155
/* {{{ sxe_object_clone()
@@ -2619,6 +2753,13 @@ static const zend_function_entry sxe_functions[] = { /* {{{ */
2619
2753
SXE_ME (addAttribute , arginfo_class_SimpleXMLElement_addAttribute , ZEND_ACC_PUBLIC )
2620
2754
SXE_ME (__toString , arginfo_class_SimpleXMLElement___toString , ZEND_ACC_PUBLIC )
2621
2755
SXE_ME (count , arginfo_class_SimpleXMLElement_count , ZEND_ACC_PUBLIC )
2756
+ SXE_ME (rewind , arginfo_class_SimpleXMLElement_rewind , ZEND_ACC_PUBLIC )
2757
+ SXE_ME (valid , arginfo_class_SimpleXMLElement_valid , ZEND_ACC_PUBLIC )
2758
+ SXE_ME (current , arginfo_class_SimpleXMLElement_current , ZEND_ACC_PUBLIC )
2759
+ SXE_ME (key , arginfo_class_SimpleXMLElement_key , ZEND_ACC_PUBLIC )
2760
+ SXE_ME (next , arginfo_class_SimpleXMLElement_next , ZEND_ACC_PUBLIC )
2761
+ SXE_ME (hasChildren , arginfo_class_SimpleXMLElement_hasChildren , ZEND_ACC_PUBLIC )
2762
+ SXE_ME (getChildren , arginfo_class_SimpleXMLElement_getChildren , ZEND_ACC_PUBLIC )
2622
2763
PHP_FE_END
2623
2764
};
2624
2765
/* }}} */
@@ -2627,13 +2768,14 @@ static const zend_function_entry sxe_functions[] = { /* {{{ */
2627
2768
*/
2628
2769
PHP_MINIT_FUNCTION (simplexml )
2629
2770
{
2630
- zend_class_entry sxe ;
2771
+ zend_class_entry ce ;
2631
2772
2632
- INIT_CLASS_ENTRY (sxe , "SimpleXMLElement" , sxe_functions );
2633
- sxe . create_object = sxe_object_new ;
2634
- sxe_class_entry = zend_register_internal_class ( & sxe ) ;
2773
+ INIT_CLASS_ENTRY (ce , "SimpleXMLElement" , sxe_functions );
2774
+ sxe_class_entry = zend_register_internal_class ( & ce ) ;
2775
+ sxe_class_entry -> create_object = sxe_object_new ;
2635
2776
sxe_class_entry -> get_iterator = php_sxe_get_iterator ;
2636
- zend_class_implements (sxe_class_entry , 3 , zend_ce_traversable , zend_ce_countable , zend_ce_stringable );
2777
+ zend_class_implements (sxe_class_entry , 3 ,
2778
+ zend_ce_countable , zend_ce_stringable , spl_ce_RecursiveIterator );
2637
2779
2638
2780
memcpy (& sxe_object_handlers , & std_object_handlers , sizeof (zend_object_handlers ));
2639
2781
sxe_object_handlers .offset = XtOffsetOf (php_sxe_object , zo );
@@ -2660,9 +2802,13 @@ PHP_MINIT_FUNCTION(simplexml)
2660
2802
sxe_class_entry -> serialize = zend_class_serialize_deny ;
2661
2803
sxe_class_entry -> unserialize = zend_class_unserialize_deny ;
2662
2804
2663
- php_libxml_register_export (sxe_class_entry , simplexml_export_node );
2805
+ /* TODO: Why do we have two variables for this? */
2806
+ ce_SimpleXMLElement = sxe_class_entry ;
2664
2807
2665
- PHP_MINIT (sxe )(INIT_FUNC_ARGS_PASSTHRU );
2808
+ INIT_CLASS_ENTRY (ce , "SimpleXMLIterator" , NULL );
2809
+ ce_SimpleXMLIterator = zend_register_internal_class_ex (& ce , ce_SimpleXMLElement );
2810
+
2811
+ php_libxml_register_export (sxe_class_entry , simplexml_export_node );
2666
2812
2667
2813
return SUCCESS ;
2668
2814
}
0 commit comments