Mercurial > packages > magicforger
annotate src/Generator/BaseGenerator.php @ 7:769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
| author | luka |
|---|---|
| date | Wed, 18 Oct 2023 21:04:11 -0400 |
| parents | b0b2e79ad8e6 |
| children | d4730c14806d |
| 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 |
| 4 | 51 $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
|
52 |
| 4 | 53 $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
|
54 |
| 4 | 55 $file = $this->apply_replacements($file); |
| 56 | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
57 $file = $this->apply_inserts($file); |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
58 |
|
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 $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
|
60 |
| 4 | 61 $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
|
62 |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
63 $this->format_file($path); |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
64 |
|
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
|
65 $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
|
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 $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
|
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 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
70 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
71 * 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
|
72 */ |
|
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
|
73 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
|
74 { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
75 $prompted = false; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
76 if (is_null($input->getArgument('table'))) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
77 $prompted = true; |
| 2 | 78 $table = null; |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
79 while (null === $table) { |
| 2 | 80 $table = $this->components->askWithCompletion( |
| 81 'What Table should we use?', | |
| 82 $this->possibleTables() | |
| 83 ); | |
| 84 } | |
| 85 | |
| 86 $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
|
87 } |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
88 |
|
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 parent::promptForMissingArguments($input, $output); |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
90 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
91 // 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
|
92 if ($prompted) { |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
93 $this->afterPromptingForMissingArguments($input, $output); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
94 } |
|
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
|
95 } |
|
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
|
96 |
|
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 * 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
|
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 * @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
|
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 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
|
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 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
|
105 ['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
|
106 ]; |
|
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 |
|
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 * 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
|
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 * @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
|
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 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
|
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 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
|
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 } |
|
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 * 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
|
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 * @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
|
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 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
|
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 return [ |
| 4 | 128 ['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
|
129 ]; |
|
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
|
130 } |
|
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 * 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
|
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 * @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
|
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 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
|
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 } |
|
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 |
| 2 | 141 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
142 * Determines if the file exists. |
| 4 | 143 */ |
| 144 protected function fileExists(string $path): bool | |
| 145 { | |
| 146 return $this->files->exists($path); | |
| 147 } | |
| 148 | |
| 149 /** | |
| 2 | 150 * Gets the file that will be worked on. If there is already an existing file |
| 151 * then we can open that. However if we are forcing the operation, then we | |
| 152 * will start with an empty stub. | |
| 153 */ | |
| 154 protected function getFile($name) | |
| 155 { | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
156 if (!($this->hasOption('fresh') |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
157 && $this->option('fresh')) |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
158 && $this->fileExists($name)) { |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
159 // Working with an existing file |
| 4 | 160 return $this->files->get($name); |
| 2 | 161 } |
| 162 | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
163 // Working with a stub |
| 2 | 164 return $this->files->get($this->getStub()); |
| 165 } | |
| 166 | |
|
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
|
167 /** |
|
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
|
168 * 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
|
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 * @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
|
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 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
|
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 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
|
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 |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
177 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
178 * 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
|
179 */ |
|
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
|
180 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
|
181 { |
|
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 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
|
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 |
|
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 * 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
|
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 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
|
189 { |
| 2 | 190 return $this->getTables(); |
| 191 } | |
|
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
|
192 |
|
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
|
193 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
194 * 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
|
195 */ |
|
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
|
196 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
|
197 { |
| 2 | 198 if (is_null($this->tables)) { |
| 199 $this->tables = collect($this->getSchema()->listTableNames())->all(); | |
| 200 } | |
|
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
|
201 |
| 2 | 202 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
|
203 } |
|
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
|
204 |
|
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 /** |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
206 * 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
|
207 */ |
|
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
|
208 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
|
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 if (is_null($this->schema)) { |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
211 $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
|
212 } |
|
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
|
213 |
|
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 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
|
215 } |
| 5 | 216 |
| 217 protected function getTable(string $table_name) | |
| 218 { | |
| 219 return $this->getSchema()->introspectTable($table_name); | |
| 220 } | |
| 221 | |
| 222 protected function getCurrentTable() | |
| 223 { | |
| 224 return $this->currentTable; | |
| 225 } | |
| 226 | |
| 227 protected function setCurrentTable(string $table_name) | |
| 228 { | |
| 229 $table = null; | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
230 if (!is_null($table_name) && '' !== trim($table_name)) { |
| 5 | 231 $table = $this->getTable($table_name); |
| 232 } | |
| 233 $this->currentTable = $table; | |
| 234 } | |
|
7
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
235 |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
236 protected function format_file(string $path) |
|
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 exec('php-cs-fixer fix '.$path); |
|
769a17898cc0
Various changes to the generators and replacers - probably mostly just formatting
luka
parents:
5
diff
changeset
|
239 } |
|
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
|
240 } |
