From d7dfe03af26ddf4a6e2fb3e3b5ba4096f980350f Mon Sep 17 00:00:00 2001 From: Karan Datwani Date: Fri, 10 Mar 2023 18:45:24 +0530 Subject: [PATCH 1/3] add force attr --- src/Console/Commands/CrudBackpackCommand.php | 8 ++++---- src/Console/Commands/CrudControllerBackpackCommand.php | 2 +- src/Console/Commands/CrudModelBackpackCommand.php | 4 ++-- src/Console/Commands/CrudRequestBackpackCommand.php | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Console/Commands/CrudBackpackCommand.php b/src/Console/Commands/CrudBackpackCommand.php index 466d840..db6ee20 100644 --- a/src/Console/Commands/CrudBackpackCommand.php +++ b/src/Console/Commands/CrudBackpackCommand.php @@ -15,7 +15,7 @@ class CrudBackpackCommand extends BackpackCommand * @var string */ protected $signature = 'backpack:crud {name} - {--validation= : Validation type, must be request, array or field}'; + {--validation= : Validation type, must be request, array or field} {--force}'; /** * The console command description. @@ -52,14 +52,14 @@ public function handle() } // Create the CRUD Model and show output - $this->call('backpack:crud-model', ['name' => $name]); + $this->call('backpack:crud-model', ['name' => $nameTitle, '--force' => $this->option('force')]); // Create the CRUD Controller and show output - $this->call('backpack:crud-controller', ['name' => $name, '--validation' => $validation]); + $this->call('backpack:crud-controller', ['name' => $nameTitle, '--validation' => $validation, '--force' => $this->option('force')]); // Create the CRUD Request and show output if ($validation === 'request') { - $this->call('backpack:crud-request', ['name' => $name]); + $this->call('backpack:crud-request', ['name' => $nameTitle, '--force' => $this->option('force')]); } // Create the CRUD route diff --git a/src/Console/Commands/CrudControllerBackpackCommand.php b/src/Console/Commands/CrudControllerBackpackCommand.php index 60f5a56..5f41f46 100644 --- a/src/Console/Commands/CrudControllerBackpackCommand.php +++ b/src/Console/Commands/CrudControllerBackpackCommand.php @@ -22,7 +22,7 @@ class CrudControllerBackpackCommand extends BackpackCommand * @var string */ protected $signature = 'backpack:crud-controller {name} - {--validation=request : Validation type, must be request, array or field}'; + {--validation=request : Validation type, must be request, array or field} {--force}'; /** * The console command description. diff --git a/src/Console/Commands/CrudModelBackpackCommand.php b/src/Console/Commands/CrudModelBackpackCommand.php index cb000bb..99e859b 100644 --- a/src/Console/Commands/CrudModelBackpackCommand.php +++ b/src/Console/Commands/CrudModelBackpackCommand.php @@ -22,7 +22,7 @@ class CrudModelBackpackCommand extends BackpackCommand * * @var string */ - protected $signature = 'backpack:crud-model {name}'; + protected $signature = 'backpack:crud-model {name} {--force}'; /** * The console command description. @@ -69,7 +69,7 @@ public function handle() // If no model was found, we will generate the path to the location where this class file // should be written. Then, we will build the class and make the proper replacements on // the stub files so that it gets the correctly formatted namespace and class name. - if (! $existsOnApp && ! $existsOnModels) { + if ($this->option('force') || (! $existsOnApp && ! $existsOnModels)) { $this->makeDirectory($this->getPath($namespaceModels)); $this->files->put($this->getPath($namespaceModels), $this->sortImports($this->buildClass($nameTitle))); diff --git a/src/Console/Commands/CrudRequestBackpackCommand.php b/src/Console/Commands/CrudRequestBackpackCommand.php index cc5cf09..a84b848 100644 --- a/src/Console/Commands/CrudRequestBackpackCommand.php +++ b/src/Console/Commands/CrudRequestBackpackCommand.php @@ -21,7 +21,7 @@ class CrudRequestBackpackCommand extends BackpackCommand * * @var string */ - protected $signature = 'backpack:crud-request {name}'; + protected $signature = 'backpack:crud-request {name} {--force}'; /** * The console command description. From 6f3bdbf33174676a5aefcd612c27bfc1eadf95ac Mon Sep 17 00:00:00 2001 From: Karan Datwani Date: Wed, 15 Mar 2023 14:35:25 +0530 Subject: [PATCH 2/3] deprecated commands call updated commands --- src/Console/Commands/ModelBackpackCommand.php | 66 ++----------------- .../Commands/RequestBackpackCommand.php | 31 ++------- 2 files changed, 14 insertions(+), 83 deletions(-) diff --git a/src/Console/Commands/ModelBackpackCommand.php b/src/Console/Commands/ModelBackpackCommand.php index 942a8b8..9121584 100644 --- a/src/Console/Commands/ModelBackpackCommand.php +++ b/src/Console/Commands/ModelBackpackCommand.php @@ -2,10 +2,10 @@ namespace Backpack\Generators\Console\Commands; -use Illuminate\Console\GeneratorCommand; +use Illuminate\Console\Command; use Illuminate\Support\Str; -class ModelBackpackCommand extends GeneratorCommand +class ModelBackpackCommand extends Command { /** * The console command name. @@ -19,7 +19,7 @@ class ModelBackpackCommand extends GeneratorCommand * * @var string */ - protected $signature = 'backpack:model {name} {--softdelete}'; + protected $signature = 'backpack:model {name} {--force}'; /** * The console command description. @@ -29,65 +29,13 @@ class ModelBackpackCommand extends GeneratorCommand protected $description = 'Generate a backpack templated model'; /** - * The type of class being generated. + * Execute the console command. * - * @var string - */ - protected $type = 'Model'; - - /** - * Get the stub file for the generator. - * - * @return string - */ - protected function getStub() - { - if ($this->option('softdelete')) { - return __DIR__.'/../stubs/model-softdelete.stub'; - } - - return __DIR__.'/../stubs/model.stub'; - } - - /** - * Get the default namespace for the class. + * @return bool|null * - * @param string $rootNamespace - * @return string */ - protected function getDefaultNamespace($rootNamespace) + public function handle() { - return $rootNamespace.'\Models'; - } - - /** - * Replace the table name for the given stub. - * - * @param string $stub - * @param string $name - * @return string - */ - protected function replaceTable(&$stub, $name) - { - $name = ltrim(strtolower(preg_replace('/[A-Z]/', '_$0', str_replace($this->getNamespace($name).'\\', '', $name))), '_'); - - $table = Str::snake(Str::plural($name)); - - $stub = str_replace('DummyTable', $table, $stub); - - return $this; - } - - /** - * Build the class with the given name. - * - * @param string $name - * @return string - */ - protected function buildClass($name) - { - $stub = $this->files->get($this->getStub()); - - return $this->replaceNamespace($stub, $name)->replaceTable($stub, $name)->replaceClass($stub, $name); + $this->call('backpack:crud-model', ['name' => $this->argument('name'), '--force' => $this->option('force')]); } } diff --git a/src/Console/Commands/RequestBackpackCommand.php b/src/Console/Commands/RequestBackpackCommand.php index 89e1637..65b493c 100644 --- a/src/Console/Commands/RequestBackpackCommand.php +++ b/src/Console/Commands/RequestBackpackCommand.php @@ -2,9 +2,9 @@ namespace Backpack\Generators\Console\Commands; -use Illuminate\Console\GeneratorCommand; +use Illuminate\Console\Command; -class RequestBackpackCommand extends GeneratorCommand +class RequestBackpackCommand extends Command { /** * The console command name. @@ -18,7 +18,7 @@ class RequestBackpackCommand extends GeneratorCommand * * @var string */ - protected $signature = 'backpack:request {name}'; + protected $signature = 'backpack:request {name} {--force}'; /** * The console command description. @@ -28,30 +28,13 @@ class RequestBackpackCommand extends GeneratorCommand protected $description = 'Generate a backpack templated request'; /** - * The type of class being generated. + * Execute the console command. * - * @var string - */ - protected $type = 'Request'; - - /** - * Get the stub file for the generator. - * - * @return string - */ - protected function getStub() - { - return __DIR__.'/../stubs/request.stub'; - } - - /** - * Get the default namespace for the class. + * @return bool|null * - * @param string $rootNamespace - * @return string */ - protected function getDefaultNamespace($rootNamespace) + public function handle() { - return $rootNamespace.'\Http\Requests'; + $this->call('backpack:crud-request', ['name' => $this->argument('name'), '--force' => $this->option('force')]); } } From 207d4d260b020c2d413c0396ab2169d6f0602239 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Wed, 15 Mar 2023 09:32:57 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI --- src/Console/Commands/ModelBackpackCommand.php | 2 -- src/Console/Commands/RequestBackpackCommand.php | 1 - 2 files changed, 3 deletions(-) diff --git a/src/Console/Commands/ModelBackpackCommand.php b/src/Console/Commands/ModelBackpackCommand.php index 9121584..57cf640 100644 --- a/src/Console/Commands/ModelBackpackCommand.php +++ b/src/Console/Commands/ModelBackpackCommand.php @@ -3,7 +3,6 @@ namespace Backpack\Generators\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Support\Str; class ModelBackpackCommand extends Command { @@ -32,7 +31,6 @@ class ModelBackpackCommand extends Command * Execute the console command. * * @return bool|null - * */ public function handle() { diff --git a/src/Console/Commands/RequestBackpackCommand.php b/src/Console/Commands/RequestBackpackCommand.php index 65b493c..07936a1 100644 --- a/src/Console/Commands/RequestBackpackCommand.php +++ b/src/Console/Commands/RequestBackpackCommand.php @@ -31,7 +31,6 @@ class RequestBackpackCommand extends Command * Execute the console command. * * @return bool|null - * */ public function handle() {