1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Nwidart\Modules\Commands\GeneratorCommand; |
6
|
|
|
use Nwidart\Modules\Module; |
7
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
8
|
|
|
use Pingpong\Support\Stub; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
11
|
|
|
|
12
|
|
|
class GenerateListenerCommand extends GeneratorCommand |
13
|
|
|
{ |
14
|
|
|
use ModuleCommandTrait; |
15
|
|
|
|
16
|
|
|
protected $argumentName = 'name'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The console command name. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $name = 'module:make-listener'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The console command description. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
protected $description = 'Generate a new Listener Class for the specified module'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Get the console command arguments. |
34
|
|
|
* |
35
|
|
|
* @return array |
36
|
|
|
*/ |
37
|
25 |
|
protected function getArguments() |
38
|
|
|
{ |
39
|
2 |
|
return [ |
40
|
25 |
|
['name', InputArgument::REQUIRED, 'The name of the command.'], |
41
|
25 |
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
42
|
25 |
|
]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the console command options. |
47
|
|
|
* |
48
|
|
|
* @return array |
49
|
|
|
*/ |
50
|
25 |
|
protected function getOptions() |
51
|
|
|
{ |
52
|
|
|
return [ |
53
|
25 |
|
['event', null, InputOption::VALUE_REQUIRED, 'An example option.', null], |
54
|
25 |
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
protected function getTemplateContents() |
58
|
|
|
{ |
59
|
2 |
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
60
|
|
|
|
61
|
2 |
|
return (new Stub('/listener.stub', [ |
62
|
2 |
|
'NAMESPACE' => $this->getClassNamespace($module) . "\\" . config("modules.paths.generator.listener"), |
63
|
2 |
|
"EVENTNAME" => $this->getEventName($module), |
64
|
2 |
|
"EVENTSHORTENEDNAME" => $this->option('event'), |
65
|
2 |
|
"CLASS" => $this->getClass(), |
66
|
2 |
|
'DUMMYNAMESPACE' => $this->laravel->getNamespace() . "Events" |
67
|
2 |
|
]))->render(); |
68
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
protected function getDestinationFilePath() |
72
|
|
|
{ |
73
|
2 |
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
74
|
|
|
|
75
|
2 |
|
$seederPath = $this->laravel['modules']->config('paths.generator.listener'); |
76
|
|
|
|
77
|
2 |
|
return $path . $seederPath . '/' . $this->getFileName() . '.php'; |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
2 |
|
protected function getFileName() |
85
|
|
|
{ |
86
|
2 |
|
return studly_case($this->argument('name')); |
|
|
|
|
87
|
2 |
|
} |
88
|
|
|
|
89
|
2 |
|
public function fire() |
90
|
|
|
{ |
91
|
2 |
|
if (!$this->option('event')) { |
92
|
|
|
return $this->error("The --event option is neccessary"); |
93
|
|
|
} |
94
|
|
|
|
95
|
2 |
|
parent::fire(); |
96
|
2 |
|
} |
97
|
|
|
|
98
|
2 |
|
protected function getEventName(Module $module) |
99
|
|
|
{ |
100
|
2 |
|
return $this->getClassNamespace($module) . "\\" . config("modules.paths.generator.event") . "\\" . $this->option('event'); |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.