Mercurial > packages > magicforger
comparison src/Generator/Requests/RequestGenerator.php @ 5:b0b2e79ad8e6
Not exatly sure what was changed but commiting to it :)
| author | luka |
|---|---|
| date | Thu, 12 Oct 2023 19:41:04 -0400 |
| parents | |
| children | 769a17898cc0 |
comparison
equal
deleted
inserted
replaced
| 4:a20439b1c9d3 | 5:b0b2e79ad8e6 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Wizzard\MagicForger\Generator\Requests; | |
| 4 | |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | |
| 6 use Symfony\Component\Console\Input\InputInterface; | |
| 7 use Symfony\Component\Console\Input\InputOption; | |
| 8 use Symfony\Component\Console\Output\OutputInterface; | |
| 9 use Wizzard\MagicForger\Generator\BaseGenerator; | |
| 10 use Illuminate\Support\Str; | |
| 11 | |
| 12 #[AsCommand(name: 'mf:request')] | |
| 13 class RequestGenerator extends BaseGenerator | |
| 14 { | |
| 15 /** | |
| 16 * The name and signature of the console command. | |
| 17 * | |
| 18 * @var string | |
| 19 */ | |
| 20 protected $name = 'mf:request'; | |
| 21 | |
| 22 /** | |
| 23 * The console command description. | |
| 24 * | |
| 25 * @var string | |
| 26 */ | |
| 27 protected $description = 'Generates the Request File for a table.'; | |
| 28 | |
| 29 /** | |
| 30 * The type of class being generated. | |
| 31 * | |
| 32 * @var string | |
| 33 */ | |
| 34 protected $type = 'Request'; | |
| 35 | |
| 36 /** | |
| 37 * Execute the console command. | |
| 38 */ | |
| 39 public function handle() | |
| 40 { | |
| 41 // First we need to ensure that the table exists, then we can | |
| 42 if (!$this->tableExists($this->getTableInput())) { | |
| 43 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); | |
| 44 | |
| 45 return false; | |
| 46 } | |
| 47 | |
| 48 if ($this->option('all')) { | |
| 49 $this->input->setOption('store_request', true); | |
| 50 $this->input->setOption('update_request', true); | |
| 51 } | |
| 52 | |
| 53 if ($this->option('store_request')) { | |
| 54 $this->createStoreRequest(); | |
| 55 } | |
| 56 | |
| 57 if ($this->option('update_request')) { | |
| 58 $this->createUpdateRequest(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * Get the console command options. | |
| 64 * | |
| 65 * @return array | |
| 66 */ | |
| 67 protected function getOptions() | |
| 68 { | |
| 69 return array_merge(parent::getOptions(), [ | |
| 70 ['all', 'a', InputOption::VALUE_NONE, 'Generate all request classes for the table.'], | |
| 71 ['store_request', 's', InputOption::VALUE_NONE, 'Generate store request class for the table.'], | |
| 72 ['update_request', 'u', InputOption::VALUE_NONE, 'Generate update request class for the table.'], | |
| 73 ]); | |
| 74 } | |
| 75 | |
| 76 /** | |
| 77 * Interact further with the user if they were prompted for missing arguments. | |
| 78 * | |
| 79 * @return void | |
| 80 */ | |
| 81 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) | |
| 82 { | |
| 83 } | |
| 84 /** | |
| 85 * Get the stub file for the generator. | |
| 86 * | |
| 87 * @return string | |
| 88 */ | |
| 89 protected function getStub() | |
| 90 { | |
| 91 } | |
| 92 | |
| 93 protected function createStoreRequest() | |
| 94 { | |
| 95 $this->call('mf:store_request', ['table' => $this->getTableInput()]); | |
| 96 } | |
| 97 | |
| 98 protected function createUpdateRequest() | |
| 99 { | |
| 100 $this->call('mf:update_request', ['table' => $this->getTableInput()]); | |
| 101 } | |
| 102 | |
| 103 } |
