1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelPlus\Extension\Generators\Commands; |
4
|
|
|
|
5
|
|
|
use Jumilla\Generators\Laravel\OneFileGeneratorCommand as BaseCommand; |
6
|
|
|
use Jumilla\Generators\FileGenerator; |
7
|
|
|
use LaravelPlus\Extension\Addons\Addon; |
8
|
|
|
use LaravelPlus\Extension\Generators\GeneratorCommandTrait; |
9
|
|
|
use RuntimeException; |
10
|
|
|
|
11
|
|
|
class ListenerMakeCommand extends BaseCommand |
12
|
|
|
{ |
13
|
|
|
use GeneratorCommandTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The console command singature. |
17
|
|
|
* |
18
|
|
|
* @var stringphp |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'make:listener |
21
|
|
|
{name : The name of the class} |
22
|
|
|
{--a|addon= : The name of the addon} |
23
|
|
|
{--e|event= : The event class the being listened for} |
24
|
|
|
{--queued : Indicates the event listener should be queued} |
25
|
|
|
'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* The console command description. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
protected $description = '[+] Create a new event listener class'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The type of class being generated. |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $type = 'Listener'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* The constructor. |
43
|
|
|
*/ |
44
|
8 |
|
public function __construct() |
45
|
|
|
{ |
46
|
8 |
|
parent::__construct(); |
47
|
|
|
|
48
|
8 |
|
$this->setStubDirectory(__DIR__.'/../stubs'); |
49
|
8 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Process command line arguments |
53
|
|
|
* |
54
|
|
|
* @return bool |
55
|
|
|
*/ |
56
|
6 |
|
protected function processArguments() |
57
|
|
|
{ |
58
|
6 |
|
if ($this->option('event') == null) { |
59
|
1 |
|
throw new RuntimeException('Missing required option: --event'); |
60
|
|
|
} |
61
|
|
|
|
62
|
5 |
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the default namespace for the class. |
67
|
|
|
* |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
4 |
|
protected function getDefaultNamespace() |
71
|
|
|
{ |
72
|
4 |
|
return $this->getRootNamespace().'\\Listeners'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the stub file for the generator. |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
4 |
|
protected function getStub() |
81
|
|
|
{ |
82
|
4 |
|
return $this->option('queued') ? 'listener-queued.stub' : 'listener-sync.stub'; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Generate file. |
87
|
|
|
* |
88
|
|
|
* @param \Jumilla\Generators\FileGenerator $generator |
89
|
|
|
* @param string $path |
90
|
|
|
* @param string $fqcn |
91
|
|
|
* |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
4 |
|
protected function generateFile(FileGenerator $generator, $path, $fqcn) |
95
|
|
|
{ |
96
|
4 |
|
list($namespace, $class) = $this->splitFullQualifyClassName($fqcn); |
97
|
|
|
|
98
|
4 |
|
return $generator->file($path)->template($this->getStub(), [ |
99
|
4 |
|
'namespace' => $namespace, |
100
|
4 |
|
'root_namespace' => $this->getAppNamespace(), // use App\Events\{$event} |
101
|
4 |
|
'class' => $class, |
102
|
4 |
|
'event' => $this->option('event'), |
103
|
|
|
]); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|