@@ -41,6 +41,11 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry(void) /* {{{ */
4141}
4242/* }}} */
4343
44+ typedef enum sxe_access_mode {
45+ SXE_ACCESS_ELEMENTS ,
46+ SXE_ACCESS_ATTRIBS ,
47+ } sxe_access_mode ;
48+
4449static php_sxe_object * php_sxe_object_new (zend_class_entry * ce , zend_function * fptr_count );
4550static xmlNodePtr php_sxe_reset_iterator (php_sxe_object * sxe );
4651static xmlNodePtr php_sxe_reset_iterator_no_clear_iter_data (php_sxe_object * sxe , int use_data );
@@ -207,7 +212,7 @@ static xmlNodePtr sxe_get_element_by_name(php_sxe_object *sxe, xmlNodePtr node,
207212/* }}} */
208213
209214/* {{{ sxe_prop_dim_read() */
210- static zval * sxe_prop_dim_read (zend_object * object , zval * member , bool elements , bool attribs , int type , zval * rv )
215+ static zval * sxe_prop_dim_read (zend_object * object , zval * member , sxe_access_mode access_mode , int type , zval * rv )
211216{
212217 php_sxe_object * sxe ;
213218 zend_string * name ;
@@ -231,8 +236,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
231236 if (Z_TYPE_P (member ) == IS_LONG ) {
232237 if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
233238long_dim :
234- attribs = 0 ;
235- elements = 1 ;
239+ access_mode = SXE_ACCESS_ELEMENTS ;
236240 }
237241 name = NULL ;
238242 } else {
@@ -251,8 +255,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
251255 GET_NODE (sxe , node );
252256
253257 if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
254- attribs = 1 ;
255- elements = 0 ;
258+ access_mode = SXE_ACCESS_ATTRIBS ;
256259 node = php_sxe_get_first_node_non_destructive (sxe , node );
257260 attr = (xmlAttrPtr )node ;
258261 test = sxe -> iter .name != NULL ;
@@ -271,7 +274,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
271274 ZVAL_NULL (rv );
272275
273276 if (node ) {
274- if (attribs ) {
277+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
275278 if (Z_TYPE_P (member ) != IS_LONG || sxe -> iter .type == SXE_ITER_ATTRLIST ) {
276279 if (Z_TYPE_P (member ) == IS_LONG ) {
277280 while (attr && nodendx <= Z_LVAL_P (member )) {
@@ -294,9 +297,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
294297 }
295298 }
296299 }
297- }
298-
299- if (elements ) {
300+ } else {
300301 if (!sxe -> node ) {
301302 php_libxml_increment_node_ptr ((php_libxml_node_object * )sxe , node , NULL );
302303 }
@@ -347,14 +348,14 @@ static zval *sxe_property_read(zend_object *object, zend_string *name, int type,
347348{
348349 zval member ;
349350 ZVAL_STR (& member , name );
350- return sxe_prop_dim_read (object , & member , 1 , 0 , type , rv );
351+ return sxe_prop_dim_read (object , & member , SXE_ACCESS_ELEMENTS , type , rv );
351352}
352353/* }}} */
353354
354355/* {{{ sxe_dimension_read() */
355356static zval * sxe_dimension_read (zend_object * object , zval * offset , int type , zval * rv )
356357{
357- return sxe_prop_dim_read (object , offset , 0 , 1 , type , rv );
358+ return sxe_prop_dim_read (object , offset , SXE_ACCESS_ATTRIBS , type , rv );
358359}
359360/* }}} */
360361
@@ -371,7 +372,7 @@ static void change_node_zval(xmlNodePtr node, zend_string *value)
371372/* }}} */
372373
373374/* {{{ sxe_property_write() */
374- static zval * sxe_prop_dim_write (zend_object * object , zval * member , zval * value , bool elements , bool attribs , xmlNodePtr * pnewnode )
375+ static zval * sxe_prop_dim_write (zend_object * object , zval * member , zval * value , sxe_access_mode access_mode , xmlNodePtr * pnewnode )
375376{
376377 php_sxe_object * sxe ;
377378 xmlNodePtr node ;
@@ -405,8 +406,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
405406 if (Z_TYPE_P (member ) == IS_LONG ) {
406407 if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
407408long_dim :
408- attribs = 0 ;
409- elements = 1 ;
409+ access_mode = SXE_ACCESS_ELEMENTS ;
410410 }
411411 } else {
412412 if (Z_TYPE_P (member ) != IS_STRING ) {
@@ -421,7 +421,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
421421 }
422422
423423 if (!Z_STRLEN_P (member )) {
424- zend_value_error ("Cannot create %s with an empty name" , attribs ? "attribute" : "element" );
424+ zend_value_error ("Cannot create %s with an empty name" , access_mode == SXE_ACCESS_ATTRIBS ? "attribute" : "element" );
425425 if (member == & tmp_zv ) {
426426 zval_ptr_dtor_str (& tmp_zv );
427427 }
@@ -433,8 +433,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
433433 GET_NODE (sxe , node );
434434
435435 if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
436- attribs = 1 ;
437- elements = 0 ;
436+ access_mode = SXE_ACCESS_ATTRIBS ;
438437 node = php_sxe_get_first_node_non_destructive (sxe , node );
439438 attr = (xmlAttrPtr )node ;
440439 test = sxe -> iter .name != NULL ;
@@ -452,7 +451,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
452451 zend_value_error ("Cannot append to an attribute list" );
453452 return & EG (error_zval );
454453 }
455- if (attribs && !node && sxe -> iter .type == SXE_ITER_ELEMENT ) {
454+ if (access_mode == SXE_ACCESS_ATTRIBS && !node && sxe -> iter .type == SXE_ITER_ELEMENT ) {
456455 node = xmlNewChild (mynode , mynode -> ns , BAD_CAST ZSTR_VAL (sxe -> iter .name ), NULL );
457456 attr = node -> properties ;
458457 }
@@ -485,15 +484,15 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
485484 if (member == & tmp_zv ) {
486485 zval_ptr_dtor_str (& tmp_zv );
487486 }
488- zend_type_error ("It's not possible to assign a complex type to %s, %s given" , attribs ? "attributes" : "properties" , zend_zval_value_name (value ));
487+ zend_type_error ("It's not possible to assign a complex type to %s, %s given" , access_mode == SXE_ACCESS_ATTRIBS ? "attributes" : "properties" , zend_zval_value_name (value ));
489488 return & EG (error_zval );
490489 }
491490 }
492491
493492 if (node ) {
494493 php_libxml_invalidate_node_list_cache_from_doc (node -> doc );
495494
496- if (attribs ) {
495+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
497496 if (Z_TYPE_P (member ) == IS_LONG ) {
498497 while (attr && nodendx <= Z_LVAL_P (member )) {
499498 if ((!test || xmlStrEqual (attr -> name , BAD_CAST ZSTR_VAL (sxe -> iter .name ))) && match_ns ((xmlNodePtr ) attr , sxe -> iter .nsprefix , sxe -> iter .isprefix )) {
@@ -516,10 +515,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
516515 attr = attr -> next ;
517516 }
518517 }
519-
520- }
521-
522- if (elements ) {
518+ } else {
523519 if (!member || Z_TYPE_P (member ) == IS_LONG ) {
524520 if (node -> type == XML_ATTRIBUTE_NODE ) {
525521 zend_throw_error (NULL , "Cannot create duplicate attribute" );
@@ -571,7 +567,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
571567 } else if (counter > 1 ) {
572568 php_error_docref (NULL , E_WARNING , "Cannot assign to an array of nodes (duplicate subnodes or attr detected)" );
573569 value = & EG (error_zval );
574- } else if (elements ) {
570+ } else if (access_mode == SXE_ACCESS_ELEMENTS ) {
575571 if (!node ) {
576572 if (!member || Z_TYPE_P (member ) == IS_LONG ) {
577573 newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value_str ? (xmlChar * )ZSTR_VAL (value_str ) : NULL );
@@ -587,7 +583,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
587583 }
588584 newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value_str ? (xmlChar * )ZSTR_VAL (value_str ) : NULL );
589585 }
590- } else if ( attribs ) {
586+ } else {
591587 if (Z_TYPE_P (member ) == IS_LONG ) {
592588 php_error_docref (NULL , E_WARNING , "Cannot change attribute number " ZEND_LONG_FMT " when only %d attributes exist" , Z_LVAL_P (member ), nodendx );
593589 } else {
@@ -614,15 +610,15 @@ static zval *sxe_property_write(zend_object *object, zend_string *name, zval *va
614610{
615611 zval member ;
616612 ZVAL_STR (& member , name );
617- zval * retval = sxe_prop_dim_write (object , & member , value , 1 , 0 , NULL );
613+ zval * retval = sxe_prop_dim_write (object , & member , value , SXE_ACCESS_ELEMENTS , NULL );
618614 return retval == & EG (error_zval ) ? & EG (uninitialized_zval ) : retval ;
619615}
620616/* }}} */
621617
622618/* {{{ sxe_dimension_write() */
623619static void sxe_dimension_write (zend_object * object , zval * offset , zval * value )
624620{
625- sxe_prop_dim_write (object , offset , value , 0 , 1 , NULL );
621+ sxe_prop_dim_write (object , offset , value , SXE_ACCESS_ATTRIBS , NULL );
626622}
627623/* }}} */
628624
@@ -646,7 +642,7 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f
646642 return NULL ;
647643 }
648644 ZVAL_STR (& member , zname );
649- if (sxe_prop_dim_write (object , & member , NULL , 1 , 0 , & node ) == & EG (error_zval )) {
645+ if (sxe_prop_dim_write (object , & member , NULL , SXE_ACCESS_ELEMENTS , & node ) == & EG (error_zval )) {
650646 return & EG (error_zval );
651647 }
652648 type = SXE_ITER_NONE ;
@@ -664,7 +660,7 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f
664660/* }}} */
665661
666662/* {{{ sxe_prop_dim_exists() */
667- static int sxe_prop_dim_exists (zend_object * object , zval * member , int check_empty , bool elements , bool attribs )
663+ static int sxe_prop_dim_exists (zend_object * object , zval * member , int check_empty , sxe_access_mode access_mode )
668664{
669665 php_sxe_object * sxe ;
670666 xmlNodePtr node ;
@@ -688,17 +684,15 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
688684
689685 if (Z_TYPE_P (member ) == IS_LONG ) {
690686 if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
691- attribs = 0 ;
692- elements = 1 ;
687+ access_mode = SXE_ACCESS_ELEMENTS ;
693688 if (sxe -> iter .type == SXE_ITER_CHILD ) {
694689 node = php_sxe_get_first_node_non_destructive (sxe , node );
695690 }
696691 }
697692 }
698693
699694 if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
700- attribs = 1 ;
701- elements = 0 ;
695+ access_mode = SXE_ACCESS_ATTRIBS ;
702696 node = php_sxe_get_first_node_non_destructive (sxe , node );
703697 attr = (xmlAttrPtr )node ;
704698 test = sxe -> iter .name != NULL ;
@@ -709,7 +703,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
709703 }
710704
711705 if (node ) {
712- if (attribs ) {
706+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
713707 if (Z_TYPE_P (member ) == IS_LONG ) {
714708 int nodendx = 0 ;
715709
@@ -738,9 +732,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
738732 /* Attribute with no content in its text node */
739733 exists = 0 ;
740734 }
741- }
742-
743- if (elements ) {
735+ } else {
744736 if (Z_TYPE_P (member ) == IS_LONG ) {
745737 if (sxe -> iter .type == SXE_ITER_CHILD ) {
746738 node = php_sxe_get_first_node_non_destructive (sxe , node );
@@ -773,19 +765,19 @@ static int sxe_property_exists(zend_object *object, zend_string *name, int check
773765{
774766 zval member ;
775767 ZVAL_STR (& member , name );
776- return sxe_prop_dim_exists (object , & member , check_empty , 1 , 0 );
768+ return sxe_prop_dim_exists (object , & member , check_empty , SXE_ACCESS_ELEMENTS );
777769}
778770/* }}} */
779771
780772/* {{{ sxe_dimension_exists() */
781773static int sxe_dimension_exists (zend_object * object , zval * member , int check_empty )
782774{
783- return sxe_prop_dim_exists (object , member , check_empty , 0 , 1 );
775+ return sxe_prop_dim_exists (object , member , check_empty , SXE_ACCESS_ATTRIBS );
784776}
785777/* }}} */
786778
787779/* {{{ sxe_prop_dim_delete() */
788- static void sxe_prop_dim_delete (zend_object * object , zval * member , bool elements , bool attribs )
780+ static void sxe_prop_dim_delete (zend_object * object , zval * member , sxe_access_mode access_mode )
789781{
790782 php_sxe_object * sxe ;
791783 xmlNodePtr node ;
@@ -810,17 +802,15 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
810802
811803 if (Z_TYPE_P (member ) == IS_LONG ) {
812804 if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
813- attribs = 0 ;
814- elements = 1 ;
805+ access_mode = SXE_ACCESS_ELEMENTS ;
815806 if (sxe -> iter .type == SXE_ITER_CHILD ) {
816807 node = php_sxe_get_first_node_non_destructive (sxe , node );
817808 }
818809 }
819810 }
820811
821812 if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
822- attribs = 1 ;
823- elements = 0 ;
813+ access_mode = SXE_ACCESS_ATTRIBS ;
824814 node = php_sxe_get_first_node_non_destructive (sxe , node );
825815 attr = (xmlAttrPtr )node ;
826816 test = sxe -> iter .name != NULL ;
@@ -833,7 +823,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
833823 if (node ) {
834824 php_libxml_invalidate_node_list_cache_from_doc (node -> doc );
835825
836- if (attribs ) {
826+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
837827 if (Z_TYPE_P (member ) == IS_LONG ) {
838828 int nodendx = 0 ;
839829
@@ -857,9 +847,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
857847 attr = anext ;
858848 }
859849 }
860- }
861-
862- if (elements ) {
850+ } else {
863851 if (Z_TYPE_P (member ) == IS_LONG ) {
864852 if (sxe -> iter .type == SXE_ITER_CHILD ) {
865853 node = php_sxe_get_first_node_non_destructive (sxe , node );
@@ -897,14 +885,14 @@ static void sxe_property_delete(zend_object *object, zend_string *name, void **c
897885{
898886 zval member ;
899887 ZVAL_STR (& member , name );
900- sxe_prop_dim_delete (object , & member , 1 , 0 );
888+ sxe_prop_dim_delete (object , & member , SXE_ACCESS_ELEMENTS );
901889}
902890/* }}} */
903891
904892/* {{{ sxe_dimension_unset() */
905893static void sxe_dimension_delete (zend_object * object , zval * offset )
906894{
907- sxe_prop_dim_delete (object , offset , 0 , 1 );
895+ sxe_prop_dim_delete (object , offset , SXE_ACCESS_ATTRIBS );
908896}
909897/* }}} */
910898
0 commit comments