1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules\Commands\Generators; |
4
|
|
|
|
5
|
|
|
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader; |
6
|
|
|
use Rawilk\LaravelModules\Support\Stub; |
7
|
|
|
use Rawilk\LaravelModules\Traits\ModuleCommands; |
8
|
|
|
|
9
|
|
|
class EventMakeCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
use ModuleCommands; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
protected $argumentName = 'name'; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $signature = 'module:make-event |
18
|
|
|
{name : The name of the event} |
19
|
|
|
{module? : The name of the module to create the event for} |
20
|
|
|
{--p|plain : Create a plain event}'; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $description = 'Create a new event class for the specified module.'; |
24
|
|
|
|
25
|
|
|
protected function getDefaultNamespace(): string |
26
|
|
|
{ |
27
|
|
|
/** @var \Rawilk\LaravelModules\Contracts\Repository $module */ |
28
|
|
|
$module = $this->laravel['modules']; |
29
|
|
|
|
30
|
|
|
return $module->config('paths.generator.event.namespace') ?: $module->config('paths.generator.event.path', 'Events'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function getDestinationFilePath(): string |
34
|
|
|
{ |
35
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
36
|
|
|
|
37
|
|
|
$eventPath = GenerateConfigReader::read('event'); |
38
|
|
|
|
39
|
|
|
return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function getTemplateContents(): string |
43
|
|
|
{ |
44
|
|
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
45
|
|
|
|
46
|
|
|
return (new Stub($this->getStubPath(), [ |
47
|
|
|
'NAMESPACE' => $this->getClassNamespace($module), |
48
|
|
|
'CLASS' => $this->getClass(), |
49
|
|
|
]))->render(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function getStubPath(): string |
53
|
|
|
{ |
54
|
|
|
return $this->option('plain') === true |
|
|
|
|
55
|
|
|
? '/event-plain.stub' |
56
|
|
|
: '/event.stub'; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|