don't dump a scalar tag value on its own line
This commit is contained in:
parent
6f332ce0e0
commit
a549069a49
@ -115,15 +115,11 @@ class Dumper
|
|||||||
if ($value instanceof TaggedValue) {
|
if ($value instanceof TaggedValue) {
|
||||||
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
|
$output .= sprintf('%s%s !%s', $prefix, $dumpAsMap ? Inline::dump($key, $flags).':' : '-', $value->getTag());
|
||||||
|
|
||||||
if ($inline - 1 <= 0) {
|
if ($inline - 1 <= 0 || null === $value->getValue() || is_scalar($value->getValue())) {
|
||||||
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
|
$output .= ' '.$this->dump($value->getValue(), $inline - 1, 0, $flags)."\n";
|
||||||
} else {
|
} else {
|
||||||
$output .= "\n";
|
$output .= "\n";
|
||||||
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
|
$output .= $this->dump($value->getValue(), $inline - 1, $dumpAsMap ? $indent + $this->indentation : $indent + 2, $flags);
|
||||||
|
|
||||||
if (is_scalar($value->getValue())) {
|
|
||||||
$output .= "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -532,10 +532,21 @@ YAML;
|
|||||||
'user2' => new TaggedValue('user', 'john'),
|
'user2' => new TaggedValue('user', 'john'),
|
||||||
];
|
];
|
||||||
$expected = <<<YAML
|
$expected = <<<YAML
|
||||||
user1: !user
|
user1: !user jane
|
||||||
jane
|
user2: !user john
|
||||||
user2: !user
|
|
||||||
john
|
YAML;
|
||||||
|
|
||||||
|
$this->assertSame($expected, $this->dumper->dump($data, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDumpingNotInlinedNullTaggedValue()
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'foo' => new TaggedValue('bar', null),
|
||||||
|
];
|
||||||
|
$expected = <<<YAML
|
||||||
|
foo: !bar null
|
||||||
|
|
||||||
YAML;
|
YAML;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user