Skip to content

Commit

Permalink
krlove#1 allow associate array property generation ; add version for …
Browse files Browse the repository at this point in the history
…composer.json
  • Loading branch information
wxs77577 committed Feb 28, 2017
1 parent c1f0cb6 commit 72962ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "krlove/code-generator",
"description": "Code Generator",
"version": "1.0.1",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
13 changes: 10 additions & 3 deletions src/Model/Traits/ValueTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ protected function renderTyped($value)
break;
case 'array':
$parts = [];
foreach ($value as $item) {
$parts[] = $this->renderTyped($item);
$isAssociate = false;
foreach ($value as $key => $item) {
$isAssociate = !is_integer($key);
if ($isAssociate) {
$parts[] = PHP_EOL . "\t\t'" . $key . "' => " .$this->renderTyped($item);

} else {
$parts[] = $this->renderTyped($item);
}
}
$value = '[' . implode(', ', $parts) . ']';
$value = '[' . implode(', ', $parts) . ($isAssociate ? "\n\t" : "") . ']';

break;
default:
Expand Down

0 comments on commit 72962ff

Please sign in to comment.