1 | <?php |
||
10 | class ApiMakeCommand extends Command |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * The filesystem instance. |
||
15 | * |
||
16 | * @var \Illuminate\Filesystem\Filesystem |
||
17 | */ |
||
18 | protected $files; |
||
19 | |||
20 | /** |
||
21 | * The console command name. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $name = 'make:api'; |
||
26 | |||
27 | /** |
||
28 | * The console command description. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $description = 'Create api controller, transformer and api routes for a given model (ddiimmkkaass/lumen-api-generator)'; |
||
33 | |||
34 | /** |
||
35 | * The array of variables available in stubs. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $stubVariables = [ |
||
40 | 'app' => [], |
||
41 | 'model' => [], |
||
42 | 'controller' => [], |
||
43 | 'transformer' => [], |
||
44 | 'route' => [], |
||
45 | ]; |
||
46 | |||
47 | protected $modelsBaseNamespace; |
||
48 | |||
49 | /** |
||
50 | * Create a new controller creator command instance. |
||
51 | * |
||
52 | * @param \Illuminate\Filesystem\Filesystem $files |
||
53 | */ |
||
54 | public function __construct(Filesystem $files) |
||
60 | |||
61 | /** |
||
62 | * Execute the console command. |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public function fire() |
||
76 | |||
77 | /** |
||
78 | * Prepare names, paths and namespaces for stubs. |
||
79 | * |
||
80 | * @param $name |
||
81 | */ |
||
82 | protected function prepareVariablesForStubs($name) |
||
95 | |||
96 | /** |
||
97 | * Set the model name and namespace. |
||
98 | * |
||
99 | * @return $this |
||
100 | */ |
||
101 | protected function setModelData($name) |
||
122 | |||
123 | /** |
||
124 | * Set the controller names and namespaces. |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | protected function setControllerData() |
||
132 | |||
133 | /** |
||
134 | * Set route data for a given model. |
||
135 | * "Profile\Payer" -> "profile_payers". |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | protected function setRouteData() |
||
148 | |||
149 | /** |
||
150 | * Set the transformer names and namespaces. |
||
151 | * |
||
152 | * @return $this |
||
153 | */ |
||
154 | protected function setTransformerData() |
||
158 | |||
159 | /** |
||
160 | * Set entity's names and namespaces. |
||
161 | * |
||
162 | * @param string $entity |
||
163 | * |
||
164 | * @return $this |
||
165 | */ |
||
166 | protected function setDataForEntity($entity) |
||
186 | |||
187 | /** |
||
188 | * Create controller class file from a stub. |
||
189 | */ |
||
190 | protected function createController() |
||
194 | |||
195 | /** |
||
196 | * Create controller class file from a stub. |
||
197 | */ |
||
198 | protected function createTransformer() |
||
202 | |||
203 | /** |
||
204 | * Add routes to routes file. |
||
205 | */ |
||
206 | protected function addRoutes() |
||
231 | |||
232 | /** |
||
233 | * Create class with a given type. |
||
234 | * |
||
235 | * @param $type |
||
236 | * |
||
237 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
||
238 | */ |
||
239 | protected function createClass($type) |
||
254 | |||
255 | /** |
||
256 | * Get the destination file path. |
||
257 | * |
||
258 | * @param string $name |
||
259 | * |
||
260 | * @return string |
||
261 | */ |
||
262 | protected function getPath($name) |
||
268 | |||
269 | /** |
||
270 | * Build the directory for the class if needed. |
||
271 | * |
||
272 | * @param string $path |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | protected function makeDirectoryIfNeeded($path) |
||
282 | |||
283 | /** |
||
284 | * Get stub content and replace all stub placeholders |
||
285 | * with data from $this->stubData. |
||
286 | * |
||
287 | * @param string $path |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | protected function constructStub($path) |
||
303 | |||
304 | /** |
||
305 | * Get the console command arguments. |
||
306 | * |
||
307 | * @return array |
||
308 | */ |
||
309 | protected function getArguments() |
||
315 | |||
316 | /** |
||
317 | * Convert "/" to "\". |
||
318 | * |
||
319 | * @param $string |
||
320 | * |
||
321 | * @return string |
||
322 | */ |
||
323 | protected function convertSlashes($string) |
||
327 | } |
||
328 |