@@ -41,6 +41,11 @@ PHP_SXE_API zend_class_entry *sxe_get_element_class_entry(void) /* {{{ */
41
41
}
42
42
/* }}} */
43
43
44
+ typedef enum sxe_access_mode {
45
+ SXE_ACCESS_ELEMENTS ,
46
+ SXE_ACCESS_ATTRIBS ,
47
+ } sxe_access_mode ;
48
+
44
49
static php_sxe_object * php_sxe_object_new (zend_class_entry * ce , zend_function * fptr_count );
45
50
static xmlNodePtr php_sxe_reset_iterator (php_sxe_object * sxe );
46
51
static 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,
207
212
/* }}} */
208
213
209
214
/* {{{ 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 )
211
216
{
212
217
php_sxe_object * sxe ;
213
218
zend_string * name ;
@@ -231,8 +236,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
231
236
if (Z_TYPE_P (member ) == IS_LONG ) {
232
237
if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
233
238
long_dim :
234
- attribs = 0 ;
235
- elements = 1 ;
239
+ access_mode = SXE_ACCESS_ELEMENTS ;
236
240
}
237
241
name = NULL ;
238
242
} else {
@@ -251,8 +255,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
251
255
GET_NODE (sxe , node );
252
256
253
257
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
254
- attribs = 1 ;
255
- elements = 0 ;
258
+ access_mode = SXE_ACCESS_ATTRIBS ;
256
259
node = php_sxe_get_first_node_non_destructive (sxe , node );
257
260
attr = (xmlAttrPtr )node ;
258
261
test = sxe -> iter .name != NULL ;
@@ -271,7 +274,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
271
274
ZVAL_NULL (rv );
272
275
273
276
if (node ) {
274
- if (attribs ) {
277
+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
275
278
if (Z_TYPE_P (member ) != IS_LONG || sxe -> iter .type == SXE_ITER_ATTRLIST ) {
276
279
if (Z_TYPE_P (member ) == IS_LONG ) {
277
280
while (attr && nodendx <= Z_LVAL_P (member )) {
@@ -294,9 +297,7 @@ static zval *sxe_prop_dim_read(zend_object *object, zval *member, bool elements,
294
297
}
295
298
}
296
299
}
297
- }
298
-
299
- if (elements ) {
300
+ } else {
300
301
if (!sxe -> node ) {
301
302
php_libxml_increment_node_ptr ((php_libxml_node_object * )sxe , node , NULL );
302
303
}
@@ -347,14 +348,14 @@ static zval *sxe_property_read(zend_object *object, zend_string *name, int type,
347
348
{
348
349
zval member ;
349
350
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 );
351
352
}
352
353
/* }}} */
353
354
354
355
/* {{{ sxe_dimension_read() */
355
356
static zval * sxe_dimension_read (zend_object * object , zval * offset , int type , zval * rv )
356
357
{
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 );
358
359
}
359
360
/* }}} */
360
361
@@ -371,7 +372,7 @@ static void change_node_zval(xmlNodePtr node, zend_string *value)
371
372
/* }}} */
372
373
373
374
/* {{{ 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 )
375
376
{
376
377
php_sxe_object * sxe ;
377
378
xmlNodePtr node ;
@@ -405,8 +406,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
405
406
if (Z_TYPE_P (member ) == IS_LONG ) {
406
407
if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
407
408
long_dim :
408
- attribs = 0 ;
409
- elements = 1 ;
409
+ access_mode = SXE_ACCESS_ELEMENTS ;
410
410
}
411
411
} else {
412
412
if (Z_TYPE_P (member ) != IS_STRING ) {
@@ -421,7 +421,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
421
421
}
422
422
423
423
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" );
425
425
if (member == & tmp_zv ) {
426
426
zval_ptr_dtor_str (& tmp_zv );
427
427
}
@@ -433,8 +433,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
433
433
GET_NODE (sxe , node );
434
434
435
435
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
436
- attribs = 1 ;
437
- elements = 0 ;
436
+ access_mode = SXE_ACCESS_ATTRIBS ;
438
437
node = php_sxe_get_first_node_non_destructive (sxe , node );
439
438
attr = (xmlAttrPtr )node ;
440
439
test = sxe -> iter .name != NULL ;
@@ -452,7 +451,7 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
452
451
zend_value_error ("Cannot append to an attribute list" );
453
452
return & EG (error_zval );
454
453
}
455
- if (attribs && !node && sxe -> iter .type == SXE_ITER_ELEMENT ) {
454
+ if (access_mode == SXE_ACCESS_ATTRIBS && !node && sxe -> iter .type == SXE_ITER_ELEMENT ) {
456
455
node = xmlNewChild (mynode , mynode -> ns , BAD_CAST ZSTR_VAL (sxe -> iter .name ), NULL );
457
456
attr = node -> properties ;
458
457
}
@@ -485,15 +484,15 @@ static zval *sxe_prop_dim_write(zend_object *object, zval *member, zval *value,
485
484
if (member == & tmp_zv ) {
486
485
zval_ptr_dtor_str (& tmp_zv );
487
486
}
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 ));
489
488
return & EG (error_zval );
490
489
}
491
490
}
492
491
493
492
if (node ) {
494
493
php_libxml_invalidate_node_list_cache_from_doc (node -> doc );
495
494
496
- if (attribs ) {
495
+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
497
496
if (Z_TYPE_P (member ) == IS_LONG ) {
498
497
while (attr && nodendx <= Z_LVAL_P (member )) {
499
498
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,
516
515
attr = attr -> next ;
517
516
}
518
517
}
519
-
520
- }
521
-
522
- if (elements ) {
518
+ } else {
523
519
if (!member || Z_TYPE_P (member ) == IS_LONG ) {
524
520
if (node -> type == XML_ATTRIBUTE_NODE ) {
525
521
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,
571
567
} else if (counter > 1 ) {
572
568
php_error_docref (NULL , E_WARNING , "Cannot assign to an array of nodes (duplicate subnodes or attr detected)" );
573
569
value = & EG (error_zval );
574
- } else if (elements ) {
570
+ } else if (access_mode == SXE_ACCESS_ELEMENTS ) {
575
571
if (!node ) {
576
572
if (!member || Z_TYPE_P (member ) == IS_LONG ) {
577
573
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,
587
583
}
588
584
newnode = xmlNewTextChild (mynode -> parent , mynode -> ns , mynode -> name , value_str ? (xmlChar * )ZSTR_VAL (value_str ) : NULL );
589
585
}
590
- } else if ( attribs ) {
586
+ } else {
591
587
if (Z_TYPE_P (member ) == IS_LONG ) {
592
588
php_error_docref (NULL , E_WARNING , "Cannot change attribute number " ZEND_LONG_FMT " when only %d attributes exist" , Z_LVAL_P (member ), nodendx );
593
589
} else {
@@ -614,15 +610,15 @@ static zval *sxe_property_write(zend_object *object, zend_string *name, zval *va
614
610
{
615
611
zval member ;
616
612
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 );
618
614
return retval == & EG (error_zval ) ? & EG (uninitialized_zval ) : retval ;
619
615
}
620
616
/* }}} */
621
617
622
618
/* {{{ sxe_dimension_write() */
623
619
static void sxe_dimension_write (zend_object * object , zval * offset , zval * value )
624
620
{
625
- sxe_prop_dim_write (object , offset , value , 0 , 1 , NULL );
621
+ sxe_prop_dim_write (object , offset , value , SXE_ACCESS_ATTRIBS , NULL );
626
622
}
627
623
/* }}} */
628
624
@@ -646,7 +642,7 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f
646
642
return NULL ;
647
643
}
648
644
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 )) {
650
646
return & EG (error_zval );
651
647
}
652
648
type = SXE_ITER_NONE ;
@@ -664,7 +660,7 @@ static zval *sxe_property_get_adr(zend_object *object, zend_string *zname, int f
664
660
/* }}} */
665
661
666
662
/* {{{ 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 )
668
664
{
669
665
php_sxe_object * sxe ;
670
666
xmlNodePtr node ;
@@ -688,17 +684,15 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
688
684
689
685
if (Z_TYPE_P (member ) == IS_LONG ) {
690
686
if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
691
- attribs = 0 ;
692
- elements = 1 ;
687
+ access_mode = SXE_ACCESS_ELEMENTS ;
693
688
if (sxe -> iter .type == SXE_ITER_CHILD ) {
694
689
node = php_sxe_get_first_node_non_destructive (sxe , node );
695
690
}
696
691
}
697
692
}
698
693
699
694
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
700
- attribs = 1 ;
701
- elements = 0 ;
695
+ access_mode = SXE_ACCESS_ATTRIBS ;
702
696
node = php_sxe_get_first_node_non_destructive (sxe , node );
703
697
attr = (xmlAttrPtr )node ;
704
698
test = sxe -> iter .name != NULL ;
@@ -709,7 +703,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
709
703
}
710
704
711
705
if (node ) {
712
- if (attribs ) {
706
+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
713
707
if (Z_TYPE_P (member ) == IS_LONG ) {
714
708
int nodendx = 0 ;
715
709
@@ -738,9 +732,7 @@ static int sxe_prop_dim_exists(zend_object *object, zval *member, int check_empt
738
732
/* Attribute with no content in its text node */
739
733
exists = 0 ;
740
734
}
741
- }
742
-
743
- if (elements ) {
735
+ } else {
744
736
if (Z_TYPE_P (member ) == IS_LONG ) {
745
737
if (sxe -> iter .type == SXE_ITER_CHILD ) {
746
738
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
773
765
{
774
766
zval member ;
775
767
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 );
777
769
}
778
770
/* }}} */
779
771
780
772
/* {{{ sxe_dimension_exists() */
781
773
static int sxe_dimension_exists (zend_object * object , zval * member , int check_empty )
782
774
{
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 );
784
776
}
785
777
/* }}} */
786
778
787
779
/* {{{ 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 )
789
781
{
790
782
php_sxe_object * sxe ;
791
783
xmlNodePtr node ;
@@ -810,17 +802,15 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
810
802
811
803
if (Z_TYPE_P (member ) == IS_LONG ) {
812
804
if (sxe -> iter .type != SXE_ITER_ATTRLIST ) {
813
- attribs = 0 ;
814
- elements = 1 ;
805
+ access_mode = SXE_ACCESS_ELEMENTS ;
815
806
if (sxe -> iter .type == SXE_ITER_CHILD ) {
816
807
node = php_sxe_get_first_node_non_destructive (sxe , node );
817
808
}
818
809
}
819
810
}
820
811
821
812
if (sxe -> iter .type == SXE_ITER_ATTRLIST ) {
822
- attribs = 1 ;
823
- elements = 0 ;
813
+ access_mode = SXE_ACCESS_ATTRIBS ;
824
814
node = php_sxe_get_first_node_non_destructive (sxe , node );
825
815
attr = (xmlAttrPtr )node ;
826
816
test = sxe -> iter .name != NULL ;
@@ -833,7 +823,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
833
823
if (node ) {
834
824
php_libxml_invalidate_node_list_cache_from_doc (node -> doc );
835
825
836
- if (attribs ) {
826
+ if (access_mode == SXE_ACCESS_ATTRIBS ) {
837
827
if (Z_TYPE_P (member ) == IS_LONG ) {
838
828
int nodendx = 0 ;
839
829
@@ -857,9 +847,7 @@ static void sxe_prop_dim_delete(zend_object *object, zval *member, bool elements
857
847
attr = anext ;
858
848
}
859
849
}
860
- }
861
-
862
- if (elements ) {
850
+ } else {
863
851
if (Z_TYPE_P (member ) == IS_LONG ) {
864
852
if (sxe -> iter .type == SXE_ITER_CHILD ) {
865
853
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
897
885
{
898
886
zval member ;
899
887
ZVAL_STR (& member , name );
900
- sxe_prop_dim_delete (object , & member , 1 , 0 );
888
+ sxe_prop_dim_delete (object , & member , SXE_ACCESS_ELEMENTS );
901
889
}
902
890
/* }}} */
903
891
904
892
/* {{{ sxe_dimension_unset() */
905
893
static void sxe_dimension_delete (zend_object * object , zval * offset )
906
894
{
907
- sxe_prop_dim_delete (object , offset , 0 , 1 );
895
+ sxe_prop_dim_delete (object , offset , SXE_ACCESS_ATTRIBS );
908
896
}
909
897
/* }}} */
910
898
0 commit comments