@@ -123,13 +123,7 @@ public static function dump(mixed $value, int $flags = 0): string
123
123
}
124
124
125
125
if (Yaml::DUMP_OBJECT_AS_MAP & $ flags && ($ value instanceof \stdClass || $ value instanceof \ArrayObject)) {
126
- $ output = [];
127
-
128
- foreach ($ value as $ key => $ val ) {
129
- $ output [] = sprintf ('%s: %s ' , self ::dump ($ key , $ flags ), self ::dump ($ val , $ flags ));
130
- }
131
-
132
- return sprintf ('{ %s } ' , implode (', ' , $ output ));
126
+ return self ::dumpHashArray ($ value , $ flags );
133
127
}
134
128
135
129
if (Yaml::DUMP_EXCEPTION_ON_INVALID_TYPE & $ flags ) {
@@ -232,7 +226,17 @@ private static function dumpArray(array $value, int $flags): string
232
226
return sprintf ('[%s] ' , implode (', ' , $ output ));
233
227
}
234
228
235
- // hash
229
+ return self ::dumpHashArray ($ value , $ flags );
230
+ }
231
+
232
+ /**
233
+ * Dumps hash array to a YAML string.
234
+ *
235
+ * @param array|\ArrayObject|\stdClass $value The hash array to dump
236
+ * @param int $flags A bit field of Yaml::DUMP_* constants to customize the dumped YAML string
237
+ */
238
+ private static function dumpHashArray (array |\ArrayObject |\stdClass $ value , int $ flags ): string
239
+ {
236
240
$ output = [];
237
241
foreach ($ value as $ key => $ val ) {
238
242
$ output [] = sprintf ('%s: %s ' , self ::dump ($ key , $ flags ), self ::dump ($ val , $ flags ));
0 commit comments