From 65966e3368a6730ea2437fb35682d0983f39e5c9 Mon Sep 17 00:00:00 2001 From: felipeArnold <44820260+felipeArnold@users.noreply.github.com> Date: Wed, 7 Feb 2024 14:34:22 -0300 Subject: [PATCH] Create new command EnumMakeCommand. --- .../Foundation/Console/EnumMakeCommand.php | 98 +++++++++++++++++++ .../Foundation/Console/stubs/enum.stub | 9 ++ .../Providers/ArtisanServiceProvider.php | 14 +++ 3 files changed, 121 insertions(+) create mode 100644 src/Illuminate/Foundation/Console/EnumMakeCommand.php create mode 100644 src/Illuminate/Foundation/Console/stubs/enum.stub diff --git a/src/Illuminate/Foundation/Console/EnumMakeCommand.php b/src/Illuminate/Foundation/Console/EnumMakeCommand.php new file mode 100644 index 000000000000..51dc5f083239 --- /dev/null +++ b/src/Illuminate/Foundation/Console/EnumMakeCommand.php @@ -0,0 +1,98 @@ +option('force')) { + return false; + } + + if ($this->option('test')) { + $this->createTest(); + } + } + + /** + * Create a model factory for the model. + * + * @return void + */ + protected function createTest() + { + $this->call('make:test', [ + 'name' => $this->qualifyClass($this->getNameInput()) . 'Test', + '--unit' => true, + ]); + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + return $this->resolveStubPath('/stubs/enum.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; + } + + /** + * Get the default namespace for the class. + * + * @param string $rootNamespace + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return is_dir(app_path('Enums')) ? $rootNamespace . '\\Enums' : $rootNamespace; + } +} diff --git a/src/Illuminate/Foundation/Console/stubs/enum.stub b/src/Illuminate/Foundation/Console/stubs/enum.stub new file mode 100644 index 000000000000..e0af46ef0a20 --- /dev/null +++ b/src/Illuminate/Foundation/Console/stubs/enum.stub @@ -0,0 +1,9 @@ + EnvironmentCommand::class, 'EnvironmentDecrypt' => EnvironmentDecryptCommand::class, 'EnvironmentEncrypt' => EnvironmentEncryptCommand::class, + 'EnumMake' => EnumMakeCommand::class, 'EventCache' => EventCacheCommand::class, 'EventClear' => EventClearCommand::class, 'EventList' => EventListCommand::class, @@ -394,6 +396,18 @@ protected function registerEventMakeCommand() }); } + /** + * Register the command. + * + * @return void + */ + protected function registerEnumMakeCommand() + { + $this->app->singleton(EnumMakeCommand::class, function ($app) { + return new EnumMakeCommand($app['files']); + }); + } + /** * Register the command. *