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