@@ -58,6 +58,8 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
58
58
59
59
if ($ inline <= 0 || (!\is_array ($ input ) && !$ input instanceof TaggedValue && $ dumpObjectAsInlineMap ) || empty ($ input )) {
60
60
$ output .= $ prefix .Inline::dump ($ input , $ flags );
61
+ } elseif ($ input instanceof TaggedValue) {
62
+ $ output .= $ this ->dumpTaggedValue ($ input , $ inline , $ indent , $ flags , $ prefix );
61
63
} else {
62
64
$ dumpAsMap = Inline::isHash ($ input );
63
65
@@ -137,4 +139,28 @@ public function dump($input, int $inline = 0, int $indent = 0, int $flags = 0):
137
139
138
140
return $ output ;
139
141
}
142
+
143
+ private function dumpTaggedValue (TaggedValue $ value , int $ inline , int $ indent , int $ flags , string $ prefix ): string
144
+ {
145
+ $ output = sprintf ('%s!%s ' , $ prefix ? $ prefix .' ' : '' , $ value ->getTag ());
146
+
147
+ if (Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK & $ flags && \is_string ($ value ->getValue ()) && false !== strpos ($ value ->getValue (), "\n" ) && false === strpos ($ value ->getValue (), "\r\n" )) {
148
+ // If the first line starts with a space character, the spec requires a blockIndicationIndicator
149
+ // http://www.yaml.org/spec/1.2/spec.html#id2793979
150
+ $ blockIndentationIndicator = (' ' === substr ($ value ->getValue (), 0 , 1 )) ? (string ) $ this ->indentation : '' ;
151
+ $ output .= sprintf (' |%s ' , $ blockIndentationIndicator );
152
+
153
+ foreach (explode ("\n" , $ value ->getValue ()) as $ row ) {
154
+ $ output .= sprintf ("\n%s%s%s " , $ prefix , str_repeat (' ' , $ this ->indentation ), $ row );
155
+ }
156
+
157
+ return $ output ;
158
+ }
159
+
160
+ if ($ inline - 1 <= 0 || null === $ value ->getValue () || \is_scalar ($ value ->getValue ())) {
161
+ return $ output .' ' .$ this ->dump ($ value ->getValue (), $ inline - 1 , 0 , $ flags )."\n" ;
162
+ }
163
+
164
+ return $ output ."\n" .$ this ->dump ($ value ->getValue (), $ inline - 1 , $ indent , $ flags );
165
+ }
140
166
}
0 commit comments