|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
8
|
|
|
|
|
9
|
|
|
class PublishConfigurationCommand extends Command |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* The console command name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name = 'module:publish-config'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Publish a module\'s config files to the application'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Execute the console command. |
|
27
|
|
|
* |
|
28
|
|
|
* @return mixed |
|
29
|
|
|
*/ |
|
30
|
|
|
public function fire() |
|
31
|
|
|
{ |
|
32
|
|
|
if ($module = $this->argument('module')) { |
|
33
|
|
|
$this->publishConfiguration($module); |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
return; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
foreach ($this->laravel['modules']->enabled() as $module) { |
|
39
|
|
|
$this->publishConfiguration($module->getName()); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param string $module |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
private function getServiceProviderForModule($module) |
|
48
|
|
|
{ |
|
49
|
|
|
$namespace = $this->laravel['config']->get('modules.namespace'); |
|
50
|
|
|
$studlyName = studly_case($module); |
|
51
|
|
|
|
|
52
|
|
|
return "$namespace\\$studlyName\\Providers\\{$studlyName}ServiceProvider"; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $module |
|
57
|
|
|
*/ |
|
58
|
|
|
private function publishConfiguration($module) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->call('vendor:publish', [ |
|
61
|
|
|
'--provider' => $this->getServiceProviderForModule($module), |
|
62
|
|
|
'--force' => $this->option('force'), |
|
63
|
|
|
'--tag' => ['config'], |
|
64
|
|
|
]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Get the console command arguments. |
|
69
|
|
|
* |
|
70
|
|
|
* @return array |
|
71
|
|
|
*/ |
|
72
|
43 |
|
protected function getArguments() |
|
73
|
|
|
{ |
|
74
|
|
|
return [ |
|
75
|
43 |
|
['module', InputArgument::OPTIONAL, 'The name of module being used.'], |
|
76
|
|
|
]; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
43 |
|
protected function getOptions() |
|
83
|
|
|
{ |
|
84
|
|
|
return [ |
|
85
|
43 |
|
['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'], |
|
86
|
|
|
]; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.