1 | <?php |
||
2 | |||
3 | namespace Salah3id\Domains\Commands; |
||
4 | |||
5 | use Illuminate\Support\Str; |
||
6 | use Salah3id\Domains\Support\Config\GenerateConfigReader; |
||
7 | use Salah3id\Domains\Support\Stub; |
||
8 | use Salah3id\Domains\Traits\DomainCommandTrait; |
||
9 | use Symfony\Component\Console\Input\InputArgument; |
||
10 | |||
11 | class EventMakeCommand extends GeneratorCommand |
||
12 | { |
||
13 | use DomainCommandTrait; |
||
14 | |||
15 | protected $argumentName = 'name'; |
||
16 | |||
17 | /** |
||
18 | * The console command name. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $name = 'domain:make-event'; |
||
23 | |||
24 | /** |
||
25 | * The console command description. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $description = 'Create a new event class for the specified domain'; |
||
30 | |||
31 | public function getTemplateContents() |
||
32 | { |
||
33 | $domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
||
34 | |||
35 | return (new Stub('/event.stub', [ |
||
36 | 'NAMESPACE' => $this->getClassNamespace($domain), |
||
37 | 'CLASS' => $this->getClass(), |
||
38 | ]))->render(); |
||
39 | } |
||
40 | |||
41 | public function getDestinationFilePath() |
||
42 | { |
||
43 | $path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
||
44 | |||
45 | $eventPath = GenerateConfigReader::read('event'); |
||
46 | |||
47 | return $path . $eventPath->getPath() . '/' . $this->getFileName() . '.php'; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | protected function getFileName() |
||
54 | { |
||
55 | return Str::studly($this->argument('name')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
56 | } |
||
57 | |||
58 | public function getDefaultNamespace(): string |
||
59 | { |
||
60 | $domain = $this->laravel['domains']; |
||
61 | |||
62 | return $domain->config('paths.generator.event.namespace') ?: $domain->config('paths.generator.event.path', 'Events'); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get the console command arguments. |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | protected function getArguments() |
||
71 | { |
||
72 | return [ |
||
73 | ['name', InputArgument::REQUIRED, 'The name of the event.'], |
||
74 | ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
||
75 | ]; |
||
76 | } |
||
77 | } |
||
78 |