rawilk /
laravel-modules
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Rawilk\LaravelModules\Commands\Other; |
||
| 4 | |||
| 5 | use Illuminate\Console\Command; |
||
| 6 | use Illuminate\Support\Str; |
||
| 7 | |||
| 8 | class PublishConfigurationCommand extends Command |
||
| 9 | { |
||
| 10 | /** @var string */ |
||
| 11 | protected $signature = 'module:publish-config |
||
| 12 | {module? : The module to publish the config files for} |
||
| 13 | {--f|force : Force the publishing of config files}'; |
||
| 14 | |||
| 15 | /** @var string */ |
||
| 16 | protected $description = 'Publish the config files for a module.'; |
||
| 17 | |||
| 18 | public function handle(): void |
||
| 19 | { |
||
| 20 | if ($module = $this->argument('module')) { |
||
| 21 | $this->publishConfiguration($module); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 22 | |||
| 23 | return; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** @var \Rawilk\LaravelModules\Module $module */ |
||
| 27 | foreach ($this->laravel['modules']->allEnabled() as $module) { |
||
| 28 | $this->publishConfiguration($module->getName()); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | private function getServiceProviderForModule(string $name): string |
||
| 33 | { |
||
| 34 | $namespace = $this->laravel['config']->get('modules.namespace'); |
||
| 35 | $studlyName = Str::studly($name); |
||
| 36 | |||
| 37 | return "{$namespace}\\$studlyName\\Providers\\{$studlyName}ServiceProvider"; |
||
| 38 | } |
||
| 39 | |||
| 40 | private function publishConfiguration(string $module): void |
||
| 41 | { |
||
| 42 | $this->call('vendor:publish', [ |
||
| 43 | '--provider' => $this->getServiceProviderForModule($module), |
||
| 44 | '--force' => $this->option('force'), |
||
| 45 | '--tag' => ['config'] |
||
| 46 | ]); |
||
| 47 | } |
||
| 48 | } |
||
| 49 |