|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Salah3id\Domains\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Illuminate\Support\Str; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
|
|
10
|
|
|
class PublishConfigurationCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* The console command name. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $name = 'domain:publish-config'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The console command description. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $description = 'Publish a domain\'s config files to the application'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Execute the console command. |
|
28
|
|
|
*/ |
|
29
|
|
|
public function handle(): int |
|
30
|
|
|
{ |
|
31
|
|
|
$this->components->info('publishing domain config files...'); |
|
32
|
|
|
|
|
33
|
|
|
if ($domain = $this->argument('domain')) { |
|
34
|
|
|
$this->publishConfiguration($domain); |
|
35
|
|
|
|
|
36
|
|
|
return 0; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
foreach ($this->laravel['domains']->allEnabled() as $domain) { |
|
40
|
|
|
$this->publishConfiguration($domain->getName()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return 0; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param string $domain |
|
48
|
|
|
* @return string |
|
49
|
|
|
*/ |
|
50
|
|
|
private function getServiceProviderForDomain($domain) |
|
51
|
|
|
{ |
|
52
|
|
|
$namespace = $this->laravel['config']->get('domains.namespace'); |
|
53
|
|
|
$studlyName = Str::studly($domain); |
|
54
|
|
|
|
|
55
|
|
|
return "$namespace\\$studlyName\\Providers\\{$studlyName}ServiceProvider"; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param string $domain |
|
60
|
|
|
*/ |
|
61
|
|
|
private function publishConfiguration($domain) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->call('vendor:publish', [ |
|
64
|
|
|
'--provider' => $this->getServiceProviderForDomain($domain), |
|
65
|
|
|
'--force' => $this->option('force'), |
|
66
|
|
|
'--tag' => ['config'], |
|
67
|
|
|
]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get the console command arguments. |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function getArguments() |
|
76
|
|
|
{ |
|
77
|
|
|
return [ |
|
78
|
|
|
['domain', InputArgument::OPTIONAL, 'The name of domain being used.'], |
|
79
|
|
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function getOptions() |
|
86
|
|
|
{ |
|
87
|
|
|
return [ |
|
88
|
|
|
['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'], |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|