Mercurial > packages > magicforger
annotate src/Generator/Requests/RequestGenerator.php @ 20:81a76472ba21 main-dev
More namespace issues
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Wed, 26 Feb 2025 19:29:55 -0500 |
| parents | 769a17898cc0 |
| children | ee8ef14e158d |
| 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 | |
| 41 if (!$this->tableExists($this->getTableInput())) { | |
| 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 * | |
| 64 * @return array | |
| 65 */ | |
| 66 protected function getOptions() | |
| 67 { | |
| 68 return array_merge(parent::getOptions(), [ | |
| 69 ['all', 'a', InputOption::VALUE_NONE, 'Generate all request classes for the table.'], | |
| 70 ['store_request', 's', InputOption::VALUE_NONE, 'Generate store request class for the table.'], | |
| 71 ['update_request', 'u', InputOption::VALUE_NONE, 'Generate update request class for the table.'], | |
| 72 ]); | |
| 73 } | |
| 74 | |
| 75 /** | |
| 76 * Interact further with the user if they were prompted for missing arguments. | |
| 77 * | |
| 78 * @return void | |
| 79 */ | |
| 80 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) | |
| 81 { | |
| 82 } | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
83 |
| 5 | 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 } |
