Skip to content

Commit

Permalink
add option to generate phpdoc properties (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
dakorpar authored Mar 1, 2019
1 parent 0b63912 commit a4fc1c7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/Pdo/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$config = new \DodoIt\EntityGenerator\Generator\Config([
'path' => __DIR__ . '/Entities',
'extends' => \Examples\Pdo\Entities\Entity::class,
'namespace' => 'Examples\Pdo\Entities'
'namespace' => 'Examples\Pdo\Entities',
]);

$pdo = new \PDO('mysql:dbname=example;host=127.0.0.1', 'root', '');
Expand Down
10 changes: 10 additions & 0 deletions src/Generator/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public function __construct(?array $config = null)
*/
public $propertyVisibility = 'protected';

/**
* @var bool
*/
public $generatePhpDocProperties = false;

/**
* @var string
*/
public $phpDocProperty = '@property';

/**
* @param string $name
* @return void
Expand Down
20 changes: 15 additions & 5 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,21 @@ protected function validateColumnName(string $table, Column $column): void
protected function generateColumn(ClassType $entity, Column $column): void
{
$type = $this->getColumnType($column);
$entity->addProperty($column->getField())
->setVisibility($this->config->propertyVisibility)
->addComment('')
->addComment('@var ' . $type)
->addComment('');

if($this->config->generateProperties) {
$entity->addProperty($column->getField())
->setVisibility($this->config->propertyVisibility)
->addComment('@var ' . $type);
}

if ($this->config->generateColumnConstant) {
$columnConstant = $this->config->prefix . Strings::upper(Inflector::tableize($column->getField()));
$entity->addConstant($columnConstant, $column->getField());
}

if($this->config->generatePhpDocProperties) {
$entity->addComment($this->config->phpDocProperty . ' ' . $type . ' $' .$column->getField());
}

if ($this->config->generateColumnConstant) {
$columnConstant = $this->config->prefix . Strings::upper(Inflector::tableize($column->getField()));
Expand Down

0 comments on commit a4fc1c7

Please sign in to comment.