@@ -57,18 +57,11 @@ public static function decodeAsObject(string $data, array $need_array = []): std
57
57
$ ret ->{$ name } = self ::intoObject ($ xml , $ need_array , $ name );
58
58
return $ ret ;
59
59
}
60
- private static function toXml (&$ data , \Psr \Http \Message \StreamInterface $ result , string $ outer_key ,
60
+ private static function toXml (&$ data ,
61
+ \Psr \Http \Message \StreamInterface $ result ,
62
+ string $ outer_key ,
61
63
?int $ level ): void {
62
- $ is_fixed_array = true ;
63
- $ i = 0 ;
64
- foreach ($ data as $ key => &$ val ) {
65
- if ($ key !== $ i ) {
66
- $ is_fixed_array = false ;
67
- break ;
68
- }
69
- ++$ i ;
70
- }
71
- unset($ val );
64
+ $ is_fixed_array = is_array ($ data ) && array_is_list ($ data );
72
65
73
66
if (! $ is_fixed_array && '' !== $ outer_key ) {
74
67
if ($ level ) {
@@ -80,6 +73,9 @@ private static function toXml(&$data, \Psr\Http\Message\StreamInterface $result,
80
73
}
81
74
}
82
75
foreach ($ data as $ key => &$ val ) {
76
+ if ($ val instanceof \BackedEnum) {
77
+ $ val = $ val ->value ;
78
+ }
83
79
if (is_scalar ($ val )) {
84
80
if (isset ($ level )) {
85
81
$ result ->write (str_repeat (' ' , $ is_fixed_array ? $ level : $ level + 1 ));
@@ -97,8 +93,11 @@ private static function toXml(&$data, \Psr\Http\Message\StreamInterface $result,
97
93
$ result ->write ("\n" );
98
94
}
99
95
} else {
100
- self ::toXml ($ val , $ result , $ is_fixed_array ? $ outer_key : $ key ,
101
- isset ($ level ) ? ($ is_fixed_array ? $ level : $ level + 1 ) : null );
96
+ self ::toXml ($ val ,
97
+ $ result ,
98
+ $ is_fixed_array ? $ outer_key : $ key ,
99
+ isset ($ level ) ? ($ is_fixed_array ? $ level : $ level + 1 ) : null
100
+ );
102
101
}
103
102
}
104
103
if (! $ is_fixed_array && '' !== $ outer_key ) {
0 commit comments