Mercurial > packages > magicforger
annotate src/Generator/Generator.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 | 1a717c7b211f |
| rev | line source |
|---|---|
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
1 <?php |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
2 |
|
19
19b7a8de0019
updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents:
13
diff
changeset
|
3 namespace Wizard\MagicForger\Generator; |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
4 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
5 use Symfony\Component\Console\Attribute\AsCommand; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
6 use Symfony\Component\Console\Input\InputInterface; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
7 use Symfony\Component\Console\Input\InputOption; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
8 use Symfony\Component\Console\Output\OutputInterface; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
9 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
10 #[AsCommand(name: 'mf')] |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
11 class Generator extends BaseGenerator |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
12 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
13 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
14 * The name and signature of the console command. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
15 * |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
16 * @var string |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
17 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
18 protected $name = 'mf'; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
19 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
20 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
21 * The console command description. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
22 * |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
23 * @var string |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
24 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
25 protected $description = 'Generates any (or all) of the available files.'; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
26 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
27 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
28 * Execute the console command. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
29 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
30 public function handle() |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
31 { |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
32 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
33 // 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
|
34 if (! $this->tableExists($this->getTableInput())) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
35 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
36 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
37 return false; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
38 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
39 |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
40 /* $this->setCurrentTable($this->getTableInput()); */ |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
41 /* dd($this->getCurrentTable()->getForeignKeys()); */ |
| 5 | 42 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
43 if ($this->option('all')) { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
44 /* $this->input->setOption('factory', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
45 /* $this->input->setOption('seed', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
46 /* $this->input->setOption('migration', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
47 $this->input->setOption('controller', true); |
| 12 | 48 $this->input->setOption('model', true); |
| 5 | 49 $this->input->setOption('request', true); |
| 50 $this->input->setOption('route', true); | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
51 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
52 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
53 /* if ($this->option('factory')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
54 /* $this->createFactory(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
55 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
56 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
57 /* if ($this->option('migration')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
58 /* $this->createMigration(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
59 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
60 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
61 /* if ($this->option('seed')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
62 /* $this->createSeeder(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
63 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
64 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
65 if ($this->option('controller')) { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
66 $this->createController(); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
67 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
68 |
| 12 | 69 if ($this->option('model')) { |
| 70 $this->createModel(); | |
| 71 } | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
72 |
| 5 | 73 if ($this->option('request')) { |
| 74 $this->createRequest(); | |
| 75 } | |
| 76 | |
| 77 if ($this->option('route')) { | |
| 78 $this->createRoute(); | |
| 79 } | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
80 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
81 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
82 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
83 * Get the console command options. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
84 */ |
|
22
ee8ef14e158d
Now able to include through composer
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
85 protected function getOptions(): array |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
86 { |
| 5 | 87 return array_merge(parent::getOptions(), [ |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
88 ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
89 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], |
| 5 | 90 ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], |
| 91 ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], | |
| 92 ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], | |
| 93 ]); | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
94 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
95 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
96 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
97 * Interact further with the user if they were prompted for missing arguments. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
98 */ |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
99 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void {} |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
100 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
101 protected function getStub(): void {} |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
102 |
|
22
ee8ef14e158d
Now able to include through composer
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
103 protected function createController(): void |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
104 { |
| 5 | 105 $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
| 106 } | |
| 107 | |
| 108 protected function createModel() | |
| 109 { | |
| 110 $this->call('mf:model', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | |
| 111 } | |
| 112 | |
| 113 protected function createRequest() | |
| 114 { | |
| 115 $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); | |
| 116 } | |
| 117 | |
| 118 protected function createRoute() | |
| 119 { | |
| 120 $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
121 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
122 } |
