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
{
@@ -2024,6 +2026,138 @@ SXE_METHOD(count)
2024
2026
}
2025
2027
/* }}} */
2026
2028
2029
+
2030
+ /* {{{ proto void SimpleXMLElement::rewind()
2031
+ Rewind to first element */
2032
+ SXE_METHOD (rewind )
2033
+ {
2034
+ if (zend_parse_parameters_none () == FAILURE ) {
2035
+ RETURN_THROWS ();
2036
+ }
2037
+
2038
+ php_sxe_rewind_iterator (Z_SXEOBJ_P (ZEND_THIS ));
2039
+ }
2040
+ /* }}} */
2041
+
2042
+ /* {{{ proto bool SimpleXMLElement::valid()
2043
+ Check whether iteration is valid */
2044
+ SXE_METHOD (valid )
2045
+ {
2046
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2047
+
2048
+ if (zend_parse_parameters_none () == FAILURE ) {
2049
+ RETURN_THROWS ();
2050
+ }
2051
+
2052
+ RETURN_BOOL (!Z_ISUNDEF (sxe -> iter .data ));
2053
+ }
2054
+ /* }}} */
2055
+
2056
+ /* {{{ proto SimpleXMLElement SimpleXMLElement::current()
2057
+ Get current element */
2058
+ SXE_METHOD (current )
2059
+ {
2060
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2061
+ zval * data ;
2062
+
2063
+ if (zend_parse_parameters_none () == FAILURE ) {
2064
+ RETURN_THROWS ();
2065
+ }
2066
+
2067
+ if (Z_ISUNDEF (sxe -> iter .data )) {
2068
+ return ; /* return NULL */
2069
+ }
2070
+
2071
+ data = & sxe -> iter .data ;
2072
+ ZVAL_COPY_DEREF (return_value , data );
2073
+ }
2074
+ /* }}} */
2075
+
2076
+ /* {{{ proto string SimpleXMLElement::key()
2077
+ Get name of current child element */
2078
+ SXE_METHOD (key )
2079
+ {
2080
+ xmlNodePtr curnode ;
2081
+ php_sxe_object * intern ;
2082
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2083
+
2084
+ if (zend_parse_parameters_none () == FAILURE ) {
2085
+ RETURN_THROWS ();
2086
+ }
2087
+
2088
+ if (Z_ISUNDEF (sxe -> iter .data )) {
2089
+ RETURN_FALSE ;
2090
+ }
2091
+
2092
+ intern = Z_SXEOBJ_P (& sxe -> iter .data );
2093
+ if (intern != NULL && intern -> node != NULL ) {
2094
+ curnode = (xmlNodePtr )((php_libxml_node_ptr * )intern -> node )-> node ;
2095
+ RETURN_STRINGL ((char * )curnode -> name , xmlStrlen (curnode -> name ));
2096
+ }
2097
+
2098
+ RETURN_FALSE ;
2099
+ }
2100
+ /* }}} */
2101
+
2102
+ /* {{{ proto void SimpleXMLElement::next()
2103
+ Move to next element */
2104
+ SXE_METHOD (next )
2105
+ {
2106
+ if (zend_parse_parameters_none () == FAILURE ) {
2107
+ RETURN_THROWS ();
2108
+ }
2109
+
2110
+ php_sxe_move_forward_iterator (Z_SXEOBJ_P (ZEND_THIS ));
2111
+ }
2112
+ /* }}} */
2113
+
2114
+ /* {{{ proto bool SimpleXMLElement::hasChildren()
2115
+ Check whether element has children (elements) */
2116
+ SXE_METHOD (hasChildren )
2117
+ {
2118
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2119
+ php_sxe_object * child ;
2120
+ xmlNodePtr node ;
2121
+
2122
+ if (zend_parse_parameters_none () == FAILURE ) {
2123
+ RETURN_THROWS ();
2124
+ }
2125
+
2126
+ if (Z_ISUNDEF (sxe -> iter .data ) || sxe -> iter .type == SXE_ITER_ATTRLIST ) {
2127
+ RETURN_FALSE ;
2128
+ }
2129
+ child = Z_SXEOBJ_P (& sxe -> iter .data );
2130
+
2131
+ GET_NODE (child , node );
2132
+ if (node ) {
2133
+ node = node -> children ;
2134
+ }
2135
+ while (node && node -> type != XML_ELEMENT_NODE ) {
2136
+ node = node -> next ;
2137
+ }
2138
+ RETURN_BOOL (node ? 1 : 0 );
2139
+ }
2140
+ /* }}} */
2141
+
2142
+ /* {{{ proto SimpleXMLElement SimpleXMLElement::getChildren()
2143
+ Get child element iterator */
2144
+ SXE_METHOD (getChildren )
2145
+ {
2146
+ php_sxe_object * sxe = Z_SXEOBJ_P (ZEND_THIS );
2147
+ zval * data ;
2148
+
2149
+ if (zend_parse_parameters_none () == FAILURE ) {
2150
+ RETURN_THROWS ();
2151
+ }
2152
+
2153
+ if (Z_ISUNDEF (sxe -> iter .data ) || sxe -> iter .type == SXE_ITER_ATTRLIST ) {
2154
+ return ; /* return NULL */
2155
+ }
2156
+
2157
+ data = & sxe -> iter .data ;
2158
+ ZVAL_COPY_DEREF (return_value , data );
2159
+ }
2160
+
2027
2161
static zend_object_handlers sxe_object_handlers ;
2028
2162
2029
2163
/* {{{ sxe_object_clone()
@@ -2606,13 +2740,14 @@ ZEND_GET_MODULE(simplexml)
2606
2740
*/
2607
2741
PHP_MINIT_FUNCTION (simplexml )
2608
2742
{
2609
- zend_class_entry sxe ;
2743
+ zend_class_entry ce ;
2610
2744
2611
- INIT_CLASS_ENTRY (sxe , "SimpleXMLElement" , class_SimpleXMLElement_methods );
2612
- sxe . create_object = sxe_object_new ;
2613
- sxe_class_entry = zend_register_internal_class ( & sxe ) ;
2745
+ INIT_CLASS_ENTRY (ce , "SimpleXMLElement" , class_SimpleXMLElement_methods );
2746
+ sxe_class_entry = zend_register_internal_class ( & ce ) ;
2747
+ sxe_class_entry -> create_object = sxe_object_new ;
2614
2748
sxe_class_entry -> get_iterator = php_sxe_get_iterator ;
2615
- zend_class_implements (sxe_class_entry , 3 , zend_ce_traversable , zend_ce_countable , zend_ce_stringable );
2749
+ zend_class_implements (sxe_class_entry , 3 ,
2750
+ zend_ce_countable , zend_ce_stringable , spl_ce_RecursiveIterator );
2616
2751
2617
2752
memcpy (& sxe_object_handlers , & std_object_handlers , sizeof (zend_object_handlers ));
2618
2753
sxe_object_handlers .offset = XtOffsetOf (php_sxe_object , zo );
@@ -2639,9 +2774,13 @@ PHP_MINIT_FUNCTION(simplexml)
2639
2774
sxe_class_entry -> serialize = zend_class_serialize_deny ;
2640
2775
sxe_class_entry -> unserialize = zend_class_unserialize_deny ;
2641
2776
2642
- php_libxml_register_export (sxe_class_entry , simplexml_export_node );
2777
+ /* TODO: Why do we have two variables for this? */
2778
+ ce_SimpleXMLElement = sxe_class_entry ;
2643
2779
2644
- PHP_MINIT (sxe )(INIT_FUNC_ARGS_PASSTHRU );
2780
+ INIT_CLASS_ENTRY (ce , "SimpleXMLIterator" , NULL );
2781
+ ce_SimpleXMLIterator = zend_register_internal_class_ex (& ce , ce_SimpleXMLElement );
2782
+
2783
+ php_libxml_register_export (sxe_class_entry , simplexml_export_node );
2645
2784
2646
2785
return SUCCESS ;
2647
2786
}
0 commit comments