1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
6
|
|
|
use Pingpong\Support\Stub; |
7
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
|
11
|
|
|
class CommandCommand extends GeneratorCommand |
12
|
|
|
{ |
13
|
|
|
use ModuleCommandTrait; |
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 = 'module:make-command'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* The console command description. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $description = 'Generate new Artisan command for the specified module.'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get the console command arguments. |
38
|
|
|
* |
39
|
|
|
* @return array |
40
|
|
|
*/ |
41
|
16 |
|
protected function getArguments() |
42
|
|
|
{ |
43
|
|
|
return array( |
44
|
16 |
|
array('name', InputArgument::REQUIRED, 'The name of the command.'), |
45
|
16 |
|
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'), |
46
|
16 |
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the console command options. |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
16 |
|
protected function getOptions() |
55
|
|
|
{ |
56
|
|
|
return array( |
57
|
16 |
|
array('command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', null), |
58
|
16 |
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
3 |
|
protected function getTemplateContents() |
65
|
|
|
{ |
66
|
3 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
67
|
|
|
|
68
|
3 |
|
return (new Stub('/command.stub', [ |
69
|
3 |
|
'COMMAND_NAME' => $this->getCommandName(), |
70
|
3 |
|
'NAMESPACE' => $this->getClassNamespace($module), |
71
|
3 |
|
'CLASS' => $this->getClass(), |
72
|
3 |
|
]))->render(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
3 |
|
protected function getDestinationFilePath() |
79
|
|
|
{ |
80
|
3 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
81
|
|
|
|
82
|
3 |
|
$seederPath = $this->laravel['modules']->config('paths.generator.command'); |
83
|
|
|
|
84
|
3 |
|
return $path.$seederPath.'/'.$this->getFileName().'.php'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
3 |
|
private function getFileName() |
91
|
|
|
{ |
92
|
3 |
|
return Str::studly($this->argument('name')); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
3 |
|
private function getCommandName() |
99
|
|
|
{ |
100
|
3 |
|
return $this->option('command') ?: 'command:name'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get default namespace. |
105
|
|
|
* |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
3 |
|
public function getDefaultNamespace() |
109
|
|
|
{ |
110
|
3 |
|
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.