File tree Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Expand file tree Collapse file tree 2 files changed +19
-7
lines changed Original file line number Diff line number Diff line change 1212
1313class ObjectDriver implements Driver
1414{
15+ private const DEFAULT_YAML_CONFIG = [
16+ 'yaml_inline ' => 2 ,
17+ 'yaml_indent ' => 4 ,
18+ 'yaml_flags ' => Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK ,
19+ ];
20+
21+ /**
22+ * @param array{
23+ * yaml_inline: int,
24+ * yaml_indent: int,
25+ * yaml_flags: int
26+ * } $yamlConfig
27+ */
1528 public function __construct (
16- protected int $ yamlInline = 2 ,
29+ protected array $ yamlConfig = [] ,
1730 ) {
31+ $ this ->yamlConfig = array_merge (self ::DEFAULT_YAML_CONFIG , $ yamlConfig );
1832 }
1933
2034 public function serialize ($ data ): string
@@ -31,11 +45,7 @@ public function serialize($data): string
3145 $ serializer = new Serializer ($ normalizers , $ encoders );
3246
3347 return $ this ->dedent (
34- $ serializer ->serialize ($ data , 'yaml ' , [
35- 'yaml_inline ' => $ this ->yamlInline ,
36- 'yaml_indent ' => 4 ,
37- 'yaml_flags ' => Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK ,
38- ])
48+ $ serializer ->serialize ($ data , 'yaml ' , $ this ->yamlConfig )
3949 );
4050 }
4151
Original file line number Diff line number Diff line change @@ -92,7 +92,9 @@ public function it_can_serialize_a_class_instance()
9292 #[Test]
9393 public function it_can_serialize_with_custom_parameters ()
9494 {
95- $ driver = new ObjectDriver (3 );
95+ $ driver = new ObjectDriver ([
96+ 'yaml_inline ' => 3 ,
97+ ]);
9698
9799 $ nestedObject = (object ) [
98100 'foo ' => (object ) [
You can’t perform that action at this time.
0 commit comments