|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Console\Commands\Generator; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
|
7
|
|
|
use Illuminate\Support\Str; |
|
8
|
|
|
|
|
9
|
|
|
abstract class BaseGenerator extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
protected $filesystem; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Create a new command instance. |
|
15
|
|
|
* |
|
16
|
|
|
* @return void |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct(Filesystem $filesystem) |
|
19
|
|
|
{ |
|
20
|
|
|
parent::__construct(); |
|
21
|
|
|
|
|
22
|
|
|
$this->filesystem = $filesystem; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* get stub content. |
|
27
|
|
|
* |
|
28
|
|
|
* @param $type |
|
29
|
|
|
* |
|
30
|
|
|
* @return bool|string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function getStubs($type) : string |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->filesystem->get(__DIR__."/stubs/$type.stub"); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get path for save controller files. |
|
39
|
|
|
* |
|
40
|
|
|
* @return string |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function getControllerPath() : string |
|
43
|
|
|
{ |
|
44
|
|
|
return app_path('Http/Controllers/Admin/'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get path for save View files. |
|
49
|
|
|
* |
|
50
|
|
|
* @return string |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getViewPath() : string |
|
53
|
|
|
{ |
|
54
|
|
|
return resource_path('views/admin/'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Get path for save Tests files. |
|
59
|
|
|
* |
|
60
|
|
|
* @return string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected function getTestsPath() : string |
|
63
|
|
|
{ |
|
64
|
|
|
return base_path('tests/'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get path for save Repository files. |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function getRepositoriesPath() : string |
|
73
|
|
|
{ |
|
74
|
|
|
return app_path('Repositories/'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Get path for update Repository files. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function getBindServiceProviderPath() : string |
|
83
|
|
|
{ |
|
84
|
|
|
return app_path('Providers/AppServiceProvider.php'); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Get path for save Services files. |
|
89
|
|
|
* |
|
90
|
|
|
* @return string |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function getServicesPath() : string |
|
93
|
|
|
{ |
|
94
|
|
|
return app_path('Services/'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Get target name. |
|
99
|
|
|
* |
|
100
|
|
|
* @return array|null|string |
|
101
|
|
|
*/ |
|
102
|
|
|
protected function getTargetName() |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->argument('name'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Replace & save file. |
|
109
|
|
|
* |
|
110
|
|
|
* @param $stub |
|
111
|
|
|
* @param $path |
|
112
|
|
|
* @param $name |
|
113
|
|
|
*/ |
|
114
|
|
|
protected function proceedAndSaveFile($name, $stub, $path) |
|
115
|
|
|
{ |
|
116
|
|
|
$template = str_replace([ |
|
117
|
|
|
'{{Model}}', |
|
118
|
|
|
'{{model}}', |
|
119
|
|
|
'{{models}}', |
|
120
|
|
|
], [ |
|
121
|
|
|
ucwords($name), |
|
122
|
|
|
strtolower($name), |
|
123
|
|
|
strtolower(Str::plural($name)), |
|
124
|
|
|
], |
|
125
|
|
|
$this->getStubs($stub) |
|
126
|
|
|
); |
|
127
|
|
|
$this->filesystem->put($path, $template); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|