1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelZero\Framework\Commands\App; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\GeneratorCommand; |
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
|
9
|
|
|
class CommandMaker extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* The console command name. |
13
|
|
|
* |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
protected $name = 'make:command'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command description. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $description = 'Create a new command'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The type of class being generated. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $type = 'Console command'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Replace the class name for the given stub. |
34
|
|
|
* |
35
|
|
|
* @param string $stub |
36
|
|
|
* @param string $name |
37
|
|
|
* |
38
|
|
|
* @return string |
39
|
|
|
*/ |
40
|
|
|
protected function replaceClass($stub, $name) |
41
|
|
|
{ |
42
|
|
|
$stub = parent::replaceClass($stub, $name); |
43
|
|
|
|
44
|
|
|
return str_replace('dummy:command', $this->option('command'), $stub); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the desired class name from the input. |
49
|
|
|
* |
50
|
|
|
* @return string |
51
|
|
|
*/ |
52
|
|
|
protected function getNameInput() |
53
|
|
|
{ |
54
|
|
|
return ucfirst(parent::getNameInput()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the stub file for the generator. |
59
|
|
|
* |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
protected function getStub() |
63
|
|
|
{ |
64
|
|
|
return __DIR__.'/stubs/console.stub'; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Get the default namespace for the class. |
69
|
|
|
* |
70
|
|
|
* @param string $rootNamespace |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
|
|
protected function getDefaultNamespace($rootNamespace) |
75
|
|
|
{ |
76
|
|
|
return $rootNamespace.'\Commands'; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the console command arguments. |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
protected function getArguments() |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
['name', InputArgument::REQUIRED, 'The name of the command.'], |
88
|
|
|
]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the console command options. |
93
|
|
|
* |
94
|
|
|
* @return array |
95
|
|
|
*/ |
96
|
|
|
protected function getOptions() |
97
|
|
|
{ |
98
|
|
|
return [ |
99
|
|
|
[ |
100
|
|
|
'command', |
101
|
|
|
null, |
102
|
|
|
InputOption::VALUE_OPTIONAL, |
103
|
|
|
'The terminal command that should be assigned.', |
104
|
|
|
'command:name', |
105
|
|
|
], |
106
|
|
|
]; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|