Skip to content
/ yaml Public
Closed
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
35 changes: 28 additions & 7 deletions Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,24 @@ private function doDump(mixed $input, int $inline = 0, int $indent = 0, int $fla
if (Yaml::DUMP_OBJECT_AS_MAP & $flags && ($value instanceof \ArrayObject || $value instanceof \stdClass)) {
$dumpObjectAsInlineMap = !(array) $value;
}

$willBeInlined = $inline - 1 <= 0 || !\is_array($value) && $dumpObjectAsInlineMap || !$value;
$isSequenceItem = !$dumpAsMap;
$willBeInlined =
$inline - 1 <= 0
|| (!\is_array($value) && $dumpObjectAsInlineMap)
|| !$value
|| (
$isSequenceItem
&& \is_array($value)
&& Inline::isHash($value)
&& $this->isSimpleInlineMap($value)
);

$output .= \sprintf('%s%s%s%s',
$prefix,
$dumpAsMap ? Inline::dump($key, $flags).':' : '-',
$willBeInlined || ($compactNestedMapping && \is_array($value) && Inline::isHash($value)) ? ' ' : "\n",
$compactNestedMapping && \is_array($value) && Inline::isHash($value) ? substr($this->doDump($value, $inline - 1, $indent + 2, $flags, $nestingLevel + 1), $indent + 2) : $this->doDump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags, $nestingLevel + 1)
).($willBeInlined ? "\n" : '');
$prefix,
$dumpAsMap ? Inline::dump($key, $flags).':' : '-',
$willBeInlined || ($compactNestedMapping && \is_array($value) && Inline::isHash($value)) ? ' ' : "\n",
$compactNestedMapping && \is_array($value) && Inline::isHash($value) ? substr($this->doDump($value, $inline - 1, $indent + 2, $flags, $nestingLevel + 1), $indent + 2) : $this->doDump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $flags, $nestingLevel + 1)
).($willBeInlined ? "\n" : '');
}
}

Expand Down Expand Up @@ -181,4 +190,16 @@ private function getBlockIndentationIndicator(string $value): string

return '';
}

private function isSimpleInlineMap(array $value): bool
{
foreach ($value as $v) {
if (\is_array($v) || $v instanceof TaggedValue) {
return false;
}
}

return true;
}

}