2
2
3
3
namespace Eghamat24 \DatabaseRepository \Commands ;
4
4
5
- use Illuminate \Support \Str ;
5
+ use Illuminate \Support \Collection ;
6
6
use Eghamat24 \DatabaseRepository \Creators \BaseCreator ;
7
7
use Eghamat24 \DatabaseRepository \Creators \CreatorRedisRepository ;
8
8
use Eghamat24 \DatabaseRepository \CustomMySqlQueries ;
9
- use Illuminate \Console \Command ;
10
9
11
10
class MakeRedisRepository extends BaseCommand
12
11
{
12
+ use CustomMySqlQueries;
13
+
14
+ private const OBJECT_NAME = 'Redis Repository ' ;
15
+
13
16
/**
14
17
* The name and signature of the console command.
15
18
*
@@ -28,37 +31,69 @@ class MakeRedisRepository extends BaseCommand
28
31
*/
29
32
protected $ description = 'Create a new Redis repository class ' ;
30
33
31
- use CustomMySqlQueries;
32
-
33
- /**
34
- * Execute the console command.
35
- *
36
- * @return int
37
- */
38
34
public function handle ()
39
35
{
40
36
$ this ->checkStrategyName ();
41
37
$ this ->setArguments ();
42
38
43
- $ redisRepositoryName = "Redis $ this ->entityName " . "Repository " ;
44
- $ redisRepositoryNamespace = config ('repository.path.namespace.repositories ' );
45
- $ relativeRedisRepositoryPath = config ('repository.path.relative.repositories ' ) . "$ this ->entityName " . DIRECTORY_SEPARATOR ;
39
+ $ redisRepositoryName = "Redis $ this ->entityName " . 'Repository ' ;
40
+ $ relativeRedisRepositoryPath = config ('repository.path.relative.repositories ' ) . $ this ->entityName . DIRECTORY_SEPARATOR ;
46
41
$ filenameWithPath = $ relativeRedisRepositoryPath . $ redisRepositoryName . '.php ' ;
47
42
48
- $ this ->checkDelete ($ filenameWithPath , $ redisRepositoryName , "Redis Repository " );
49
- $ this ->checkDirectory ($ relativeRedisRepositoryPath );
50
- $ this ->checkClassExist ($ this ->repositoryNamespace , $ redisRepositoryName , "Redis Repository " );
51
- $ columns = $ this ->getAllColumnsInTable ($ this ->tableName );
52
- $ this ->checkEmpty ($ columns , $ this ->tableName );
43
+ $ this ->checkAndPrepare ($ filenameWithPath , $ redisRepositoryName , $ relativeRedisRepositoryPath );
44
+ $ this ->getColumnsOf ($ this ->tableName );
53
45
54
- if ($ this ->detectForeignKeys ) {
55
- $ foreignKeys = $ this ->extractForeignKeys ($ this ->tableName );
56
- }
46
+ $ redisRepositoryCreator = $ this ->getRedisRepositoryCreator ($ redisRepositoryName );
47
+ $ baseContent = $ this ->getBaseContent ($ redisRepositoryCreator , $ filenameWithPath );
57
48
58
- $ repositoryStubsPath = __DIR__ . '/../../ ' . config ('repository.path.stub.repositories.base ' );
59
- $ mysqlRepoCreator = new CreatorRedisRepository ($ redisRepositoryName , $ redisRepositoryNamespace , $ this ->entityName , $ this ->strategyName , $ repositoryStubsPath );
60
- $ creator = new BaseCreator ($ mysqlRepoCreator );
61
- $ baseContent = $ creator ->createClass ($ filenameWithPath , $ this );
62
49
$ this ->finalized ($ filenameWithPath , $ redisRepositoryName , $ baseContent );
63
50
}
51
+
52
+
53
+ private function getColumnsOf (string $ tableName ): Collection
54
+ {
55
+ $ columns = $ this ->getAllColumnsInTable ($ tableName );
56
+ $ this ->checkEmpty ($ columns , $ tableName );
57
+
58
+ return $ columns ;
59
+ }
60
+
61
+
62
+ private function getRedisRepositoryCreator (string $ redisRepositoryName ): CreatorRedisRepository
63
+ {
64
+ $ redisRepositoryNamespace = config ('repository.path.namespace.repositories ' );
65
+ $ repositoryStubsPath = __DIR__ . '/../../ ' . config ('repository.path.stub.repositories.base ' );
66
+
67
+ return new CreatorRedisRepository (
68
+ $ redisRepositoryName ,
69
+ $ redisRepositoryNamespace ,
70
+ $ this ->entityName ,
71
+ $ this ->strategyName ,
72
+ $ repositoryStubsPath
73
+ );
74
+ }
75
+
76
+ /**
77
+ * @param CreatorRedisRepository $redisRepositoryCreator
78
+ * @param string $filenameWithPath
79
+ * @return string
80
+ */
81
+ private function getBaseContent (CreatorRedisRepository $ redisRepositoryCreator , string $ filenameWithPath ): string
82
+ {
83
+ $ creator = new BaseCreator ($ redisRepositoryCreator );
84
+ return $ creator ->createClass ($ filenameWithPath , $ this );
85
+ }
86
+
87
+ /**
88
+ * @param string $filenameWithPath
89
+ * @param string $redisRepositoryName
90
+ * @param string $relativeRedisRepositoryPath
91
+ * @return void
92
+ */
93
+ private function checkAndPrepare (string $ filenameWithPath , string $ redisRepositoryName , string $ relativeRedisRepositoryPath ): void
94
+ {
95
+ $ this ->checkDelete ($ filenameWithPath , $ redisRepositoryName , self ::OBJECT_NAME );
96
+ $ this ->checkDirectory ($ relativeRedisRepositoryPath );
97
+ $ this ->checkClassExist ($ this ->repositoryNamespace , $ redisRepositoryName , self ::OBJECT_NAME );
98
+ }
64
99
}
0 commit comments