diff --git a/src/Analyser/Database/DatabaseAnalyser.php b/src/Analyser/Database/DatabaseAnalyser.php index e44a01a..e9c9ce2 100644 --- a/src/Analyser/Database/DatabaseAnalyser.php +++ b/src/Analyser/Database/DatabaseAnalyser.php @@ -70,11 +70,11 @@ protected function analyseColumns(Table $table): void $column->setNullable($col['nullable']); $column->setType(Helpers::columnType($col['nativetype'])); $column->setDefault($col['default']); - $column->setOnUpdate(Strings::contains(isset($col['vendor']['extra']) ? $col['vendor']['extra'] : $col['vendor']['Extra'], 'on update')); + $column->setOnUpdate(Strings::contains($col['vendor']['extra'] ?? $col['vendor']['Extra'], 'on update')); // Analyse ENUM if ($col['nativetype'] === ColumnTypes::NATIVE_TYPE_ENUM) { - $enum = Strings::matchAll(isset($col['vendor']['type']) ? $col['vendor']['type'] : $col['vendor']['Type'], ColumnTypes::NATIVE_REGEX_ENUM, PREG_PATTERN_ORDER); + $enum = Strings::matchAll($col['vendor']['type'] ?? $col['vendor']['Type'], ColumnTypes::NATIVE_REGEX_ENUM, PREG_PATTERN_ORDER); if ($enum) { $column->setEnum($enum[1]); $column->setType(ColumnTypes::TYPE_ENUM); @@ -95,7 +95,6 @@ protected function analyseIndexes(Table $table): void $keys = $this->driver->getForeignKeys($tableName); foreach ($indexes as $index) { - foreach ($index['columns'] as $col) { $column = $table->getColumn($col); @@ -103,7 +102,6 @@ protected function analyseIndexes(Table $table): void $column->setUnique($index['unique']); $column->setIndex(true); } - } foreach ($keys as $key) { diff --git a/src/Entity/Table.php b/src/Entity/Table.php index ae11086..9485ee8 100644 --- a/src/Entity/Table.php +++ b/src/Entity/Table.php @@ -59,6 +59,7 @@ public function getPrimaryKeyColumns(): array $primary[] = $column; } } + return $primary; } diff --git a/src/Generator.php b/src/Generator.php index f0c3956..82a3113 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -97,15 +97,19 @@ public function generate(): void if ($this->config->get('generator.generate.entities')) { $this->entityGenerator->generate($database); } + if ($this->config->get('generator.generate.repositories')) { $this->repositoryGenerator->generate($database); } + if ($this->config->get('generator.generate.mappers')) { $this->mapperGenerator->generate($database); } + if ($this->config->get('generator.generate.facades')) { $this->facadeGenerator->generate($database); } + if ($this->config->get('generator.generate.model')) { $this->modelGenerator->generate($database); } diff --git a/src/Generator/Entity/Decorator/ColumnConstantGenerator.php b/src/Generator/Entity/Decorator/ColumnConstantGenerator.php index a8570a9..892e397 100644 --- a/src/Generator/Entity/Decorator/ColumnConstantGenerator.php +++ b/src/Generator/Entity/Decorator/ColumnConstantGenerator.php @@ -26,6 +26,7 @@ public function doDecorate(Column $column, ClassType $class, PhpNamespace $names if (!$this->config->get('entity.generate.column.constant')) { return; } + $name = Strings::upper($this->config->get('entity.column.constants.prefix') . $column->getName()); $class->addConstant($name, Helpers::camelCase($column->getName())); } diff --git a/src/Generator/Entity/Decorator/ColumnDocumentor.php b/src/Generator/Entity/Decorator/ColumnDocumentor.php index 90e0d9b..f49f85e 100644 --- a/src/Generator/Entity/Decorator/ColumnDocumentor.php +++ b/src/Generator/Entity/Decorator/ColumnDocumentor.php @@ -47,7 +47,7 @@ public function doDecorate(Column $column, ClassType $class, PhpNamespace $names } // Enum - if (!empty($enum = $column->getEnum())) { + if (!empty($column->getEnum())) { $doc->setEnum(Strings::upper($column->getName())); } diff --git a/src/Generator/Entity/EntityGenerator.php b/src/Generator/Entity/EntityGenerator.php index 50898b7..cdbd72d 100644 --- a/src/Generator/Entity/EntityGenerator.php +++ b/src/Generator/Entity/EntityGenerator.php @@ -51,7 +51,6 @@ public function generate(Database $database): void // Add table columns foreach ($table->getColumns() as $column) { - if ($this->config->get('generator.entity.exclude.primary')) { if ($column->isPrimary()) continue; } diff --git a/src/Generator/Model/ModelGenerator.php b/src/Generator/Model/ModelGenerator.php index f3056ce..478d837 100644 --- a/src/Generator/Model/ModelGenerator.php +++ b/src/Generator/Model/ModelGenerator.php @@ -47,6 +47,7 @@ public function generate(Database $database): void $doc->setVariable(lcfirst($this->entityResolver->resolveEntityName($table))); $class->addComment((string) $doc); } + $this->generateFile($this->modelResolver->resolveModelFilename(), (string) $namespace); } diff --git a/src/Generator/Repository/RepositoryGenerator.php b/src/Generator/Repository/RepositoryGenerator.php index 375a53c..cb6b0b8 100644 --- a/src/Generator/Repository/RepositoryGenerator.php +++ b/src/Generator/Repository/RepositoryGenerator.php @@ -39,6 +39,7 @@ public function generate(Database $database): void $namespace->addUse($extends); $class->setExtends($extends); } + $namespace->addUse($this->entityResolver->resolveEntityNamespace($table) . '\\' . $this->entityResolver->resolveEntityName($table)); $entityName = $this->entityResolver->resolveEntityName($table); $class->addMethod('getEntityClassNames') diff --git a/src/Resolver/Impl/SimpleResolver.php b/src/Resolver/Impl/SimpleResolver.php index 2f5c410..0cf1a13 100644 --- a/src/Resolver/Impl/SimpleResolver.php +++ b/src/Resolver/Impl/SimpleResolver.php @@ -47,6 +47,7 @@ protected function table(Table $table, bool $singularize = false): string if ($singularize) { $name = Inflector::singularize($name); } + return $name; } diff --git a/src/Resolver/Impl/SimpleSeparateResolver.php b/src/Resolver/Impl/SimpleSeparateResolver.php index 122d099..144ef58 100644 --- a/src/Resolver/Impl/SimpleSeparateResolver.php +++ b/src/Resolver/Impl/SimpleSeparateResolver.php @@ -78,6 +78,7 @@ protected function resolveFilenameFor(string $type, Table $table): string if ($this->config->get($type . '.name.singularize')) { $name = Inflector::singularize($name); } + $name .= $this->config->get($type . '.filename.suffix'); return $this->config->get($type . '.folder') . DIRECTORY_SEPARATOR . $name . '.' . IFilenameResolver::PHP_EXT; } @@ -88,8 +89,8 @@ protected function resolveNameFor(string $type, Table $table): string if ($this->config->get($type . '.name.singularize')) { $name = Inflector::singularize($name); } - $name .= $this->config->get($type . '.name.suffix'); - return $name; + + return $name . $this->config->get($type . '.name.suffix'); } } diff --git a/src/Resolver/Impl/SimpleTogetherResolver.php b/src/Resolver/Impl/SimpleTogetherResolver.php index 5a825dd..8206581 100644 --- a/src/Resolver/Impl/SimpleTogetherResolver.php +++ b/src/Resolver/Impl/SimpleTogetherResolver.php @@ -69,6 +69,7 @@ protected function resolveName(string $type, Table $table): string if ($this->config->get($type . '.name.singularize')) { $name = Inflector::singularize($name); } + $name .= $this->config->get($type . '.name.suffix'); return $this->normalize($name); } @@ -80,6 +81,7 @@ protected function resolveFilenameFor(string $type, Table $table): string if ($this->config->get($type . '.name.singularize')) { $name = Inflector::singularize($name); } + $filename = $this->normalize($name . $this->config->get($type . '.filename.suffix')) . '.' . IFilenameResolver::PHP_EXT; return $folder . Helpers::DS . $filename; } diff --git a/src/Utils/Helpers.php b/src/Utils/Helpers.php index 23011c4..10ff273 100644 --- a/src/Utils/Helpers.php +++ b/src/Utils/Helpers.php @@ -59,6 +59,7 @@ public static function columnType(string $type): string } } } + return $cache[$type]; }