1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Consigliere\Components\Commands; |
4
|
|
|
|
5
|
|
|
use Consigliere\Components\Support\Stub; |
6
|
|
|
use Consigliere\Components\Traits\ComponentCommandTrait; |
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
|
10
|
|
|
class GenerateEventCommand extends Command |
11
|
|
|
{ |
12
|
|
|
use ComponentCommandTrait; |
13
|
|
|
|
14
|
|
|
protected $argumentName = 'name'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The console command name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $name = 'component:make-event'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command description. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'Generate a new Event Class for the specified component'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get the console command arguments. |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
protected function getArguments() |
36
|
|
|
{ |
37
|
|
|
return [ |
38
|
|
|
['name', InputArgument::REQUIRED, 'The name of the event.'], |
39
|
|
|
['component', InputArgument::OPTIONAL, 'The name of component will be used.'], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get the console command options. |
45
|
|
|
* |
46
|
|
|
* @return array |
47
|
|
|
*/ |
48
|
|
|
protected function getOptions() |
49
|
|
|
{ |
50
|
|
|
return [ |
51
|
|
|
['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getTemplateContents() |
56
|
|
|
{ |
57
|
|
|
$component = $this->laravel['components']->findOrFail($this->getComponentName()); |
58
|
|
|
|
59
|
|
|
return (new Stub('/event.stub', [ |
60
|
|
|
'NAMESPACE' => $this->getClassNamespace($component) . "\\" . config('components.paths.generator.event'), |
61
|
|
|
"CLASS" => $this->getClass(), |
62
|
|
|
'DUMMYNAMESPACE' => $this->laravel->getNamespace() . 'Events', |
63
|
|
|
]))->render(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getDestinationFilePath() |
67
|
|
|
{ |
68
|
|
|
$path = $this->laravel['components']->getComponentPath($this->getComponentName()); |
69
|
|
|
$seederPath = $this->laravel['components']->config('paths.generator.event'); |
70
|
|
|
|
71
|
|
|
return $path . $seederPath . '/' . $this->getFileName() . '.php'; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
|
|
protected function getFileName() |
78
|
|
|
{ |
79
|
|
|
return studly_case($this->argument('name')); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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.