File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Filter options
src/Symfony/Component/Serializer/Encoder Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
Original file line number Diff line number Diff line change @@ -28,7 +28,17 @@ class YamlEncoder implements EncoderInterface, DecoderInterface
28
28
29
29
public const PRESERVE_EMPTY_OBJECTS = 'preserve_empty_objects ' ;
30
30
31
+ /**
32
+ * Override the amount of spaces to use for indentation of nested nodes.
33
+ *
34
+ * This option only works in the constructor, not in calls to `encode`.
35
+ */
36
+ public const YAML_INDENTATION = 'yaml_indentation ' ;
37
+
31
38
public const YAML_INLINE = 'yaml_inline ' ;
39
+ /**
40
+ * Initial indentation for root element.
41
+ */
32
42
public const YAML_INDENT = 'yaml_indent ' ;
33
43
public const YAML_FLAGS = 'yaml_flags ' ;
34
44
@@ -46,8 +56,12 @@ public function __construct(Dumper $dumper = null, Parser $parser = null, array
46
56
throw new RuntimeException ('The YamlEncoder class requires the "Yaml" component. Install "symfony/yaml" to use it. ' );
47
57
}
48
58
49
- $ this ->dumper = $ dumper ?? new Dumper ();
59
+ if (!$ dumper ) {
60
+ $ dumper = \array_key_exists (self ::YAML_INDENTATION , $ defaultContext ) ? new Dumper ($ defaultContext [self ::YAML_INDENTATION ]) : new Dumper ();
61
+ }
62
+ $ this ->dumper = $ dumper ;
50
63
$ this ->parser = $ parser ?? new Parser ();
64
+ unset($ defaultContext [self ::YAML_INDENTATION ]);
51
65
$ this ->defaultContext = array_merge ($ this ->defaultContext , $ defaultContext );
52
66
}
53
67
You can’t perform that action at this time.
0 commit comments