From 4061f837c0df317f97c55329334cbf61506573a5 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Sat, 30 May 2026 19:01:41 -0400 Subject: [PATCH] wip --- src/Configurator.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/Configurator.php b/src/Configurator.php index 3e5307c..44b33aa 100644 --- a/src/Configurator.php +++ b/src/Configurator.php @@ -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); @@ -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.']'; + } }