annotate src/Generator/BaseGenerator.php @ 9:d4730c14806d

Small changes to config generation and table name input
author luka
date Sat, 02 Dec 2023 10:18:52 -0500
parents 769a17898cc0
children 19b7a8de0019
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
9
d4730c14806d Small changes to config generation and table name input
luka
parents: 7
diff changeset
51 $this->setCurrentTable($this->getTableInput());
d4730c14806d Small changes to config generation and table name input
luka
parents: 7
diff changeset
52
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
53 $path = $this->getPath();
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
54
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
55 $file = $this->getFile($path);
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
56
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
57 $file = $this->apply_replacements($file);
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
58
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
59 $file = $this->apply_inserts($file);
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
60
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
61 $this->makeDirectory($path);
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
62
4
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
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
65 $this->format_file($path);
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
66
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
67 $info = $this->type;
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
68
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
69 $this->components->info(sprintf('%s [%s] created successfully.', $info, $path));
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
70 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
71
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
72 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
73 * Override the original so that we can prompt for a table with autocomplete.
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
74 */
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
75 protected function promptForMissingArguments(InputInterface $input, OutputInterface $output)
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
76 {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
77 $prompted = false;
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
78 if (is_null($input->getArgument('table'))) {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
79 $prompted = true;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
80 $table = null;
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
81 while (null === $table) {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
82 $table = $this->components->askWithCompletion(
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
83 'What Table should we use?',
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
84 $this->possibleTables()
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
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
88 $input->setArgument('table', $table);
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
89 }
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
90
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
91 parent::promptForMissingArguments($input, $output);
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
92
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
93 // This will get missed if we prompt here but not in the parent
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
94 if ($prompted) {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
95 $this->afterPromptingForMissingArguments($input, $output);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
96 }
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
97 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
98
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
99 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
100 * Get the console command arguments.
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
101 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
102 * @return array
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
103 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
104 protected function getArguments()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
105 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
106 return [
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
107 ['table', InputOption::VALUE_REQUIRED, 'The table to generate files for.'],
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
108 ];
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
109 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
110
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
111 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
112 * Prompt for missing input arguments using the returned questions.
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
113 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
114 * @return array
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
115 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
116 protected function promptForMissingArgumentsUsing()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
117 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
118 return [
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
119 ];
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
120 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
121
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
122 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
123 * Get the console command options.
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
124 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
125 * @return array
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
126 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
127 protected function getOptions()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
128 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
129 return [
4
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
130 ['fresh', 'f', InputOption::VALUE_NONE, 'Start from the stub or use existing if possible.'],
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
131 ];
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
132 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
133
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
134 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
135 * Interact further with the user if they were prompted for missing arguments.
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
136 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
137 * @return void
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
138 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
139 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
140 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
141 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
142
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
143 /**
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
144 * Determines if the file exists.
4
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 protected function fileExists(string $path): bool
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 return $this->files->exists($path);
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
a20439b1c9d3 Added Model generator and other updates.
luka
parents: 3
diff changeset
151 /**
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
152 * 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
153 * 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
154 * will start with an empty stub.
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 {
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
158 if (!($this->hasOption('fresh')
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
159 && $this->option('fresh'))
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
160 && $this->fileExists($name)) {
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
161 // Working with an existing file
4
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
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
165 // Working with a stub
2
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
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
169 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
170 * Get the desired class table from the input.
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
171 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
172 * @return string
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
173 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
174 protected function getTableInput()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
175 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
176 return trim($this->argument('table'));
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
177 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
178
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
179 /**
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
180 * Determines if the table exists in the current database.
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
181 */
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
182 protected function tableExists(string $table_name): bool
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
183 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
184 return in_array($table_name, $this->getTables());
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
185 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
186
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
187 /**
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
188 * Get a list of possible table names.
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
189 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
190 protected function possibleTables()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
191 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
192 return $this->getTables();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
193 }
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
194
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
195 /**
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
196 * Get the tables in the schema.
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
197 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
198 protected function getTables()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
199 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
200 if (is_null($this->tables)) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
201 $this->tables = collect($this->getSchema()->listTableNames())->all();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
202 }
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
203
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
204 return $this->tables;
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
205 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
206
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
207 /**
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
208 * Get the database schema for DB interactions.
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
209 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
210 protected function getSchema()
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
211 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
212 if (is_null($this->schema)) {
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
213 $this->schema = \DB::connection()->getDoctrineSchemaManager();
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
214 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
215
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
216 return $this->schema;
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
217 }
5
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 protected function getTable(string $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 return $this->getSchema()->introspectTable($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
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
224 protected function getCurrentTable()
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 return $this->currentTable;
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
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
229 protected function setCurrentTable(string $table_name)
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 $table = null;
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
232 if (!is_null($table_name) && '' !== trim($table_name)) {
5
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
233 $table = $this->getTable($table_name);
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
234 }
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
235 $this->currentTable = $table;
b0b2e79ad8e6 Not exatly sure what was changed but commiting to it :)
luka
parents: 4
diff changeset
236 }
7
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
237
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
238 protected function format_file(string $path)
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
239 {
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
240 exec('php-cs-fixer fix '.$path);
769a17898cc0 Various changes to the generators and replacers - probably mostly just formatting
luka
parents: 5
diff changeset
241 }
1
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
242 }