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
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
|
12
|
|
|
class CommandMakeCommand extends GeneratorCommand |
13
|
|
|
{ |
14
|
|
|
use DomainCommandTrait; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The name of argument name. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $argumentName = 'name'; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The console command name. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $name = 'domain:make-command'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The console command description. |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $description = 'Generate new Artisan command for the specified domain.'; |
36
|
|
|
|
37
|
|
|
public function getDefaultNamespace(): string |
38
|
|
|
{ |
39
|
|
|
$domain = $this->laravel['domains']; |
40
|
|
|
|
41
|
|
|
return $domain->config('paths.generator.command.namespace') ?: $domain->config('paths.generator.command.path', 'Console'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get the console command arguments. |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
|
|
protected function getArguments() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
|
|
['name', InputArgument::REQUIRED, 'The name of the command.'], |
53
|
|
|
['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the console command options. |
59
|
|
|
* |
60
|
|
|
* @return array |
61
|
|
|
*/ |
62
|
|
|
protected function getOptions() |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
['command', null, InputOption::VALUE_OPTIONAL, 'The terminal command that should be assigned.', null], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
protected function getTemplateContents() |
73
|
|
|
{ |
74
|
|
|
$domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
75
|
|
|
|
76
|
|
|
return (new Stub('/command.stub', [ |
77
|
|
|
'COMMAND_NAME' => $this->getCommandName(), |
78
|
|
|
'NAMESPACE' => $this->getClassNamespace($domain), |
79
|
|
|
'CLASS' => $this->getClass(), |
80
|
|
|
]))->render(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
private function getCommandName() |
87
|
|
|
{ |
88
|
|
|
return $this->option('command') ?: 'command:name'; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return mixed |
93
|
|
|
*/ |
94
|
|
|
protected function getDestinationFilePath() |
95
|
|
|
{ |
96
|
|
|
$path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
97
|
|
|
|
98
|
|
|
$commandPath = GenerateConfigReader::read('command'); |
99
|
|
|
|
100
|
|
|
return $path . $commandPath->getPath() . '/' . $this->getFileName() . '.php'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
private function getFileName() |
107
|
|
|
{ |
108
|
|
|
return Str::studly($this->argument('name')); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|