Skip to content
Snippets Groups Projects
Commit 8b6c7b82 authored by Demian Katz's avatar Demian Katz
Browse files

Make config writer smarter about arrays.

parent 15c71001
No related merge requests found
...@@ -120,6 +120,13 @@ class Writer ...@@ -120,6 +120,13 @@ class Writer
} else if (strstr($content, '=')) { } else if (strstr($content, '=')) {
$contentParts = explode('=', $content, 2); $contentParts = explode('=', $content, 2);
$key = trim($contentParts[0]); $key = trim($contentParts[0]);
// If the key we are trying to set is already present as an array,
// we need to clear out the multiple existing values before writing
// in a new one:
if ($key == $setting . '[]') {
continue;
}
// Standard case for match on section + key:
if ($currentSection == $section && $key == $setting) { if ($currentSection == $section && $key == $setting) {
$settingSet = true; $settingSet = true;
if ($value === null) { if ($value === null) {
...@@ -231,6 +238,18 @@ class Writer ...@@ -231,6 +238,18 @@ class Writer
$tabStr .= ' '; $tabStr .= ' ';
} }
// Special case: if value is an array, we need to adjust the key
// accordingly:
if (is_array($value)) {
$retVal = '';
foreach ($value as $current) {
$retVal .= $key . '[]' . $tabStr . " = "
. $this->buildContentValue($current);
}
return $retVal;
}
// Standard case: value is not an array:
return $key . $tabStr . " = " . $this->buildContentValue($value); return $key . $tabStr . " = " . $this->buildContentValue($value);
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment