@@ -33,6 +33,7 @@ class Inline
33
33
private static $ objectSupport = false ;
34
34
private static $ objectForMap = false ;
35
35
private static $ constantSupport = false ;
36
+ private static $ nullAsTilde = false ;
36
37
37
38
/**
38
39
* @param int $flags
@@ -45,6 +46,7 @@ public static function initialize($flags, $parsedLineNumber = null, $parsedFilen
45
46
self ::$ objectSupport = (bool ) (Yaml::PARSE_OBJECT & $ flags );
46
47
self ::$ objectForMap = (bool ) (Yaml::PARSE_OBJECT_FOR_MAP & $ flags );
47
48
self ::$ constantSupport = (bool ) (Yaml::PARSE_CONSTANT & $ flags );
49
+ self ::$ nullAsTilde = (bool ) (Yaml::DUMP_NULL_AS_TILDE & $ flags );
48
50
self ::$ parsedFilename = $ parsedFilename ;
49
51
50
52
if (null !== $ parsedLineNumber ) {
@@ -129,7 +131,7 @@ public static function dump($value, int $flags = 0): string
129
131
throw new DumpException (sprintf ('Unable to dump PHP resources in a YAML file ("%s"). ' , get_resource_type ($ value )));
130
132
}
131
133
132
- return ' null ' ;
134
+ return self :: dumpNull ( $ flags ) ;
133
135
case $ value instanceof \DateTimeInterface:
134
136
return $ value ->format ('c ' );
135
137
case \is_object ($ value ):
@@ -155,11 +157,11 @@ public static function dump($value, int $flags = 0): string
155
157
throw new DumpException ('Object support when dumping a YAML file has been disabled. ' );
156
158
}
157
159
158
- return ' null ' ;
160
+ return self :: dumpNull ( $ flags ) ;
159
161
case \is_array ($ value ):
160
162
return self ::dumpArray ($ value , $ flags );
161
163
case null === $ value :
162
- return ' null ' ;
164
+ return self :: dumpNull ( $ flags ) ;
163
165
case true === $ value :
164
166
return 'true ' ;
165
167
case false === $ value :
@@ -256,6 +258,15 @@ private static function dumpArray(array $value, int $flags): string
256
258
return sprintf ('{ %s } ' , implode (', ' , $ output ));
257
259
}
258
260
261
+ private static function dumpNull (int $ flags ): string
262
+ {
263
+ if (Yaml::DUMP_NULL_AS_TILDE & $ flags ) {
264
+ return '~ ' ;
265
+ }
266
+
267
+ return 'null ' ;
268
+ }
269
+
259
270
/**
260
271
* Parses a YAML scalar.
261
272
*
0 commit comments