Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit de4b207

Browse filesBrowse files
committed
deprecate the Dumper::setIndentation() method
1 parent 33c797e commit de4b207
Copy full SHA for de4b207

File tree

5 files changed

+46
-3
lines changed
Filter options

5 files changed

+46
-3
lines changed

‎UPGRADE-3.1.md

Copy file name to clipboardExpand all lines: UPGRADE-3.1.md
+3Lines 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

Copy file name to clipboardExpand all lines: UPGRADE-4.0.md
+3Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Dumper.php
+11-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Tests/DumperTest.php
+28Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Yaml.php
+1-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.