Skip to content

Commit f7a506e

Browse files
Adds make:config command (#56819)
* add make:config command * add registerConfigMakeCommand * Update config.stub * Update ConfigMakeCommand.php * Update ConfigMakeCommand.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 586bfaa commit f7a506e

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
namespace Illuminate\Foundation\Console;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
use Illuminate\Support\Str;
7+
use Symfony\Component\Console\Attribute\AsCommand;
8+
use Symfony\Component\Console\Input\InputOption;
9+
10+
use function Illuminate\Filesystem\join_paths;
11+
12+
#[AsCommand(name: 'make:config', aliases: ['config:make'])]
13+
class ConfigMakeCommand extends GeneratorCommand
14+
{
15+
/**
16+
* The name and signature of the console command.
17+
*
18+
* @var string
19+
*/
20+
protected $name = 'make:config';
21+
22+
/**
23+
* The console command description.
24+
*
25+
* @var string
26+
*/
27+
protected $description = 'Create a new configuration file';
28+
29+
/**
30+
* The type of file being generated.
31+
*
32+
* @var string
33+
*/
34+
protected $type = 'Config';
35+
36+
/**
37+
* The console command name aliases.
38+
*
39+
* @var array<int, string>
40+
*/
41+
protected $aliases = ['config:make'];
42+
43+
/**
44+
* Get the destination file path.
45+
*
46+
* @param string $name
47+
*/
48+
protected function getPath($name): string
49+
{
50+
return config_path(Str::finish($this->argument('name'), '.php'));
51+
}
52+
53+
/**
54+
* Get the stub file for the generator.
55+
*/
56+
protected function getStub(): string
57+
{
58+
$relativePath = join_paths('stubs', 'config.stub');
59+
60+
return file_exists($customPath = $this->laravel->basePath($relativePath))
61+
? $customPath
62+
: join_paths(__DIR__, $relativePath);
63+
}
64+
65+
/**
66+
* Get the console command arguments.
67+
*/
68+
protected function getOptions(): array
69+
{
70+
return [
71+
['force', 'f', InputOption::VALUE_NONE, 'Create the configuration file even if it already exists'],
72+
];
73+
}
74+
75+
/**
76+
* Prompt for missing input arguments using the returned questions.
77+
*
78+
* @return array
79+
*/
80+
protected function promptForMissingArgumentsUsing()
81+
{
82+
return [
83+
'name' => 'What should the configuration file be named?',
84+
];
85+
}
86+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
//
5+
];

src/Illuminate/Foundation/Providers/ArtisanServiceProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use Illuminate\Foundation\Console\ComponentMakeCommand;
4040
use Illuminate\Foundation\Console\ConfigCacheCommand;
4141
use Illuminate\Foundation\Console\ConfigClearCommand;
42+
use Illuminate\Foundation\Console\ConfigMakeCommand;
4243
use Illuminate\Foundation\Console\ConfigPublishCommand;
4344
use Illuminate\Foundation\Console\ConfigShowCommand;
4445
use Illuminate\Foundation\Console\ConsoleMakeCommand;
@@ -189,6 +190,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
189190
'ChannelMake' => ChannelMakeCommand::class,
190191
'ClassMake' => ClassMakeCommand::class,
191192
'ComponentMake' => ComponentMakeCommand::class,
193+
'ConfigMake' => ConfigMakeCommand::class,
192194
'ConfigPublish' => ConfigPublishCommand::class,
193195
'ConsoleMake' => ConsoleMakeCommand::class,
194196
'ControllerMake' => ControllerMakeCommand::class,
@@ -388,6 +390,18 @@ protected function registerConfigClearCommand()
388390
});
389391
}
390392

393+
/**
394+
* Register the command.
395+
*
396+
* @return void
397+
*/
398+
protected function registerConfigMakeCommand()
399+
{
400+
$this->app->singleton(ConfigMakeCommand::class, function ($app) {
401+
return new ConfigMakeCommand($app['files']);
402+
});
403+
}
404+
391405
/**
392406
* Register the command.
393407
*

0 commit comments

Comments
 (0)