Skip to content
Merged
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: 34 additions & 1 deletion src/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ protected function buildEndingGroup($isArrayValue, $indentation, $matchParent =
*/
protected function varExport($value)
{
$value = VarExporter::export($value);
$value = $this->exportMultiline($value);

// Remove numeric keys.
$value = preg_replace("/(\s*)[0-9]+\s=>\s(.*)/", '$1$2', $value);
Expand All @@ -434,4 +434,37 @@ protected function varExport($value)

return $value;
}

/**
* Export var as a multiline string.
*
* VarExporter collapses small scalar arrays onto a single line, so we
* handle the array nesting ourselves to keep config files multiline,
* delegating only scalar leaves to VarExporter.
*
* @param mixed $value
* @param string $indent
* @return string
*/
protected function exportMultiline($value, $indent = '')
{
if (! is_array($value)) {
return VarExporter::export($value);
}

if ($value === []) {
return '[]';
}

$subIndent = $indent.' ';
$isList = array_is_list($value);

$lines = collect($value)->map(function ($value, $key) use ($isList, $subIndent) {
$prefix = $isList ? '' : VarExporter::export($key).' => ';

return $subIndent.$prefix.$this->exportMultiline($value, $subIndent);
});

return "[\n".$lines->implode(",\n").",\n".$indent.']';
}
}
Loading