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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
17
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
18 /**
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
19 * The schema of the database.
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
20 *
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
21 * @var string
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
22 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
23 protected $schema;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
24
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
25 /**
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
26 * The tables available in the schema.
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
27 *
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
28 * @var array
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
29 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
30 protected $tables;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
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 /**
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
33 * The current Table being used.
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
34 *
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
35 * @var table
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
36 */
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
37 protected $currentTable;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
38
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
55 $file = $this->apply_replacements($file);
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
80 $table = $this->components->askWithCompletion(
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
81 'What Table should we use?',
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
82 $this->possibleTables()
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
83 );
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
84 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
85
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
143 */
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
144 protected function fileExists(string $path): bool
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
145 {
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
146 return $this->files->exists($path);
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
147 }
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
148
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
149 /**
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
150 * Gets the file that will be worked on. If there is already an existing file
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
151 * then we can open that. However if we are forcing the operation, then we
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
152 * will start with an empty stub.
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
153 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
154 protected function getFile($name)
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
160 return $this->files->get($name);
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
161 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
164 return $this->files->get($this->getStub());
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
165 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
190 return $this->getTables();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
198 if (is_null($this->tables)) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
199 $this->tables = collect($this->getSchema()->listTableNames())->all();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
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
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
216
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
217 protected function getTable(string $table_name)
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
218 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
219 return $this->getSchema()->introspectTable($table_name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
220 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
221
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
222 protected function getCurrentTable()
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
223 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
224 return $this->currentTable;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
225 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
226
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
227 protected function setCurrentTable(string $table_name)
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
228 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
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
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
231 $table = $this->getTable($table_name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
232 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
233 $this->currentTable = $table;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
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 }