Skip to content

Commit

Permalink
Dump is now performed in nested array instead of dotted keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
hpolthof committed Sep 15, 2015
1 parent 092da06 commit 7bab972
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Console/Commands/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ protected function write($dump)
}
}

private function assignArrayByPath(&$arr, $path, $value) {
$keys = explode('.', $path);

while ($key = array_shift($keys)) {
$arr = &$arr[$key];
if(is_array($arr)) ksort($arr);
}

$arr = $value;
}

/**
* @param $content
* @param $locale
Expand All @@ -110,6 +121,8 @@ protected function write($dump)
*/
protected function getFileTemplate($content, $locale, $group, $date)
{
$content = $this->convertToOrderedNestedArray($content);

$array_text = var_export($content, true);
$data = <<<EOF
<?php
Expand All @@ -135,4 +148,18 @@ protected function fixNulledValues($content)
return $content;
}

/**
* @param $content
* @return array
*/
private function convertToOrderedNestedArray($content)
{
$new_content = array();
foreach ($content as $key => $value) {
$this->assignArrayByPath($new_content, $key, $value);
}
$content = $new_content;
return $content;
}

}

0 comments on commit 7bab972

Please sign in to comment.