Mercurial > packages > magicforger
annotate src/Generator/Generator.php @ 38:c062f013fd19 ls_dev_2025_09
Making test a default with the -a option
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Thu, 25 Sep 2025 20:24:13 -0400 |
| parents | 116b36f5e73b |
| children |
| 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')) { |
|
36
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
44 $this->input->setOption('factory', true); |
|
3
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); |
|
25
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
50 $this->input->setOption('view', true); |
| 5 | 51 $this->input->setOption('route', true); |
|
38
c062f013fd19
Making test a default with the -a option
Luka Sitas <sitas.luka.97@gmail.com>
parents:
37
diff
changeset
|
52 $this->input->setOption('test', true); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
53 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
54 |
|
36
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
55 if ($this->option('factory')) { |
|
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
56 $this->createFactory(); |
|
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
57 } |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
58 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
59 /* if ($this->option('migration')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
60 /* $this->createMigration(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
61 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
62 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
63 /* if ($this->option('seed')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
64 /* $this->createSeeder(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
65 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
66 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
67 if ($this->option('controller')) { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
68 $this->createController(); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
69 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
70 |
| 12 | 71 if ($this->option('model')) { |
| 72 $this->createModel(); | |
| 73 } | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
74 |
| 5 | 75 if ($this->option('request')) { |
| 76 $this->createRequest(); | |
| 77 } | |
| 78 | |
|
25
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
79 if ($this->option('view')) { |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
80 $this->createView(); |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
81 } |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
82 |
| 5 | 83 if ($this->option('route')) { |
| 84 $this->createRoute(); | |
| 85 } | |
|
37
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
86 |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
87 if ($this->option('test')) { |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
88 $this->createTest(); |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
89 } |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
90 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
91 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
92 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
93 * Get the console command options. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
94 */ |
|
22
ee8ef14e158d
Now able to include through composer
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
95 protected function getOptions(): array |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
96 { |
| 5 | 97 return array_merge(parent::getOptions(), [ |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
98 ['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
|
99 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], |
| 5 | 100 ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], |
| 101 ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], | |
|
25
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
102 ['view', '', InputOption::VALUE_NONE, 'Generate base views for the table.'], |
| 5 | 103 ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], |
|
37
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
104 ['factory', 'F', InputOption::VALUE_NONE, 'Generate base factory classes for the table.'], |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
105 ['test', 't', InputOption::VALUE_NONE, 'Generate base test classes for the table.'], |
| 5 | 106 ]); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
107 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
108 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
109 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
110 * 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
|
111 */ |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
112 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
|
113 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
22
diff
changeset
|
114 protected function getStub(): void {} |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
115 |
|
22
ee8ef14e158d
Now able to include through composer
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
116 protected function createController(): void |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
117 { |
| 5 | 118 $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
| 119 } | |
| 120 | |
| 121 protected function createModel() | |
| 122 { | |
| 123 $this->call('mf:model', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | |
| 124 } | |
| 125 | |
| 126 protected function createRequest() | |
| 127 { | |
| 128 $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); | |
| 129 } | |
| 130 | |
|
25
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
131 protected function createView() |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
132 { |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
133 $this->call('mf:view', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
134 } |
|
1a717c7b211f
added support for some basic views
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
135 |
| 5 | 136 protected function createRoute() |
| 137 { | |
| 138 $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
|
139 } |
|
36
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
140 |
|
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
141 protected function createFactory() |
|
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
142 { |
|
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
143 $this->call('mf:factory', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
|
76584181267a
Got factories working in a basic way, not sure how complex tables will handle it though
Luka Sitas <sitas.luka.97@gmail.com>
parents:
25
diff
changeset
|
144 } |
|
37
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
145 |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
146 protected function createTest() |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
147 { |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
148 $this->call('mf:test', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
|
116b36f5e73b
Adding support for tests. It's pretty basic but we can improve later.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
36
diff
changeset
|
149 } |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
150 } |
