1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Foundation\Generator\Commands; |
4
|
|
|
|
5
|
|
|
use Foundation\Generator\Abstracts\AbstractGeneratorCommand; |
6
|
|
|
use Foundation\Generator\Abstracts\FileGeneratorCommand; |
7
|
|
|
use Foundation\Generator\Events\RouteGeneratedEvent; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
|
12
|
|
|
class RouteMakeCommand extends FileGeneratorCommand |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* The console command name. |
16
|
|
|
* |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
protected $name = 'larapi:make:route'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The console command description. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $description = 'Create a new route file for the specified module'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The name of the generated resource. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $generatorName = 'route'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The stub name. |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $stub = 'route.stub'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The file path. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $filePath = '/Routes'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The event that will fire when the file is created. |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $event = RouteGeneratedEvent::class; |
55
|
|
|
|
56
|
2 |
|
protected function stubOptions(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
2 |
|
'MODULE_NAME' => ucfirst($this->getModuleName()), |
60
|
2 |
|
'CAPS_MODULE_NAME' => strtoupper($this->getModuleName()), |
61
|
2 |
|
'VERSION' => $this->getVersion() |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
2 |
|
protected function getVersion() :string { |
66
|
2 |
|
return $this->getOption('versioning'); |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
protected function afterGeneration(): void |
70
|
|
|
{ |
71
|
2 |
|
$this->info("Don't forget to add permissions to the Permission model!"); |
72
|
2 |
|
} |
73
|
|
|
|
74
|
|
|
protected function handleVersioningOption($shortcut, $type, $question, $default){ |
|
|
|
|
75
|
|
|
return $this->anticipate('What is the version of the route?',['v1','v2','v3','v4','v5'],$default); |
76
|
|
|
} |
77
|
|
|
|
78
|
112 |
|
protected function setOptions(): array |
79
|
|
|
{ |
80
|
|
|
return [ |
81
|
112 |
|
['versioning', null, InputOption::VALUE_OPTIONAL, 'The route version', 'v1'], |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
2 |
|
protected function getFileName() :string |
86
|
|
|
{ |
87
|
2 |
|
return strtolower(Str::plural($this->getModuleName())).'.'.$this->getVersion() . '.php'; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.