Skip to content

Commit

Permalink
Fix dotted assignment logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaecyra committed May 17, 2012
1 parent 3d9a4ba commit dba947f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
9 changes: 8 additions & 1 deletion library/core/class.configuration.php
Expand Up @@ -186,9 +186,16 @@ public static function Format($Data, $Options = array()) {
$VariableName = GetValue('VariableName', $Options);
$WrapPHP = GetValue('WrapPHP', $Options, TRUE);
$ByLine = GetValue('ByLine', $Options, FALSE);
$Headings = GetValue('Headings', $Options, TRUE);
$FormatStyle = GetValue('FormatStyle', $Options);
$Formatter = "Format{$FormatStyle}Assignment";

if ($FormatStyle == 'Dotted') {
$Headings = FALSE;
$WrapPHP = FALSE;
$ByLine = FALSE;
}

$FirstLine = '';
$Lines = array();
if ($WrapPHP)
Expand All @@ -210,7 +217,7 @@ public static function Format($Data, $Options = array()) {
if ($FormatStyle == 'Array')
$Prefix = '$'.$VariableName."[".var_export($Key, TRUE)."]";
if ($FormatStyle == 'Dotted')
$Prefix = var_export($Key, TRUE);
$Prefix = '$'.$VariableName."['".trim(var_export($Key, TRUE), "'");

$Formatter($Lines, $Prefix, $Value);
}
Expand Down
20 changes: 12 additions & 8 deletions library/core/functions.general.php
Expand Up @@ -1112,21 +1112,25 @@ function FormatDottedAssignment(&$Array, $Prefix, $Value) {
$IsAssociativeArray = array_key_exists(0, $Value) === FALSE || is_array($Value[0]) === TRUE ? TRUE : FALSE;
if ($IsAssociativeArray === TRUE) {
foreach ($Value as $k => $v) {
FormatArrayAssignment($Array, "{$Prefix}.{$k}", $v);
FormatDottedAssignment($Array, "{$Prefix}.{$k}", $v);
}
} else {
// If $Value is not an associative array, just write it like a simple array definition.
$FormattedValue = array_map(array('Gdn_Format', 'ArrayValueForPhp'), $Value);
$Prefix .= "']";
$Array[] = $Prefix .= " = array('".implode("', '", $FormattedValue)."');";
}
} elseif (is_int($Value)) {
$Array[] = $Prefix .= ' = '.$Value.';';
} elseif (is_bool($Value)) {
$Array[] = $Prefix .= ' = '.($Value ? 'TRUE' : 'FALSE').';';
} elseif (in_array($Value, array('TRUE', 'FALSE'))) {
$Array[] = $Prefix .= ' = '.($Value == 'TRUE' ? 'TRUE' : 'FALSE').';';
} else {
$Array[] = $Prefix .= ' = '.var_export($Value, TRUE).';';
$Prefix .= "']";
if (is_int($Value)) {
$Array[] = $Prefix .= ' = '.$Value;
} elseif (is_bool($Value)) {
$Array[] = $Prefix .= ' = '.($Value ? 'TRUE' : 'FALSE').';';
} elseif (in_array($Value, array('TRUE', 'FALSE'))) {
$Array[] = $Prefix .= ' = '.($Value == 'TRUE' ? 'TRUE' : 'FALSE').';';
} else {
$Array[] = $Prefix .= ' = '.var_export($Value, TRUE).';';
}
}
}
}
Expand Down

0 comments on commit dba947f

Please sign in to comment.