Skip to content

Commit

Permalink
Fill in class and property documentation based on Database Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarnauts committed Feb 2, 2017
1 parent 397c3fd commit 5ff79ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,11 @@ private function generateProperties($table)
} else {
$type = $columnPhpType;
}
$properties[$column->name] = $type;
$properties[$column->name] = [
'type' => $type,
'name' => $column->name,
'comment' => $column->comment,
];
}

return $properties;
Expand Down
8 changes: 6 additions & 2 deletions generators/model/default/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
use Yii;

/**
<?php if (property_exists($tableSchema, 'comment') && $tableSchema->comment): ?>
* <?= strtr($tableSchema->comment, ["\n" => "\n * "]) . "\n" ?>
<?php else: ?>
* This is the model class for table "<?= $generator->generateTableName($tableName) ?>".
<?php endif; ?>
*
<?php foreach ($properties as $property => $type): ?>
* @property <?= "{$type} \${$property}\n" ?>
<?php foreach ($properties as $property => $data): ?>
* @property <?= "{$data['type']} \${$property}\n" . ($data['comment'] ? ' ' . strtr($data['comment'], ["\n" => ' ']) : '') . "\n" ?>
<?php endforeach; ?>
<?php if (!empty($relations)): ?>
*
Expand Down

0 comments on commit 5ff79ae

Please sign in to comment.