comparison src/Generator/Requests/RequestGenerator.php @ 34:f65ab84ee47f default

merge with codex
author luka
date Wed, 10 Sep 2025 21:00:47 -0400
parents 21439512ba69
children 2cf26b593f4a
comparison
equal deleted inserted replaced
10:a9ff874afdbd 34:f65ab84ee47f
1 <?php 1 <?php
2 2
3 namespace Wizzard\MagicForger\Generator\Requests; 3 namespace Wizard\MagicForger\Generator\Requests;
4 4
5 use Symfony\Component\Console\Attribute\AsCommand; 5 use Symfony\Component\Console\Attribute\AsCommand;
6 use Symfony\Component\Console\Input\InputInterface; 6 use Symfony\Component\Console\Input\InputInterface;
7 use Symfony\Component\Console\Input\InputOption; 7 use Symfony\Component\Console\Input\InputOption;
8 use Symfony\Component\Console\Output\OutputInterface; 8 use Symfony\Component\Console\Output\OutputInterface;
9 use Wizzard\MagicForger\Generator\BaseGenerator; 9 use Wizard\MagicForger\Generator\BaseGenerator;
10 10
11 #[AsCommand(name: 'mf:request')] 11 #[AsCommand(name: 'mf:request')]
12 class RequestGenerator extends BaseGenerator 12 class RequestGenerator extends BaseGenerator
13 { 13 {
14 /** 14 /**
36 * Execute the console command. 36 * Execute the console command.
37 */ 37 */
38 public function handle() 38 public function handle()
39 { 39 {
40 // First we need to ensure that the table exists, then we can 40 // First we need to ensure that the table exists, then we can
41 if (!$this->tableExists($this->getTableInput())) { 41 if (! $this->tableExists($this->getTableInput())) {
42 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); 42 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.');
43 43
44 return false; 44 return false;
45 } 45 }
46 46
47 if ($this->option('all')) { 47 if ($this->option('all')) {
48 $this->input->setOption('filter_request', true);
48 $this->input->setOption('store_request', true); 49 $this->input->setOption('store_request', true);
49 $this->input->setOption('update_request', true); 50 $this->input->setOption('update_request', true);
51 }
52
53 if ($this->option('filter_request')) {
54 $this->createFilterRequest();
50 } 55 }
51 56
52 if ($this->option('store_request')) { 57 if ($this->option('store_request')) {
53 $this->createStoreRequest(); 58 $this->createStoreRequest();
54 } 59 }
58 } 63 }
59 } 64 }
60 65
61 /** 66 /**
62 * Get the console command options. 67 * Get the console command options.
63 *
64 * @return array
65 */ 68 */
66 protected function getOptions() 69 protected function getOptions(): array
67 { 70 {
68 return array_merge(parent::getOptions(), [ 71 return array_merge(parent::getOptions(), [
69 ['all', 'a', InputOption::VALUE_NONE, 'Generate all request classes for the table.'], 72 ['all', 'a', InputOption::VALUE_NONE, 'Generate all request classes for the table.'],
73 ['filter_request', 'i', InputOption::VALUE_NONE, 'Generate filter request class for the table.'],
70 ['store_request', 's', InputOption::VALUE_NONE, 'Generate store request class for the table.'], 74 ['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.'], 75 ['update_request', 'u', InputOption::VALUE_NONE, 'Generate update request class for the table.'],
72 ]); 76 ]);
73 } 77 }
74 78
75 /** 79 /**
76 * Interact further with the user if they were prompted for missing arguments. 80 * Interact further with the user if they were prompted for missing arguments.
77 *
78 * @return void
79 */ 81 */
80 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) 82 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void {}
81 {
82 }
83 83
84 /** 84 /**
85 * Get the stub file for the generator. 85 * Get the stub file for the generator.
86 * 86 *
87 * @return string 87 * @return string
88 */ 88 */
89 protected function getStub() 89 protected function getStub() {}
90
91 protected function createFilterRequest()
90 { 92 {
93 $this->call('mf:filter_request', ['table' => $this->getTableInput()]);
91 } 94 }
92 95
93 protected function createStoreRequest() 96 protected function createStoreRequest()
94 { 97 {
95 $this->call('mf:store_request', ['table' => $this->getTableInput()]); 98 $this->call('mf:store_request', ['table' => $this->getTableInput()]);