From 8364deb0cfe0cf41339557f2735039ada7ec17ca Mon Sep 17 00:00:00 2001 From: ericmp Date: Fri, 19 Jan 2024 18:52:21 +0100 Subject: [PATCH 1/2] Adds make:view Artisan command --- .../Foundation/Console/EnumMakeCommand.php | 82 +++++++++++++++++++ .../Foundation/Console/stubs/enum.stub | 8 ++ 2 files changed, 90 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..4d5164199785 --- /dev/null +++ b/src/Illuminate/Foundation/Console/EnumMakeCommand.php @@ -0,0 +1,82 @@ +argument('name')); + + $name = str_replace(['\\', '.'], '/', $this->argument('name')); + + return $name; + } + + /** + * Get the stub file for the generator. + * + * @return string + */ + protected function getStub() + { + return $this->resolveStubPath( + '/stubs/enum.stub', + ); + } + + + /** + * Get the default namespace for the generator. + * + * @return string + */ + protected function getDefaultNamespace($rootNamespace) + { + return $rootNamespace . '\Enums'; + } + + protected function replaceClass($stub, $name) + { + $class = str_replace($this->getNamespace($name) . '\\', '', $name); + + return str_replace('{{enum_name}}', $class, $stub); + } +} diff --git a/src/Illuminate/Foundation/Console/stubs/enum.stub b/src/Illuminate/Foundation/Console/stubs/enum.stub new file mode 100644 index 000000000000..e81be39003aa --- /dev/null +++ b/src/Illuminate/Foundation/Console/stubs/enum.stub @@ -0,0 +1,8 @@ + Date: Fri, 19 Jan 2024 19:08:30 +0100 Subject: [PATCH 2/2] fix code style --- src/Illuminate/Foundation/Console/EnumMakeCommand.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Foundation/Console/EnumMakeCommand.php b/src/Illuminate/Foundation/Console/EnumMakeCommand.php index 4d5164199785..7c3273521f3c 100644 --- a/src/Illuminate/Foundation/Console/EnumMakeCommand.php +++ b/src/Illuminate/Foundation/Console/EnumMakeCommand.php @@ -4,11 +4,7 @@ use Illuminate\Console\Concerns\CreatesMatchingTest; use Illuminate\Console\GeneratorCommand; -use Illuminate\Foundation\Inspiring; -use Illuminate\Support\Facades\File; -use Illuminate\Support\Str; use Symfony\Component\Console\Attribute\AsCommand; -use Symfony\Component\Console\Input\InputOption; #[AsCommand(name: 'make:enum')] class EnumMakeCommand extends GeneratorCommand @@ -62,7 +58,6 @@ protected function getStub() ); } - /** * Get the default namespace for the generator. * @@ -70,12 +65,12 @@ protected function getStub() */ protected function getDefaultNamespace($rootNamespace) { - return $rootNamespace . '\Enums'; + return $rootNamespace.'\Enums'; } protected function replaceClass($stub, $name) { - $class = str_replace($this->getNamespace($name) . '\\', '', $name); + $class = str_replace($this->getNamespace($name).'\\', '', $name); return str_replace('{{enum_name}}', $class, $stub); }