Skip to content

[Yaml] deprecate the Dumper::setIndentation() method #17746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADE-3.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Serializer
Yaml
----

* The `Dumper::setIndentation()` method is deprecated and will be removed in
Symfony 4.0. Pass the indentation level to the constructor instead.

* Deprecated support for passing `true`/`false` as the second argument to the
`parse()` method to trigger exceptions when an invalid type was passed.

Expand Down
3 changes: 3 additions & 0 deletions UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Serializer
Yaml
----

* The `Dumper::setIndentation()` method was removed. Pass the indentation
level to the constructor instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically the method was not removed yet.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, you are right (I forgot to reply to your comment on your PR last week, sorry for that). But I think we should keep the upgrade files in sync (we did the same during the development of the 2.x versions with the UPGRADE-3.0.md file). Otherwise we would need to spend a lot of time on syncing the files when the development of 4.0 starts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only worried that we document that something was removed in UPGRADE-4.0.md file, but then we forget to remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, forgetting to remove deprecated APIs would be a failure in our process anyway

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

I documented the change mentioned by xabbuh here: #17753.


* Removed support for passing `true`/`false` as the second argument to the
`parse()` method to trigger exceptions when an invalid type was passed.

Expand Down
12 changes: 11 additions & 1 deletion src/Symfony/Component/Yaml/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@ class Dumper
*
* @var int
*/
protected $indentation = 4;
protected $indentation;

/**
* @param int $indentation
*/
public function __construct($indentation = 4)
{
$this->indentation = $indentation;
}

/**
* Sets the indentation.
Expand All @@ -32,6 +40,8 @@ class Dumper
*/
public function setIndentation($num)
{
@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);

$this->indentation = (int) $num;
}

Expand Down
28 changes: 28 additions & 0 deletions src/Symfony/Component/Yaml/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,34 @@ protected function tearDown()
$this->array = null;
}

public function testIndentationInConstructor()
{
$dumper = new Dumper(7);
$expected = <<<'EOF'
'': bar
foo: '#bar'
'foo''bar': { }
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo
foobar:
foo: bar
bar:
- 1
- foo

EOF;
$this->assertEquals($expected, $dumper->dump($this->array, 4, 0));
}

/**
* @group legacy
*/
public function testSetIndentation()
{
$this->dumper->setIndentation(7);
Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/Yaml/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public static function dump($array, $inline = 2, $indent = 4, $exceptionOnInvali
$flags = (int) $flags;
}

$yaml = new Dumper();
$yaml->setIndentation($indent);
$yaml = new Dumper($indent);

return $yaml->dump($array, $inline, 0, $exceptionOnInvalidType, $flags);
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy