Skip to content

Commit 435252a

Browse files
committed
fix:
- add POINT datatype as string - remove laravel/helpers package
1 parent 3f5edfd commit 435252a

12 files changed

+45
-35
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"php": "^8.0",
1414
"ext-pdo": "*",
1515
"ext-json": "*",
16-
"laravel/helpers": "^1.5",
1716
"illuminate/console": "^6.0|^7.0|^8.0|^9.0",
1817
"illuminate/support": "^6.0|^7.0|^8.0|^9.0",
1918
"illuminate/cache": "^6.0|^7.0|^8.0|^9.0",

src/Commands/MakeEntity.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Nanvaie\DatabaseRepository\Commands;
44

5+
use Illuminate\Support\Str;
56
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
67
use Illuminate\Console\Command;
78

@@ -63,7 +64,7 @@ public function handle(): int
6364
{
6465
$tableName = $this->argument('table_name');
6566
$detectForeignKeys = $this->option('foreign-keys');
66-
$entityName = str_singular(ucfirst(camel_case($tableName)));
67+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
6768
$entityNamespace = config('repository.path.namespace.entities');
6869
$relativeEntitiesPath = config('repository.path.relative.entities');
6970
$entityStubsPath = __DIR__ . '/../../' . config('repository.path.stub.entities');
@@ -93,7 +94,7 @@ public function handle(): int
9394
}
9495

9596
foreach ($columns as $_column) {
96-
$_column->COLUMN_NAME = camel_case($_column->COLUMN_NAME);
97+
$_column->COLUMN_NAME = Str::camel($_column->COLUMN_NAME);
9798
}
9899

99100
$baseContent = file_get_contents($entityStubsPath.'class.stub');

src/Commands/MakeEnum.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Nanvaie\DatabaseRepository\Commands;
44

5+
use Illuminate\Support\Str;
56
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
67
use Illuminate\Console\Command;
78

@@ -62,7 +63,7 @@ public function handle(): int
6263
$enums = [];
6364
foreach ($columns as $_column) {
6465
if ($_column->DATA_TYPE == 'enum') {
65-
$enumClassName = studly_case(str_singular(ucfirst(camel_case($_column->TABLE_NAME))) . '_' . $_column->COLUMN_NAME);
66+
$enumClassName = Str::studly(Str::singular(ucfirst(Str::camel($_column->TABLE_NAME))) . '_' . $_column->COLUMN_NAME);
6667
$enums[$enumClassName] = explode(',', str_replace(['enum(', '\'', ')'], ['', '', ''], $_column->COLUMN_TYPE));
6768

6869
$filenameWithPath = $relativeEntitiesPath . $enumClassName.'.php';

src/Commands/MakeFactory.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Nanvaie\DatabaseRepository\Commands;
44

5+
use Illuminate\Support\Str;
56
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
67
use Illuminate\Console\Command;
78

@@ -29,7 +30,7 @@ class MakeFactory extends Command
2930
public function writeSetter(string $setterStub, string $columnName): string
3031
{
3132
return str_replace(['{{ SetterName }}', '{{ AttributeName }}'],
32-
[ucfirst($columnName), snake_case($columnName)],
33+
[ucfirst($columnName), Str::snake($columnName)],
3334
$setterStub);
3435
}
3536

@@ -41,8 +42,8 @@ public function writeSetter(string $setterStub, string $columnName): string
4142
public function handle(): int
4243
{
4344
$tableName = $this->argument('table_name');
44-
$entityName = str_singular(ucfirst(camel_case($tableName)));
45-
$entityVariableName = camel_case($entityName);
45+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
46+
$entityVariableName = Str::camel($entityName);
4647
$factoryName = $entityName.'Factory';
4748
$entityNamespace = config('repository.path.namespace.entities');
4849
$factoryNamespace = config('repository.path.namespace.factories');
@@ -74,7 +75,7 @@ public function handle(): int
7475
}
7576

7677
foreach ($columns as $_column) {
77-
$_column->COLUMN_NAME = camel_case($_column->COLUMN_NAME);
78+
$_column->COLUMN_NAME = Str::camel($_column->COLUMN_NAME);
7879
}
7980

8081
$baseContent = file_get_contents($factoryStubsPath.'class.stub');

src/Commands/MakeInterfaceRepository.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Nanvaie\DatabaseRepository\Commands;
44

5+
use Illuminate\Support\Str;
56
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
67
use Illuminate\Console\Command;
78

@@ -30,14 +31,14 @@ class MakeInterfaceRepository extends Command
3031
private function writeGetOneFunction(string $getOneStub, string $columnName, string $attributeType): string
3132
{
3233
return str_replace(['{{ FunctionName }}', '{{ ColumnName }}', '{{ AttributeType }}', '{{ AttributeName }}'],
33-
[ucfirst(camel_case($columnName)), $columnName, $attributeType, camel_case($columnName)],
34+
[ucfirst(Str::camel($columnName)), $columnName, $attributeType, Str::camel($columnName)],
3435
$getOneStub);
3536
}
3637

3738
private function writeGetAllFunction(string $getOneStub, string $columnName, string $attributeType): string
3839
{
3940
return str_replace(['{{ FunctionNamePlural }}', '{{ AttributeType }}', '{{ AttributeNamePlural }}'],
40-
[ucfirst(str_plural(camel_case($columnName))), $attributeType, str_plural(camel_case($columnName))],
41+
[ucfirst(Str::plural(Str::camel($columnName))), $attributeType, Str::plural(Str::camel($columnName))],
4142
$getOneStub);
4243
}
4344

@@ -50,8 +51,8 @@ public function handle(): int
5051
{
5152
$tableName = $this->argument('table_name');
5253
$detectForeignKeys = $this->option('foreign-keys');
53-
$entityName = str_singular(ucfirst(camel_case($tableName)));
54-
$entityVariableName = camel_case($entityName);
54+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
55+
$entityVariableName = Str::camel($entityName);
5556
$interfaceName = "I$entityName"."Repository";
5657
$entityNamespace = config('repository.path.namespace.entities');
5758
$repositoryNamespace = config('repository.path.namespace.repositories');

src/Commands/MakeMySqlRepository.php

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

33
namespace Nanvaie\DatabaseRepository\Commands;
44

5+
use Illuminate\Support\Str;
56
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
67
use Illuminate\Console\Command;
78

@@ -30,28 +31,28 @@ class MakeMySqlRepository extends Command
3031
private function writeGetOneFunction(string $getOneStub, string $columnName, string $attributeType): string
3132
{
3233
return str_replace(['{{ FunctionName }}', '{{ ColumnName }}', '{{ AttributeType }}', '{{ AttributeName }}'],
33-
[ucfirst(camel_case($columnName)), $columnName, $attributeType, camel_case($columnName)],
34+
[ucfirst(Str::camel($columnName)), $columnName, $attributeType, Str::camel($columnName)],
3435
$getOneStub);
3536
}
3637

3738
private function writeGetAllFunction(string $getOneStub, string $columnName, string $attributeType): string
3839
{
3940
return str_replace(['{{ FunctionNamePlural }}', '{{ ColumnName }}', '{{ AttributeType }}', '{{ AttributeNamePlural }}'],
40-
[ucfirst(str_plural(camel_case($columnName))), $columnName, $attributeType, str_plural(camel_case($columnName))],
41+
[ucfirst(Str::plural(Str::camel($columnName))), $columnName, $attributeType, Str::plural(Str::camel($columnName))],
4142
$getOneStub);
4243
}
4344

4445
private function writeGetterFunction(string $getterStub, string $columnName): string
4546
{
4647
return str_replace(['{{ ColumnName }}', '{{ GetterName }}'],
47-
[$columnName, ucfirst(camel_case($columnName))],
48+
[$columnName, ucfirst(Str::camel($columnName))],
4849
$getterStub);
4950
}
5051

5152
private function writeSetterFunction(string $setterStub, string $columnName): string
5253
{
5354
return str_replace('{{ SetterName }}',
54-
ucfirst(camel_case($columnName)),
55+
ucfirst(Str::camel($columnName)),
5556
$setterStub);
5657
}
5758

@@ -64,8 +65,8 @@ public function handle(): int
6465
{
6566
$tableName = $this->argument('table_name');
6667
$detectForeignKeys = $this->option('foreign-keys');
67-
$entityName = str_singular(ucfirst(camel_case($tableName)));
68-
$entityVariableName = camel_case($entityName);
68+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
69+
$entityVariableName = Str::camel($entityName);
6970
$factoryName = $entityName.'Factory';
7071
$interfaceName = 'I'.$entityName.'Repository';
7172
$mysqlRepositoryName = 'MySql'.$entityName.'Repository';

src/Commands/MakeRedisRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Nanvaie\DatabaseRepository\Commands;
44

5+
use Illuminate\Support\Str;
56
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
67
use Illuminate\Console\Command;
78

@@ -36,7 +37,7 @@ public function handle(): int
3637
{
3738
$tableName = $this->argument('table_name');
3839
$detectForeignKeys = $this->option('foreign-keys');
39-
$entityName = str_singular(ucfirst(camel_case($tableName)));
40+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
4041
$redisRepositoryName = "Redis$entityName"."Repository";
4142
$redisRepositoryNamespace = config('repository.path.namespace.repositories');
4243
$relativeRedisRepositoryPath = config('repository.path.relative.repositories') . "$entityName" . DIRECTORY_SEPARATOR;

src/Commands/MakeRepository.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nanvaie\DatabaseRepository\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Str;
67
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
78

89
class MakeRepository extends Command
@@ -31,20 +32,20 @@ private function writeFunction(string $functionStub, string $functionName, strin
3132
{
3233
if ($functionName === 'getOneBy') {
3334
$functionReturnType = '?{{ EntityName }}';
34-
$functionName .= ucfirst(camel_case($columnName));
35-
$columnName = camel_case($columnName);
35+
$functionName .= ucfirst(Str::camel($columnName));
36+
$columnName = Str::camel($columnName);
3637
} elseif ($functionName === 'getAllBy') {
3738
$functionReturnType = 'Collection';
38-
$functionName .= ucfirst(str_plural(camel_case($columnName)));
39-
$columnName = str_plural(camel_case($columnName));
39+
$functionName .= ucfirst(Str::plural(Str::camel($columnName)));
40+
$columnName = Str::plural(Str::camel($columnName));
4041
} elseif ($functionName === 'create') {
4142
$functionReturnType = $attributeType;
4243
} elseif (in_array($functionName, ['update', 'remove', 'restore'])) {
4344
$functionReturnType = 'int';
4445
}
4546

4647
return str_replace(['{{ FunctionName }}', '{{ AttributeType }}', '{{ AttributeName }}', '{{ FunctionReturnType }}'],
47-
[$functionName, $attributeType, camel_case($columnName), $functionReturnType],
48+
[$functionName, $attributeType, Str::camel($columnName), $functionReturnType],
4849
$functionStub);
4950
}
5051

@@ -64,8 +65,8 @@ public function handle(): int
6465
{
6566
$tableName = $this->argument('table_name');
6667
$detectForeignKeys = $this->option('foreign-keys');
67-
$entityName = str_singular(ucfirst(camel_case($tableName)));
68-
$entityVariableName = camel_case($entityName);
68+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
69+
$entityVariableName = Str::camel($entityName);
6970
$factoryName = $entityName.'Factory';
7071
$interfaceName = 'I'.$entityName.'Repository';
7172
$repositoryName = $entityName.'Repository';

src/Commands/MakeResource.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Nanvaie\DatabaseRepository\Commands;
44

55
use Illuminate\Console\Command;
6+
use Illuminate\Support\Str;
67
use Nanvaie\DatabaseRepository\CustomMySqlQueries;
78

89
class MakeResource extends Command
@@ -37,7 +38,7 @@ public function writeGetter(string $getterStub, string $columnName, string $attr
3738
public function writeForeignGetter(string $foreignGetterStub, string $columnName, string $attributeName)
3839
{
3940
return str_replace(['{{ AttributeName }}', '{{ GetterName }}', '{{ AttributeType }}'],
40-
[snake_case($columnName), ucfirst($columnName), ucfirst($attributeName)],
41+
[Str::snake($columnName), ucfirst($columnName), ucfirst($attributeName)],
4142
$foreignGetterStub);
4243
}
4344

@@ -50,8 +51,8 @@ public function handle(): int
5051
{
5152
$tableName = $this->argument('table_name');
5253
$detectForeignKeys = $this->option('foreign-keys');
53-
$entityName = str_singular(ucfirst(camel_case($tableName)));
54-
$entityVariableName = camel_case($entityName);
54+
$entityName = Str::singular(ucfirst(Str::camel($tableName)));
55+
$entityVariableName = Str::camel($entityName);
5556
$entityNamespace = config('repository.path.namespace.entities');
5657
$resourceName = $entityName."Resource";
5758
$resourceNamespace = config('repository.path.namespace.resources');
@@ -92,7 +93,7 @@ public function handle(): int
9293

9394
$getterFunctions = '';
9495
foreach ($columns as $_column) {
95-
$getterFunctions .= $this->writeGetter($getterStub, $_column->COLUMN_NAME, camel_case($_column->COLUMN_NAME));
96+
$getterFunctions .= $this->writeGetter($getterStub, $_column->COLUMN_NAME, Str::camel($_column->COLUMN_NAME));
9697
}
9798

9899
$foreignGetterFunctions = '';

src/CustomMySqlQueries.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Collection;
66
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Str;
78

89
trait CustomMySqlQueries
910
{
@@ -37,6 +38,7 @@ trait CustomMySqlQueries
3738
'time' => 'string',
3839
'datetime' => 'string',
3940
'timestamp' => 'string',
41+
'point' => 'string',
4042
];
4143

4244
/**
@@ -81,8 +83,8 @@ public function extractForeignKeys(string $tableName): Collection
8183
->get();
8284

8385
$foreignKeys->each(function ($foreignKey) {
84-
$foreignKey->VARIABLE_NAME = camel_case(str_replace('_id', '', $foreignKey->COLUMN_NAME));
85-
$foreignKey->ENTITY_DATA_TYPE = ucfirst(camel_case(str_singular($foreignKey->REFERENCED_TABLE_NAME)));
86+
$foreignKey->VARIABLE_NAME = Str::camel(str_replace('_id', '', $foreignKey->COLUMN_NAME));
87+
$foreignKey->ENTITY_DATA_TYPE = ucfirst(Str::camel(Str::singular($foreignKey->REFERENCED_TABLE_NAME)));
8688
});
8789

8890
return $foreignKeys;

0 commit comments

Comments
 (0)