Mercurial > packages > magicforger
annotate src/Generator/BaseGenerator.php @ 26:555bfaa500ac codex
Big update for view creation based on the column type.
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Thu, 15 May 2025 21:50:38 -0400 |
| parents | 827efbf4d73c |
| children |
| rev | line source |
|---|---|
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
1 <?php |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
2 |
|
19
19b7a8de0019
updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents:
9
diff
changeset
|
3 namespace Wizard\MagicForger\Generator; |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
4 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
5 use Illuminate\Console\GeneratorCommand; |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
6 use Illuminate\Support\Facades\Schema; |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
7 use Symfony\Component\Console\Input\InputInterface; |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
8 use Symfony\Component\Console\Input\InputOption; |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
9 use Symfony\Component\Console\Output\OutputInterface; |
|
19
19b7a8de0019
updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents:
9
diff
changeset
|
10 use Wizard\MagicForger\Replacer\Replacer; |
|
19b7a8de0019
updating namespace from typo
Luka Sitas <sitas.luka.97@gmail.com>
parents:
9
diff
changeset
|
11 use Wizard\MagicForger\Replacer\TableReplacer; |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
12 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
13 abstract class BaseGenerator extends GeneratorCommand |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
14 { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
15 use Replacer; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
16 use TableReplacer; |
| 2 | 17 |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
18 protected $schema = null; |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
19 |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
20 protected $tables = null; |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
21 |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
22 protected $currentTable = null; |
| 5 | 23 |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
24 protected static $cached_snippets = []; |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
25 |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
26 public function handle() |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
27 { |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
28 |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
29 if (! $this->tableExists($this->getTableInput())) { |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
30 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
31 |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
32 return false; |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
33 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
34 |
| 9 | 35 $this->setCurrentTable($this->getTableInput()); |
| 4 | 36 $path = $this->getPath(); |
| 37 $file = $this->getFile($path); | |
| 38 $file = $this->apply_replacements($file); | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
39 $file = $this->apply_inserts($file); |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
40 $this->makeDirectory($path); |
| 4 | 41 $this->files->put($path, $this->sortImports($file)); |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
42 $this->format_file($path); |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
43 $this->components->info(sprintf('%s [%s] created successfully.', $this->type, $path)); |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
44 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
45 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
46 protected function promptForMissingArguments(InputInterface $input, OutputInterface $output): void |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
47 { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
48 $prompted = false; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
49 if (is_null($input->getArgument('table'))) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
50 $prompted = true; |
| 2 | 51 $table = null; |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
52 while ($table === null) { |
| 2 | 53 $table = $this->components->askWithCompletion( |
| 54 'What Table should we use?', | |
| 55 $this->possibleTables() | |
| 56 ); | |
| 57 } | |
| 58 $input->setArgument('table', $table); | |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
59 } |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
60 |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
61 parent::promptForMissingArguments($input, $output); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
62 |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
63 if ($prompted) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
64 $this->afterPromptingForMissingArguments($input, $output); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
65 } |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
66 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
67 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
68 protected function getArguments(): array |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
69 { |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
70 return [ |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
71 ['table', InputOption::VALUE_REQUIRED, 'The table to generate files for.'], |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
72 ]; |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
73 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
74 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
75 protected function promptForMissingArgumentsUsing(): array |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
76 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
77 return []; |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
78 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
79 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
80 protected function getOptions(): array |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
81 { |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
82 return [ |
| 4 | 83 ['fresh', 'f', InputOption::VALUE_NONE, 'Start from the stub or use existing if possible.'], |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
84 ]; |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
85 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
86 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
87 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
88 { |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
89 // Additional logic after prompting goes here |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
90 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
91 |
| 4 | 92 protected function fileExists(string $path): bool |
| 93 { | |
| 94 return $this->files->exists($path); | |
| 95 } | |
| 96 | |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
97 protected function getFile($name): string |
| 2 | 98 { |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
99 if (! ($this->hasOption('fresh') && $this->option('fresh')) && $this->fileExists($name)) { |
| 4 | 100 return $this->files->get($name); |
| 2 | 101 } |
| 102 | |
| 103 return $this->files->get($this->getStub()); | |
| 104 } | |
| 105 | |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
106 protected function getTableInput(): string |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
107 { |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
108 return trim($this->argument('table')); |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
109 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
110 |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
111 protected function tableExists(string $table_name): bool |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
112 { |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
113 return in_array($table_name, $this->getTables()); |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
114 } |
|
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
115 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
116 protected function possibleTables(): array |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
117 { |
| 2 | 118 return $this->getTables(); |
| 119 } | |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
120 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
121 protected function getTables(): array |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
122 { |
| 2 | 123 if (is_null($this->tables)) { |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
124 $this->tables = Schema::getTableListing(schema: config('database.connections.mariadb.database'), schemaQualified: false); |
| 2 | 125 } |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
126 |
| 2 | 127 return $this->tables; |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
128 } |
| 5 | 129 |
| 130 protected function getTable(string $table_name) | |
| 131 { | |
| 132 return $this->getSchema()->introspectTable($table_name); | |
| 133 } | |
| 134 | |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
135 /* |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
136 * returns array of columns in the form of: |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
137 * |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
138 [ |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
139 "name" => "column_type" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
140 "type_name" => "bigint" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
141 "type" => "bigint(20) unsigned" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
142 "collation" => null |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
143 "nullable" => true |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
144 "default" => "NULL" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
145 "auto_increment" => false |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
146 "comment" => null |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
147 "generation" => null |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
148 ] |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
149 */ |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
150 protected static function getTableColumns(string $table_name) |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
151 { |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
152 return Schema::getColumns($table_name); |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
153 } |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
154 |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
155 /* |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
156 * returns array of foreign keys in the form of: |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
157 * |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
158 [ |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
159 "name" => "foreign_key_name" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
160 "columns" => [ |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
161 0 => "local_column_name" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
162 ] |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
163 "foreign_schema" => "schema_name" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
164 "foreign_table" => "foreign_table_name" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
165 "foreign_columns" => [ |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
166 0 => "foreign_column_name" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
167 ] |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
168 "on_update" => "restrict" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
169 "on_delete" => "restrict" |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
170 ] |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
171 * |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
172 */ |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
173 protected static function getTableForeignKeys(string $table_name) |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
174 { |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
175 return Schema::getForeignKeys($table_name); |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
176 } |
|
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
177 |
| 5 | 178 protected function getCurrentTable() |
| 179 { | |
| 180 return $this->currentTable; | |
| 181 } | |
| 182 | |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
183 protected function setCurrentTable(string $table_name): void |
| 5 | 184 { |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
185 $this->currentTable = $table_name; |
| 5 | 186 } |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
187 |
|
21
f0b0d014e448
Cleaning up code based on AI overlord review
Luka Sitas <sitas.luka.97@gmail.com>
parents:
19
diff
changeset
|
188 protected function format_file(string $path): void |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
189 { |
|
23
827efbf4d73c
Huge changes to the relationships for models and more complex
Luka Sitas <sitas.luka.97@gmail.com>
parents:
21
diff
changeset
|
190 exec('./vendor/bin/pint '.escapeshellarg($path)); |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
191 } |
|
26
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
192 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
193 protected function getSnippet($snippet_name) |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
194 { |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
195 // Cache snippet contents to avoid re-reading files |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
196 if (! isset(self::$cached_snippets[$snippet_name])) { |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
197 self::$cached_snippets[$snippet_name] = $this->files->get( |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
198 $this->resolveStubPath("/snippets/$snippet_name.stub")); |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
199 } |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
200 |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
201 return self::$cached_snippets[$snippet_name]; |
|
555bfaa500ac
Big update for view creation based on the column type.
Luka Sitas <sitas.luka.97@gmail.com>
parents:
23
diff
changeset
|
202 } |
|
1
ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff
changeset
|
203 } |
