diff --git a/src/Console/Commands/DumpCommand.php b/src/Console/Commands/DumpCommand.php index 4afe900..41e035d 100644 --- a/src/Console/Commands/DumpCommand.php +++ b/src/Console/Commands/DumpCommand.php @@ -124,6 +124,9 @@ protected function getFileTemplate($content, $locale, $group, $date) $content = $this->convertToOrderedNestedArray($content); $array_text = var_export($content, true); + $array_text = $this->getArrayText($content); + + $data = <<getMaxKeyLength($arr); + + foreach($arr as $key => $value) { + + $filler = str_repeat(' ', $max_key_length - strlen($key)); + + $result .= $ident.str_repeat(' ', $ident_size)."'{$key}'{$filler} => "; + + if(is_array($value)) { + $result .= $this->getArrayText($value, $ident_size, $level+1); + } else { + $result .= var_export($value, true); + } + $result .= ",\n"; + } + $result .= $ident.")"; + + //if($level > 0) $result .= ",\n"; + + return $result; + } + /** * @param $content * @return mixed @@ -162,4 +192,18 @@ private function convertToOrderedNestedArray($content) return $content; } + /** + * @param $arr + * @return int + */ + private function getMaxKeyLength($arr) + { + $keys = array_keys($arr); + usort($keys, function ($a, $b) { + return strlen($a) < strlen($b); + }); + $max_key_length = strlen(array_shift($keys)); + return $max_key_length; + } + }