Skip to content

Commit 23e12b5

Browse files
committed
implemented uml configuration
1 parent e3a3032 commit 23e12b5

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ uay_entities:
151151
- [x] Generate app repositories
152152
- [x] Generate app enums
153153
- [x] Configure generated names
154-
- [ ] Better UML configuration
154+
- [x] Better UML configuration
155155
- [ ] Recursive namespace configurations
156156
- [ ] Config validation
157157
- [ ] Generate base repositories

src/DataModelGenerator/DataModelGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public function read(): void
263263

264264
protected function generatePlantTextUml(): void
265265
{
266-
$plantTextGenerator = new PlantTextGenerator($this->entities);
266+
$plantTextGenerator = new PlantTextGenerator($this->inputModel, $this->entities);
267267

268268
$plantTextGenerator->write($this->pathEntities . DIRECTORY_SEPARATOR . static::FILE_PLANTTEXT);
269269

src/DataModelGenerator/InputModel.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ class InputModel
1313

1414
protected const CONFIG_KEY_NAMESPACE = 'namespace';
1515
protected const CONFIG_KEY_CLASS_POSTFIX = 'classPostfix';
16+
protected const CONFIG_KEY_UML = 'uml';
1617

1718
/**
1819
* @var array
1920
*/
20-
protected $configuration = [
21+
protected static $defaultConfiguration = [
2122
self::CONFIG_KEY_NAMESPACE => [
2223
'app' => 'App',
2324
'base' => 'Generated',
@@ -29,8 +30,16 @@ class InputModel
2930
'entity' => 'Generated',
3031
'repository' => 'Repository',
3132
],
33+
self::CONFIG_KEY_UML => [
34+
'valid' => false,
35+
],
3236
];
3337

38+
/**
39+
* @var array
40+
*/
41+
protected $configuration;
42+
3443
/**
3544
* @var array
3645
*/
@@ -48,7 +57,7 @@ public function __construct(array $config)
4857
$this->{$property} = ArrayUtil::getValueByPath($config, $requiredPath);
4958
}
5059

51-
$this->configuration = ArrayUtil::fillRecursive($this->configuration, $config);
60+
$this->configuration = ArrayUtil::fillRecursive(static::$defaultConfiguration, $config);
5261
}
5362

5463
protected function getConfigStringOrThrow(string $group, string $name): string
@@ -78,6 +87,15 @@ public function getClassPostfix(string $name): string
7887
return $this->getConfigStringOrThrow(static::CONFIG_KEY_CLASS_POSTFIX, $name);
7988
}
8089

90+
/**
91+
* @param string $name
92+
* @return string
93+
*/
94+
public function getUML(string $name): string
95+
{
96+
return $this->getConfigStringOrThrow(static::CONFIG_KEY_UML, $name);
97+
}
98+
8199
public function getEntitiesData(): array
82100
{
83101
return $this->entitiesData;

src/DataModelGenerator/PlantTextGenerator.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
class PlantTextGenerator
99
{
10+
/**
11+
* @var InputModel
12+
*/
13+
protected $inputModel;
14+
1015
/**
1116
* @var string
1217
*/
@@ -16,13 +21,15 @@ protected function parseEntity(Entity $entity): array
1621
{
1722
$result = [];
1823

24+
$shouldProduceValidUML = $this->inputModel->getUML('valid');
25+
1926
$type = $entity->getType() === Entity::TYPE_ENUM ? 'enum' : 'class';
2027

2128
$result[] = "{$type} {$entity->getName()} {";
2229

2330
$plantTypeField = 'field';
2431
$plantTypeMethod = 'method';
25-
$plantTypeExternal = $plantTypeMethod;
32+
$plantTypeExternal = $shouldProduceValidUML ? $plantTypeField : $plantTypeMethod;
2633

2734
if ($entity->getType() === Entity::TYPE_ENTITY) {
2835
$result[] = " {{$plantTypeField}}+integer id";
@@ -116,10 +123,13 @@ protected function generatePlantRelation(array $members): string
116123
}
117124

118125
/**
126+
* @param InputModel $inputModel
119127
* @param Entity[] $entities
120128
*/
121-
public function __construct(array $entities)
129+
public function __construct(InputModel $inputModel, array $entities)
122130
{
131+
$this->inputModel = $inputModel;
132+
123133
$plantText = [];
124134

125135
$plantText[] = '@startuml';

0 commit comments

Comments
 (0)