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
|
|
View Code Duplication |
public function handle() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
if ($module = $this->argument('module')) { |
31
|
|
|
$this->publishConfiguration($module); |
|
|
|
|
32
|
|
|
|
33
|
|
|
return; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
foreach ($this->laravel['modules']->enabled() as $module) { |
37
|
|
|
$this->publishConfiguration($module->getName()); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param string $module |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
|
|
private function getServiceProviderForModule($module) |
46
|
|
|
{ |
47
|
|
|
$namespace = $this->laravel['config']->get('modules.namespace'); |
48
|
|
|
$studlyName = studly_case($module); |
49
|
|
|
|
50
|
|
|
return "$namespace\\$studlyName\\Providers\\{$studlyName}ServiceProvider"; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $module |
55
|
|
|
*/ |
56
|
|
|
private function publishConfiguration($module) |
57
|
|
|
{ |
58
|
|
|
$this->call('vendor:publish', [ |
59
|
|
|
'--provider' => $this->getServiceProviderForModule($module), |
60
|
|
|
'--force' => $this->option('force'), |
61
|
|
|
'--tag' => ['config'], |
62
|
|
|
]); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Get the console command arguments. |
67
|
|
|
* |
68
|
|
|
* @return array |
69
|
|
|
*/ |
70
|
56 |
|
protected function getArguments() |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
56 |
|
['module', InputArgument::OPTIONAL, 'The name of module being used.'], |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
56 |
|
protected function getOptions() |
81
|
|
|
{ |
82
|
|
|
return [ |
83
|
56 |
|
['--force', '-f', InputOption::VALUE_NONE, 'Force the publishing of config files'], |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.