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 RequestMakeCommand extends GeneratorCommand |
||
12 | { |
||
13 | use DomainCommandTrait; |
||
14 | |||
15 | /** |
||
16 | * The name of argument name. |
||
17 | * |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $argumentName = 'name'; |
||
21 | |||
22 | /** |
||
23 | * The console command name. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $name = 'domain:make-request'; |
||
28 | |||
29 | /** |
||
30 | * The console command description. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $description = 'Create a new form request class for the specified domain.'; |
||
35 | |||
36 | public function getDefaultNamespace(): string |
||
37 | { |
||
38 | $domain = $this->laravel['domains']; |
||
39 | |||
40 | return $domain->config('paths.generator.request.namespace') ?: $domain->config('paths.generator.request.path', 'Http/Requests'); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get the console command arguments. |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | protected function getArguments() |
||
49 | { |
||
50 | return [ |
||
51 | ['name', InputArgument::REQUIRED, 'The name of the form request class.'], |
||
52 | ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
||
53 | ]; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return mixed |
||
58 | */ |
||
59 | protected function getTemplateContents() |
||
60 | { |
||
61 | $domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
||
62 | |||
63 | return (new Stub('/request.stub', [ |
||
64 | 'NAMESPACE' => $this->getClassNamespace($domain), |
||
65 | 'CLASS' => $this->getClass(), |
||
66 | ]))->render(); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @return mixed |
||
71 | */ |
||
72 | protected function getDestinationFilePath() |
||
73 | { |
||
74 | $path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
||
75 | |||
76 | $requestPath = GenerateConfigReader::read('request'); |
||
77 | |||
78 | return $path . $requestPath->getPath() . '/' . $this->getFileName() . '.php'; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | private function getFileName() |
||
85 | { |
||
86 | return Str::studly($this->argument('name')); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
87 | } |
||
88 | } |
||
89 |