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