From 268b3ff0fea9a32f9bca11e160ae5d05940d4022 Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 00:13:05 +0300 Subject: [PATCH 1/7] Created make:config command and registered --- .../Foundation/Console/ConfigMakeCommand.php | 63 +++++++++++++++++++ .../Foundation/Console/stubs/config.stub | 14 +++++ .../Providers/ArtisanServiceProvider.php | 14 +++++ 3 files changed, 91 insertions(+) create mode 100644 src/Illuminate/Foundation/Console/ConfigMakeCommand.php create mode 100644 src/Illuminate/Foundation/Console/stubs/config.stub diff --git a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php new file mode 100644 index 000000000000..89531b612a48 --- /dev/null +++ b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php @@ -0,0 +1,63 @@ +resolveStubPath('/stubs/config.stub'); + } + + /** + * Resolve the fully-qualified path to the stub. + * + * @param string $stub + * @return string + */ + protected function resolveStubPath($stub) + { + return file_exists($customPath = $this->laravel->basePath(trim($stub, '/'))) + ? $customPath + : __DIR__.$stub; + } + + protected function getPath($name) + { + return $this->laravel['path.config'].'/'.$this->argument('name').'.php'; + } +} diff --git a/src/Illuminate/Foundation/Console/stubs/config.stub b/src/Illuminate/Foundation/Console/stubs/config.stub new file mode 100644 index 000000000000..6f2e4330d3e3 --- /dev/null +++ b/src/Illuminate/Foundation/Console/stubs/config.stub @@ -0,0 +1,14 @@ + CastMakeCommand::class, 'ChannelMake' => ChannelMakeCommand::class, 'ComponentMake' => ComponentMakeCommand::class, + 'ConfigMake' => ConfigMakeCommand::class, 'ConsoleMake' => ConsoleMakeCommand::class, 'ControllerMake' => ControllerMakeCommand::class, 'Docs' => DocsCommand::class, @@ -340,6 +342,18 @@ protected function registerConfigClearCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerConfigMakeCommand() + { + $this->app->singleton(ConfigMakeCommand::class, function ($app) { + return new ConfigMakeCommand($app['files']); + }); + } + /** * Register the command. * From d1fa38cfea1d99da80abb7b8525d543c533e92f5 Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 00:26:09 +0300 Subject: [PATCH 2/7] creating a config file will clear the config cache --- .../Foundation/Console/ConfigMakeCommand.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php index 89531b612a48..58575c45c225 100644 --- a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php @@ -5,6 +5,7 @@ use Illuminate\Console\GeneratorCommand; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Input\InputOption; #[AsCommand(name: 'make:config')] class ConfigMakeCommand extends GeneratorCommand @@ -35,6 +36,20 @@ class ConfigMakeCommand extends GeneratorCommand */ protected $description = 'Create a new config file'; + /** + * Execute the console command. + * + * @return void + */ + public function handle() + { + if (parent::handle() === false && ! $this->option('force')) { + return; + } + + $this->call('cache:clear'); + } + /** * @inheritDoc */ From cc7f69f5b8818524649feb9d124e65cedf96b22c Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 00:36:11 +0300 Subject: [PATCH 3/7] added CreatesMatchingTest trait to ConfigMakeCommand for testing --- src/Illuminate/Foundation/Console/ConfigMakeCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php index 58575c45c225..58e31144d2ca 100644 --- a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php @@ -2,6 +2,7 @@ namespace Illuminate\Foundation\Console; +use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Console\GeneratorCommand; use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; @@ -10,6 +11,7 @@ #[AsCommand(name: 'make:config')] class ConfigMakeCommand extends GeneratorCommand { + use CreatesMatchingTest; /** * The console command name. From 5c94e9754bab0c285092627c4657764f691409e8 Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 00:54:24 +0300 Subject: [PATCH 4/7] style.ci checks --- src/Illuminate/Foundation/Console/ConfigMakeCommand.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php index 58e31144d2ca..a874e381b9c3 100644 --- a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php @@ -4,9 +4,7 @@ use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Console\GeneratorCommand; -use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; -use Symfony\Component\Console\Input\InputOption; #[AsCommand(name: 'make:config')] class ConfigMakeCommand extends GeneratorCommand From 3832101cffb57c86f3bade1b4fb13b8b1b7a010d Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 01:16:24 +0300 Subject: [PATCH 5/7] description changed from stub --- src/Illuminate/Foundation/Console/stubs/config.stub | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/stubs/config.stub b/src/Illuminate/Foundation/Console/stubs/config.stub index 6f2e4330d3e3..badc965e69d7 100644 --- a/src/Illuminate/Foundation/Console/stubs/config.stub +++ b/src/Illuminate/Foundation/Console/stubs/config.stub @@ -7,7 +7,7 @@ return [ | {{ class }} Config File |-------------------------------------------------------------------------- | - | This file is for storing the credentials of the {{ class }} application + | This file is for storing the configurable of {{ class }} | */ From 7557ba0c37c18ba61694f88bbc213ae1ca348e2d Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 10:53:31 +0300 Subject: [PATCH 6/7] config cache clearing is optional. --- .../Foundation/Console/ConfigMakeCommand.php | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php index a874e381b9c3..381987208102 100644 --- a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php @@ -5,6 +5,7 @@ use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Console\GeneratorCommand; use Symfony\Component\Console\Attribute\AsCommand; +use Symfony\Component\Console\Input\InputOption; #[AsCommand(name: 'make:config')] class ConfigMakeCommand extends GeneratorCommand @@ -43,15 +44,18 @@ class ConfigMakeCommand extends GeneratorCommand */ public function handle() { - if (parent::handle() === false && ! $this->option('force')) { + if (parent::handle() === false) { return; } - $this->call('cache:clear'); + if ($this->option('clear-config')) + $this->call('config:clear'); } /** - * @inheritDoc + * Get the stub file for the generator. + * + * @return string */ protected function getStub() { @@ -71,8 +75,26 @@ protected function resolveStubPath($stub) : __DIR__.$stub; } + /** + * Get the destination class path. + * + * @param string $name + * @return string + */ protected function getPath($name) { return $this->laravel['path.config'].'/'.$this->argument('name').'.php'; } + + /** + * Get the console command arguments. + * + * @return array + */ + protected function getOptions() + { + return [ + ['clear-config', 'c', InputOption::VALUE_NONE, 'Clear the config cache after creating the config file.'], + ]; + } } From cdf116f796ae5b19d97be49514814486cd7a744d Mon Sep 17 00:00:00 2001 From: aknEvrnky Date: Sun, 31 Jul 2022 11:03:34 +0300 Subject: [PATCH 7/7] styleCI edits --- src/Illuminate/Foundation/Console/ConfigMakeCommand.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php index 381987208102..644f9c2b5f4e 100644 --- a/src/Illuminate/Foundation/Console/ConfigMakeCommand.php +++ b/src/Illuminate/Foundation/Console/ConfigMakeCommand.php @@ -48,8 +48,9 @@ public function handle() return; } - if ($this->option('clear-config')) + if ($this->option('clear-config')) { $this->call('config:clear'); + } } /**