1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Consigliere\Components\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Consigliere\Components\Support\Stub; |
7
|
|
|
use Consigliere\Components\Traits\ComponentCommandTrait; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
|
11
|
|
|
class MakeCommandCommand extends Command |
12
|
|
|
{ |
13
|
|
|
use ComponentCommandTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The name of argument name. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $argumentName = 'name'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command name. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $name = 'component:make-command'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The console command description. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $description = 'Generate new Artisan command for the specified component.'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the console command arguments. |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
|
|
protected function getArguments() |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
['name', InputArgument::REQUIRED, 'The name of the command.'], |
45
|
|
|
['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the console command options. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
protected function getOptions() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', null], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
protected function getTemplateContents() |
65
|
|
|
{ |
66
|
|
|
$component = $this->laravel['components']->findOrFail($this->getComponentName()); |
67
|
|
|
|
68
|
|
|
return (new Stub('/command.stub', [ |
69
|
|
|
'COMMAND_NAME' => $this->getCommandName(), |
70
|
|
|
'NAMESPACE' => $this->getClassNamespace($component), |
71
|
|
|
'CLASS' => $this->getClass(), |
72
|
|
|
]))->render(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
protected function getDestinationFilePath() |
79
|
|
|
{ |
80
|
|
|
$path = $this->laravel['components']->getComponentPath($this->getComponentName()); |
81
|
|
|
|
82
|
|
|
$seederPath = $this->laravel['components']->config('paths.generator.command'); |
83
|
|
|
|
84
|
|
|
return $path . $seederPath . '/' . $this->getFileName() . '.php'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
|
|
private function getFileName() |
91
|
|
|
{ |
92
|
|
|
return Str::studly($this->argument('name')); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
private function getCommandName() |
99
|
|
|
{ |
100
|
|
|
return $this->option('command') ?: 'command:name'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get default namespace. |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
|
|
public function getDefaultNamespace() |
109
|
|
|
{ |
110
|
|
|
return 'Console'; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.