annotate src/Generator/BaseGenerator.php @ 4:a20439b1c9d3

Added Model generator and other updates.
author luka
date Tue, 27 Jun 2023 20:16:55 -0400
parents 6468684362c2
children b0b2e79ad8e6
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;
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
6
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
7 use Illuminate\Console\GeneratorCommand;
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
8 use Illuminate\Support\Str;
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
9 use Symfony\Component\Console\Attribute\AsCommand;
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
10 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
11 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
12 use Symfony\Component\Console\Output\OutputInterface;
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
13
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
14 use Wizzard\MagicForger\Generator\Replacer;
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
15
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
16 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
17 {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
18 use Replacer;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
19
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 * The console command description.
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 * @var string
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 protected $schema;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
26
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
27 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
28 * The console command description.
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 * @var string
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
31 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
32 protected $tables;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
33
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
34 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
35 * 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
36 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
37 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
38 {
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
39
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
40
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
41 // First we need to ensure that the table exists, then we can
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
42 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
43 $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
44
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
45 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
46 }
ca36acd2bef2 Have a base going, there is 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
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
48 $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
49
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
50 $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
51
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
52 $file = $this->apply_replacements($file);
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
53
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 $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
55
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
56 $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
57
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
58 $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
59
ca36acd2bef2 Have a base going, there is 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 $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
61 }
ca36acd2bef2 Have a base going, there is 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
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
63 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
64 * 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
65 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
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 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
68 {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
69 $prompted = false;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
70 if(is_null($input->getArgument('table'))) {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
71 $prompted = true;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
72 $table = null;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
73 while ($table === null) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
74 $table = $this->components->askWithCompletion(
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
75 'What Table should we use?',
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
76 $this->possibleTables()
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
77 );
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
78 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
79
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
80 $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
81 }
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
82
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
83 parent::promptForMissingArguments($input, $output);
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
84
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
85 // This will get missed if we prompt here but not in the parent
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
86 if($prompted) {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
87 $this->afterPromptingForMissingArguments($input, $output);
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 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
90
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
91 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
92 * 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
93 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
94 * @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
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 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
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 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
99 ['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
100 ];
ca36acd2bef2 Have a base going, there is 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
ca36acd2bef2 Have a base going, there is 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 * 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
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 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
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 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
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 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
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 }
ca36acd2bef2 Have a base going, there is 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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
116 *
ca36acd2bef2 Have a base going, there is 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 * @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
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 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
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 return [
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
122 ['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
123 ];
ca36acd2bef2 Have a base going, there is 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
ca36acd2bef2 Have a base going, there is 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 * 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
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 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
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 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
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
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
135 /**
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
136 * Determines if the file exists
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
137 */
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
138 protected function fileExists(string $path): bool
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
139 {
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
140 return $this->files->exists($path);
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
141 }
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
142
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
143 /**
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
144 * 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
145 * 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
146 * will start with an empty stub.
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
147 *
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
148 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
149 protected function getFile($name)
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
150 {
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
151 if ((! $this->hasOption('fresh') ||
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
152 ! $this->option('fresh')) &&
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
153 $this->fileExists($name)) {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
154 //Working with an existing file
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
155 return $this->files->get($name);
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
156 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
157
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
158 //Working with a stub
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
159 return $this->files->get($this->getStub());
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
160 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
161
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
162 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
163 * 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
164 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
165 * @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
166 */
ca36acd2bef2 Have a base going, there is 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 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
168 {
ca36acd2bef2 Have a base going, there is 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 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
170 }
ca36acd2bef2 Have a base going, there is 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
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
172
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
173 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
174 * Determines if the table exists in the current database
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
175 */
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
176 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
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 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
179 }
ca36acd2bef2 Have a base going, there is 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
ca36acd2bef2 Have a base going, there is 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 * 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
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 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
185 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
186 return $this->getTables();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
187 }
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
188
ca36acd2bef2 Have a base going, there is 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 * Get the tables in the 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
191 */
ca36acd2bef2 Have a base going, there is 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 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
193 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
194 if (is_null($this->tables)) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
195 $this->tables = collect($this->getSchema()->listTableNames())->all();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
196 }
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
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
198 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
199 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
200
ca36acd2bef2 Have a base going, there is 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 /**
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
202 * 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
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 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
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 if (is_null($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
207 $this->schema = DB::connection()->getDoctrineSchemaManager();
ca36acd2bef2 Have a base going, there is 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 }
ca36acd2bef2 Have a base going, there is 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 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
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 }