Mercurial > packages > magicforger
annotate src/Generator/Requests/RequestGenerator.php @ 23:827efbf4d73c main-dev
Huge changes to the relationships for models and more complex
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Fri, 11 Apr 2025 20:50:20 -0400 |
| parents | ee8ef14e158d |
| children | 010ace248d14 |
| rev | line source |
|---|---|
| 5 | 1 <?php |
| 2 | |
| 20 | 3 namespace Wizard\MagicForger\Generator\Requests; |
| 5 | 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; | |
| 20 | 9 use Wizard\MagicForger\Generator\BaseGenerator; |
| 5 | 10 |
| 11 #[AsCommand(name: 'mf:request')] | |
| 12 class RequestGenerator extends BaseGenerator | |
| 13 { | |
| 14 /** | |
| 15 * The name and signature of the console command. | |
| 16 * | |
| 17 * @var string | |
| 18 */ | |
| 19 protected $name = 'mf:request'; | |
| 20 | |
| 21 /** | |
| 22 * The console command description. | |
| 23 * | |
| 24 * @var string | |
| 25 */ | |
| 26 protected $description = 'Generates the Request File for a table.'; | |
| 27 | |
| 28 /** | |
| 29 * The type of class being generated. | |
| 30 * | |
| 31 * @var string | |
| 32 */ | |
| 33 protected $type = 'Request'; | |
| 34 | |
| 35 /** | |
| 36 * Execute the console command. | |
| 37 */ | |
| 38 public function handle() | |
| 39 { | |
| 40 // First we need to ensure that the table exists, then we can | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
41 if (! $this->tableExists($this->getTableInput())) { |
| 5 | 42 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
| 43 | |
| 44 return false; | |
| 45 } | |
| 46 | |
| 47 if ($this->option('all')) { | |
| 48 $this->input->setOption('store_request', true); | |
| 49 $this->input->setOption('update_request', true); | |
| 50 } | |
| 51 | |
| 52 if ($this->option('store_request')) { | |
| 53 $this->createStoreRequest(); | |
| 54 } | |
| 55 | |
| 56 if ($this->option('update_request')) { | |
| 57 $this->createUpdateRequest(); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 /** | |
| 62 * Get the console command options. | |
| 63 */ | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
64 protected function getOptions(): array |
| 5 | 65 { |
| 66 return array_merge(parent::getOptions(), [ | |
| 67 ['all', 'a', InputOption::VALUE_NONE, 'Generate all request classes for the table.'], | |
| 68 ['store_request', 's', InputOption::VALUE_NONE, 'Generate store request class for the table.'], | |
| 69 ['update_request', 'u', InputOption::VALUE_NONE, 'Generate update request class for the table.'], | |
| 70 ]); | |
| 71 } | |
| 72 | |
| 73 /** | |
| 74 * Interact further with the user if they were prompted for missing arguments. | |
| 75 */ | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
76 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void {} |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
77 |
| 5 | 78 /** |
| 79 * Get the stub file for the generator. | |
| 80 * | |
| 81 * @return string | |
| 82 */ | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
83 protected function getStub() {} |
| 5 | 84 |
| 85 protected function createStoreRequest() | |
| 86 { | |
| 87 $this->call('mf:store_request', ['table' => $this->getTableInput()]); | |
| 88 } | |
| 89 | |
| 90 protected function createUpdateRequest() | |
| 91 { | |
| 92 $this->call('mf:update_request', ['table' => $this->getTableInput()]); | |
| 93 } | |
| 94 } |
