annotate src/Generator/BaseGenerator.php @ 5:b0b2e79ad8e6

Not exatly sure what was changed but commiting to it :)
author luka
date Thu, 12 Oct 2023 19:41:04 -0400
parents a20439b1c9d3
children 769a17898cc0
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
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
14 use Wizzard\MagicForger\Replacer\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 /**
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
21 * The schema of the database.
2
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 /**
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
28 * The tables available in the schema.
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
29 *
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
30 * @var array
2
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 /**
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
35 * The current Table being used.
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 * @var table
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 protected $currentTable;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
40
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
41 /**
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
42 * 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
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 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
45 {
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
46
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
47
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
48 // 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
49 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
50 $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
51
ca36acd2bef2 Have a base going, there is 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 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
53 }
ca36acd2bef2 Have a base going, there is 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 $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
56
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
57 $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
58
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
59 $file = $this->apply_replacements($file);
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
60
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
61 $this->makeDirectory($path);
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
62
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
63 $this->files->put($path, $this->sortImports($file));
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
64
ca36acd2bef2 Have a base going, there is 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 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
73 */
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
74 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
75 {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
76 $prompted = false;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
77 if(is_null($input->getArgument('table'))) {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
78 $prompted = true;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
79 $table = null;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
80 while ($table === null) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
81 $table = $this->components->askWithCompletion(
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
82 'What Table should we use?',
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
83 $this->possibleTables()
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
87 $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
88 }
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
89
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
90 parent::promptForMissingArguments($input, $output);
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
91
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
92 // 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
93 if($prompted) {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
94 $this->afterPromptingForMissingArguments($input, $output);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
95 }
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
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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
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 * @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
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 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
104 {
ca36acd2bef2 Have a base going, there is 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 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
106 ['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
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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
112 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
113 * @return 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
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 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
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 [
ca36acd2bef2 Have a base going, there is 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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
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 * @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
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 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
127 {
ca36acd2bef2 Have a base going, there is 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 return [
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
129 ['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
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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
135 *
ca36acd2bef2 Have a base going, there is 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 * @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
137 */
ca36acd2bef2 Have a base going, there is 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 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
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 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
141
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
142 /**
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
143 * Determines if the file exists
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
144 */
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
145 protected function fileExists(string $path): bool
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
146 {
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
147 return $this->files->exists($path);
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
150 /**
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
151 * 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
152 * 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
153 * will start with an empty stub.
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
154 *
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
155 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
156 protected function getFile($name)
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
157 {
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
158 if ((! $this->hasOption('fresh') ||
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
159 ! $this->option('fresh')) &&
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
160 $this->fileExists($name)) {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
161 //Working with an existing file
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
162 return $this->files->get($name);
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
163 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
164
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
165 //Working with a stub
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
166 return $this->files->get($this->getStub());
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
167 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
168
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
169
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
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 * 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
172 *
ca36acd2bef2 Have a base going, there is 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 * @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
174 */
ca36acd2bef2 Have a base going, there is 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 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
176 {
ca36acd2bef2 Have a base going, there is 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 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
178 }
ca36acd2bef2 Have a base going, there is 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
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
180
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
181 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
182 * 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
183 */
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
184 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
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 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
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
ca36acd2bef2 Have a base going, there is 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 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
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 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
193 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
194 return $this->getTables();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
195 }
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
196
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
197 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
198 * 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
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 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
201 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
202 if (is_null($this->tables)) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
203 $this->tables = collect($this->getSchema()->listTableNames())->all();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
204 }
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
205
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
206 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
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
ca36acd2bef2 Have a base going, there is 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 /**
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
210 * 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
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 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
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 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
215 $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
216 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
217
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
218 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
219 }
5
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 protected function getTable(string $table_name)
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
222 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
223 return $this->getSchema()->introspectTable($table_name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
224 }
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 protected function getCurrentTable()
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
227 {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
228 return $this->currentTable;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
229 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
230
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
231 protected function setCurrentTable(string $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 $table = null;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
234 if(!is_null($table_name) && trim($table_name) !== '') {
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
235 $table = $this->getTable($table_name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
236 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
237 $this->currentTable = $table;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
238 }
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
239 }