Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use table comments for documentor's variable description #131

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Generator extends \yii\gii\Generator
public $baseClass = 'yii\db\ActiveRecord';
public $generateRelations = self::RELATIONS_ALL;
public $generateLabelsFromComments = false;
public $generateDocsFromComments = false;
public $useTablePrefix = false;
public $useSchemaName = true;
public $generateQuery = false;
Expand Down Expand Up @@ -80,7 +81,7 @@ public function rules()
[['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]],
[['queryBaseClass'], 'validateClass', 'params' => ['extends' => ActiveQuery::className()]],
[['generateRelations'], 'in', 'range' => [self::RELATIONS_NONE, self::RELATIONS_ALL, self::RELATIONS_ALL_INVERSE]],
[['generateLabelsFromComments', 'useTablePrefix', 'useSchemaName', 'generateQuery'], 'boolean'],
[['generateLabelsFromComments', 'generateDocsFromComments', 'useTablePrefix', 'useSchemaName', 'generateQuery'], 'boolean'],
[['enableI18N'], 'boolean'],
[['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
]);
Expand All @@ -99,6 +100,7 @@ public function attributeLabels()
'baseClass' => 'Base Class',
'generateRelations' => 'Generate Relations',
'generateLabelsFromComments' => 'Generate Labels from DB Comments',
'generateDocsFromComments' => 'Generate model\'s propeties descriptions from DB Comments',
'generateQuery' => 'Generate ActiveQuery',
'queryNs' => 'ActiveQuery Namespace',
'queryClass' => 'ActiveQuery Class',
Expand Down Expand Up @@ -131,6 +133,8 @@ class.',
you may want to uncheck this option to accelerate the code generation process.',
'generateLabelsFromComments' => 'This indicates whether the generator should generate attribute labels
by using the comments of the corresponding DB columns.',
'generateDocsFromComments' => 'This indicates whether the generator should generate description
for each model\'s @propery by using the comments of the corresponding DB columns.',
'useTablePrefix' => 'This indicates whether the table name returned by the generated ActiveRecord class
should consider the <code>tablePrefix</code> setting of the DB connection. For example, if the
table name is <code>tbl_post</code> and <code>tablePrefix=tbl_</code>, the ActiveRecord class
Expand Down Expand Up @@ -177,7 +181,7 @@ public function requiredTemplates()
*/
public function stickyAttributes()
{
return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments', 'queryNs', 'queryBaseClass']);
return array_merge(parent::stickyAttributes(), ['ns', 'db', 'baseClass', 'generateRelations', 'generateLabelsFromComments', 'generateDocsFromComments', 'queryNs', 'queryBaseClass']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion generators/model/default/model.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* This is the model class for table "<?= $generator->generateTableName($tableName) ?>".
*
<?php foreach ($tableSchema->columns as $column): ?>
* @property <?= "{$column->phpType} \${$column->name}\n" ?>
* @property <?= "{$column->phpType} \${$column->name}" . ($generator->generateDocsFromComments ? " {$column->comment}" : '') . "\n" ?>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strtr($column->comment, ["\n" => "\n * "])

<?php endforeach; ?>
<?php if (!empty($relations)): ?>
*
Expand Down
1 change: 1 addition & 0 deletions generators/model/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Generator::RELATIONS_ALL_INVERSE => 'All relations with inverse',
]);
echo $form->field($generator, 'generateLabelsFromComments')->checkbox();
echo $form->field($generator, 'generateDocsFromComments')->checkbox();
echo $form->field($generator, 'generateQuery')->checkbox();
echo $form->field($generator, 'queryNs');
echo $form->field($generator, 'queryClass');
Expand Down