Mercurial > packages > magicforger
annotate src/Generator/BaseGenerator.php @ 9:d4730c14806d
Small changes to config generation and table name input
| author | luka |
|---|---|
| date | Sat, 02 Dec 2023 10:18:52 -0500 |
| parents | 769a17898cc0 |
| children | 19b7a8de0019 |
| 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 |
|
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
|
3 namespace Wizzard\MagicForger\Generator; |
|
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 |
|
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
|
5 use DB; |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
6 use Illuminate\Console\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
|
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; |
| 5 | 10 use Wizzard\MagicForger\Replacer\Replacer; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
11 use Wizzard\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 |
| 18 /** | |
| 5 | 19 * The schema of the database. |
| 2 | 20 * |
| 21 * @var string | |
| 22 */ | |
| 23 protected $schema; | |
| 24 | |
| 25 /** | |
| 5 | 26 * The tables available in the schema. |
| 2 | 27 * |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
28 * @var array |
| 2 | 29 */ |
| 30 protected $tables; | |
| 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 /** |
| 5 | 33 * The current Table being used. |
| 34 * | |
| 35 * @var table | |
| 36 */ | |
| 37 protected $currentTable; | |
| 38 | |
| 39 /** | |
|
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 * Execute the console command. |
|
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
|
41 */ |
|
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
|
42 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
|
43 { |
|
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 // First we need to ensure that the table exists, then we can |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
45 if (!$this->tableExists($this->getTableInput())) { |
|
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
|
46 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
|
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 |
|
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
|
48 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
|
49 } |
|
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
|
50 |
| 9 | 51 $this->setCurrentTable($this->getTableInput()); |
| 52 | |
| 4 | 53 $path = $this->getPath(); |
|
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
|
54 |
| 4 | 55 $file = $this->getFile($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
|
56 |
| 4 | 57 $file = $this->apply_replacements($file); |
| 58 | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
59 $file = $this->apply_inserts($file); |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
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 $this->makeDirectory($path); |
|
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
|
62 |
| 4 | 63 $this->files->put($path, $this->sortImports($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
|
64 |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
65 $this->format_file($path); |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
66 |
|
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
|
67 $info = $this->type; |
|
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
|
68 |
|
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 $this->components->info(sprintf('%s [%s] created successfully.', $info, $path)); |
|
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 } |
|
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 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
72 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
73 * Override the original so that we can prompt for a table with autocomplete. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
74 */ |
|
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
|
75 protected function promptForMissingArguments(InputInterface $input, OutputInterface $output) |
|
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 { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
77 $prompted = false; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
78 if (is_null($input->getArgument('table'))) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
79 $prompted = true; |
| 2 | 80 $table = null; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
81 while (null === $table) { |
| 2 | 82 $table = $this->components->askWithCompletion( |
| 83 'What Table should we use?', | |
| 84 $this->possibleTables() | |
| 85 ); | |
| 86 } | |
| 87 | |
| 88 $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
|
89 } |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
90 |
|
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
|
91 parent::promptForMissingArguments($input, $output); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
92 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
93 // This will get missed if we prompt here but not in the parent |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
94 if ($prompted) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
95 $this->afterPromptingForMissingArguments($input, $output); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
96 } |
|
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
|
97 } |
|
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
|
98 |
|
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
|
99 /** |
|
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
|
100 * Get the console command arguments. |
|
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
|
101 * |
|
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
|
102 * @return array |
|
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
|
103 */ |
|
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
|
104 protected function getArguments() |
|
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
|
105 { |
|
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
|
106 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
|
107 ['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
|
108 ]; |
|
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 /** |
|
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 * Prompt for missing input arguments using the returned questions. |
|
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 * |
|
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 * @return array |
|
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 */ |
|
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
|
116 protected function promptForMissingArgumentsUsing() |
|
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 { |
|
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
|
118 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
|
119 ]; |
|
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 } |
|
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
|
121 |
|
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 /** |
|
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
|
123 * Get the console command options. |
|
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
|
124 * |
|
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
|
125 * @return array |
|
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 */ |
|
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
|
127 protected function getOptions() |
|
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 { |
|
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
|
129 return [ |
| 4 | 130 ['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
|
131 ]; |
|
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
|
132 } |
|
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
|
133 |
|
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
|
134 /** |
|
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
|
135 * Interact further with the user if they were prompted for missing arguments. |
|
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
|
136 * |
|
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
|
137 * @return void |
|
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
|
138 */ |
|
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
|
139 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) |
|
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
|
140 { |
|
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
|
141 } |
|
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
|
142 |
| 2 | 143 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
144 * Determines if the file exists. |
| 4 | 145 */ |
| 146 protected function fileExists(string $path): bool | |
| 147 { | |
| 148 return $this->files->exists($path); | |
| 149 } | |
| 150 | |
| 151 /** | |
| 2 | 152 * Gets the file that will be worked on. If there is already an existing file |
| 153 * then we can open that. However if we are forcing the operation, then we | |
| 154 * will start with an empty stub. | |
| 155 */ | |
| 156 protected function getFile($name) | |
| 157 { | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
158 if (!($this->hasOption('fresh') |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
159 && $this->option('fresh')) |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
160 && $this->fileExists($name)) { |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
161 // Working with an existing file |
| 4 | 162 return $this->files->get($name); |
| 2 | 163 } |
| 164 | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
165 // Working with a stub |
| 2 | 166 return $this->files->get($this->getStub()); |
| 167 } | |
| 168 | |
|
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
|
169 /** |
|
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
|
170 * Get the desired class table from the input. |
|
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
|
171 * |
|
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
|
172 * @return string |
|
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
|
173 */ |
|
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
|
174 protected function getTableInput() |
|
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
|
175 { |
|
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
|
176 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
|
177 } |
|
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
|
178 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
179 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
180 * Determines if the table exists in the current database. |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
181 */ |
|
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
|
182 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
|
183 { |
|
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
|
184 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
|
185 } |
|
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
|
186 |
|
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
|
187 /** |
|
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
|
188 * Get a list of possible table names. |
|
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
|
189 */ |
|
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
|
190 protected function possibleTables() |
|
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
|
191 { |
| 2 | 192 return $this->getTables(); |
| 193 } | |
|
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
|
194 |
|
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
|
195 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
196 * Get the tables in the 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
|
197 */ |
|
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
|
198 protected function 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
|
199 { |
| 2 | 200 if (is_null($this->tables)) { |
| 201 $this->tables = collect($this->getSchema()->listTableNames())->all(); | |
| 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 |
| 2 | 204 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
|
205 } |
|
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
|
206 |
|
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
|
207 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
208 * Get the database schema for DB interactions. |
|
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
|
209 */ |
|
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
|
210 protected function getSchema() |
|
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
|
211 { |
|
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
|
212 if (is_null($this->schema)) { |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
213 $this->schema = \DB::connection()->getDoctrineSchemaManager(); |
|
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
|
214 } |
|
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
|
215 |
|
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
|
216 return $this->schema; |
|
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
|
217 } |
| 5 | 218 |
| 219 protected function getTable(string $table_name) | |
| 220 { | |
| 221 return $this->getSchema()->introspectTable($table_name); | |
| 222 } | |
| 223 | |
| 224 protected function getCurrentTable() | |
| 225 { | |
| 226 return $this->currentTable; | |
| 227 } | |
| 228 | |
| 229 protected function setCurrentTable(string $table_name) | |
| 230 { | |
| 231 $table = null; | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
232 if (!is_null($table_name) && '' !== trim($table_name)) { |
| 5 | 233 $table = $this->getTable($table_name); |
| 234 } | |
| 235 $this->currentTable = $table; | |
| 236 } | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
237 |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
238 protected function format_file(string $path) |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
239 { |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
240 exec('php-cs-fixer fix '.$path); |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
241 } |
|
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
|
242 } |
