Skip to content

Commit 31c17dd

Browse files
committed
feature #17746 [Yaml] deprecate the Dumper::setIndentation() method (xabbuh)
This PR was merged into the 3.1-dev branch. Discussion ---------- [Yaml] deprecate the Dumper::setIndentation() method | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- de4b207 deprecate the Dumper::setIndentation() method
2 parents 33c797e + de4b207 commit 31c17dd

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

UPGRADE-3.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ Serializer
3333
Yaml
3434
----
3535

36+
* The `Dumper::setIndentation()` method is deprecated and will be removed in
37+
Symfony 4.0. Pass the indentation level to the constructor instead.
38+
3639
* Deprecated support for passing `true`/`false` as the second argument to the
3740
`parse()` method to trigger exceptions when an invalid type was passed.
3841

UPGRADE-4.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Serializer
2424
Yaml
2525
----
2626

27+
* The `Dumper::setIndentation()` method was removed. Pass the indentation
28+
level to the constructor instead.
29+
2730
* Removed support for passing `true`/`false` as the second argument to the
2831
`parse()` method to trigger exceptions when an invalid type was passed.
2932

src/Symfony/Component/Yaml/Dumper.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@ class Dumper
2323
*
2424
* @var int
2525
*/
26-
protected $indentation = 4;
26+
protected $indentation;
27+
28+
/**
29+
* @param int $indentation
30+
*/
31+
public function __construct($indentation = 4)
32+
{
33+
$this->indentation = $indentation;
34+
}
2735

2836
/**
2937
* Sets the indentation.
@@ -32,6 +40,8 @@ class Dumper
3240
*/
3341
public function setIndentation($num)
3442
{
43+
@trigger_error('The '.__METHOD__.' method is deprecated since version 3.1 and will be removed in 4.0. Pass the indentation to the constructor instead.', E_USER_DEPRECATED);
44+
3545
$this->indentation = (int) $num;
3646
}
3747

src/Symfony/Component/Yaml/Tests/DumperTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ protected function tearDown()
5151
$this->array = null;
5252
}
5353

54+
public function testIndentationInConstructor()
55+
{
56+
$dumper = new Dumper(7);
57+
$expected = <<<'EOF'
58+
'': bar
59+
foo: '#bar'
60+
'foo''bar': { }
61+
bar:
62+
- 1
63+
- foo
64+
foobar:
65+
foo: bar
66+
bar:
67+
- 1
68+
- foo
69+
foobar:
70+
foo: bar
71+
bar:
72+
- 1
73+
- foo
74+
75+
EOF;
76+
$this->assertEquals($expected, $dumper->dump($this->array, 4, 0));
77+
}
78+
79+
/**
80+
* @group legacy
81+
*/
5482
public function testSetIndentation()
5583
{
5684
$this->dumper->setIndentation(7);

src/Symfony/Component/Yaml/Yaml.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvali
9696
$flags = (int) $flags;
9797
}
9898

99-
$yaml = new Dumper();
100-
$yaml->setIndentation($indent);
99+
$yaml = new Dumper($indent);
101100

102101
return $yaml->dump($array, $inline, 0, $exceptionOnInvalidType, $flags);
103102
}

0 commit comments

Comments
 (0)