2
2
3
3
namespace Eghamat24 \DatabaseRepository \Commands ;
4
4
5
- use Illuminate \Support \Str ;
6
5
use Eghamat24 \DatabaseRepository \Creators \BaseCreator ;
7
- use Eghamat24 \DatabaseRepository \Creators \CreatorEntity ;
8
6
use Eghamat24 \DatabaseRepository \Creators \CreatorMySqlRepository ;
9
7
use Eghamat24 \DatabaseRepository \CustomMySqlQueries ;
10
- use Illuminate \Console \ Command ;
8
+ use Illuminate \Support \ Collection ;
11
9
12
10
class MakeMySqlRepository extends BaseCommand
13
11
{
12
+ use CustomMySqlQueries;
13
+
14
+ private const OBJECT_NAME = 'MySql Repository ' ;
15
+
14
16
/**
15
17
* The name and signature of the console command.
16
18
*
@@ -29,24 +31,63 @@ class MakeMySqlRepository extends BaseCommand
29
31
*/
30
32
protected $ description = 'Create a new MySql repository class ' ;
31
33
32
- use CustomMySqlQueries;
33
34
34
- /**
35
- * Execute the console command.
36
- *
37
- * @return int
38
- */
39
35
public function handle (): void
40
36
{
41
37
$ this ->setArguments ();
42
- $ filenameWithPath = $ this ->relativeMysqlRepositoryPath . $ this ->mysqlRepositoryName . '.php ' ;
43
- $ this ->checkDelete ($ filenameWithPath , $ this ->mysqlRepositoryName , "MySql Repository " );
38
+
39
+ $ filenameWithPath = $ this ->getFileNameWithPath (
40
+ $ this ->relativeMysqlRepositoryPath ,
41
+ $ this ->mysqlRepositoryName
42
+ );
43
+
44
+ $ this ->checkAndPrepare ($ filenameWithPath );
45
+
46
+ $ this ->finalized (
47
+ $ filenameWithPath ,
48
+ $ this ->mysqlRepositoryName ,
49
+ $ this ->generateBaseContent ($ filenameWithPath )
50
+ );
51
+ }
52
+
53
+
54
+ private function getFileNameWithPath (string $ relativePath , string $ sectionName ): string
55
+ {
56
+ return $ relativePath . $ sectionName . '.php ' ;
57
+ }
58
+
59
+
60
+ private function checkAndPrepare (string $ filenameWithPath )
61
+ {
62
+ $ this ->checkDelete ($ filenameWithPath , $ this ->mysqlRepositoryName , self ::OBJECT_NAME );
44
63
$ this ->checkDirectory ($ this ->relativeMysqlRepositoryPath );
45
- $ this ->checkClassExist ($ this ->repositoryNamespace , $ this ->mysqlRepositoryName , "MySql Repository " );
46
- $ columns = $ this ->getAllColumnsInTable ($ this ->tableName );
47
- $ this ->checkEmpty ($ columns , $ this ->tableName );
64
+ $ this ->checkClassExist ($ this ->repositoryNamespace , $ this ->mysqlRepositoryName , self ::OBJECT_NAME );
65
+ }
66
+
67
+
68
+ private function getColumnsOf (string $ tableName ): Collection
69
+ {
70
+ $ columns = $ this ->getAllColumnsInTable ($ tableName );
71
+ $ this ->checkEmpty ($ columns , $ tableName );
72
+
73
+ return $ columns ;
74
+ }
48
75
49
- $ mysqlRepoCreator = new CreatorMySqlRepository ($ columns ,
76
+
77
+ private function generateBaseContent (string $ filenameWithPath ): string
78
+ {
79
+ $ mysqlRepoCreator = $ this ->makeMySqlRepoCreator ();
80
+
81
+ return (new BaseCreator ($ mysqlRepoCreator ))->createClass ($ filenameWithPath , $ this );
82
+ }
83
+
84
+ /**
85
+ * @return CreatorMySqlRepository
86
+ */
87
+ private function makeMySqlRepoCreator (): CreatorMySqlRepository
88
+ {
89
+ return new CreatorMySqlRepository (
90
+ $ this ->getColumnsOf ($ this ->tableName ),
50
91
$ this ->tableName ,
51
92
$ this ->entityName ,
52
93
$ this ->entityVariableName ,
@@ -59,9 +100,5 @@ public function handle(): void
59
100
$ this ->mysqlRepositoryStubsPath ,
60
101
$ this ->detectForeignKeys
61
102
);
62
- $ creator = new BaseCreator ($ mysqlRepoCreator );
63
- $ baseContent = $ creator ->createClass ($ filenameWithPath , $ this );
64
-
65
- $ this ->finalized ($ filenameWithPath , $ this ->mysqlRepositoryName , $ baseContent );
66
103
}
67
104
}
0 commit comments