22
33namespace Eghamat24 \DatabaseRepository \Commands ;
44
5- use Illuminate \Support \Str ;
5+ use Illuminate \Support \Collection ;
66use Eghamat24 \DatabaseRepository \Creators \BaseCreator ;
77use Eghamat24 \DatabaseRepository \Creators \CreatorRedisRepository ;
88use Eghamat24 \DatabaseRepository \CustomMySqlQueries ;
9- use Illuminate \Console \Command ;
109
1110class MakeRedisRepository extends BaseCommand
1211{
12+ use CustomMySqlQueries;
13+
14+ private const OBJECT_NAME = 'Redis Repository ' ;
15+
1316 /**
1417 * The name and signature of the console command.
1518 *
@@ -28,37 +31,69 @@ class MakeRedisRepository extends BaseCommand
2831 */
2932 protected $ description = 'Create a new Redis repository class ' ;
3033
31- use CustomMySqlQueries;
32-
33- /**
34- * Execute the console command.
35- *
36- * @return int
37- */
3834 public function handle ()
3935 {
4036 $ this ->checkStrategyName ();
4137 $ this ->setArguments ();
4238
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 ;
4641 $ filenameWithPath = $ relativeRedisRepositoryPath . $ redisRepositoryName . '.php ' ;
4742
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 );
5345
54- if ($ this ->detectForeignKeys ) {
55- $ foreignKeys = $ this ->extractForeignKeys ($ this ->tableName );
56- }
46+ $ redisRepositoryCreator = $ this ->getRedisRepositoryCreator ($ redisRepositoryName );
47+ $ baseContent = $ this ->getBaseContent ($ redisRepositoryCreator , $ filenameWithPath );
5748
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 );
6249 $ this ->finalized ($ filenameWithPath , $ redisRepositoryName , $ baseContent );
6350 }
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+ }
6499}
0 commit comments