annotate src/Generator/BaseGenerator.php @ 3:6468684362c2

It works! Created a controller, no update insert but it works
author luka
date Tue, 27 Jun 2023 15:32:47 -0400
parents cf9993c5c7df
children a20439b1c9d3
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 {
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
39 // 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
40 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
41 $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
42
ca36acd2bef2 Have a base going, there is 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 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
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
ca36acd2bef2 Have a base going, there is 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 $name = $this->qualifyClass($this->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
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 $path = $this->getPath($name);
ca36acd2bef2 Have a base going, there is 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
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
50 $file = $this->getFile($name);
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
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
52 dd($this->get_all_inserts($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
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 // Next, we will generate the path to the location where this class' file should get
ca36acd2bef2 Have a base going, there is 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 // written. Then, we will build the class and make the proper replacements on the
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
56 // file so that it gets the correctly formatted namespace and class name.
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 $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
58
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
59 $this->files->put($path, $this->sortImports($this->buildClass($name)));
ca36acd2bef2 Have a base going, there is 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
ca36acd2bef2 Have a base going, there is 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 $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
62
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
63 if (in_array(CreatesMatchingTest::class, class_uses_recursive($this))) {
ca36acd2bef2 Have a base going, there is 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 if ($this->handleTestCreation($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
65 $info .= ' and test';
ca36acd2bef2 Have a base going, there is 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 }
ca36acd2bef2 Have a base going, there is 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 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
72
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
73 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
74 * 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
75 *
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
76 */
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
77 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
78 {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
79 $prompted = false;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
80 if(is_null($input->getArgument('table'))) {
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
81 $prompted = true;
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
82 $table = null;
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
83 while ($table === null) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
84 $table = $this->components->askWithCompletion(
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
85 'What Table should we use?',
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
86 $this->possibleTables()
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 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
89
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
90 $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
91 }
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
92
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
93 parent::promptForMissingArguments($input, $output);
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
94
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
95 // 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
96 if($prompted) {
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
97 $this->afterPromptingForMissingArguments($input, $output);
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
98 }
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
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
ca36acd2bef2 Have a base going, there is 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 * 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
103 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
104 * @return 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
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 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
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 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
109 ['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
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
ca36acd2bef2 Have a base going, there is 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 * 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
115 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
116 * @return 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
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 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
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 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
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
ca36acd2bef2 Have a base going, there is 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 * 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
126 *
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
127 * @return 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
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 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
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 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
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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
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 * @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
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 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
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 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
143
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
144 /**
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
145 * 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
146 * 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
147 * will start with an empty stub.
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 */
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
150 protected function getFile($name)
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
151 {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
152
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
153 if ((! $this->hasOption('force') ||
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
154 ! $this->option('force')) &&
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
155 $this->alreadyExists($name)) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
156 //Working with an existing file
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
157 $this->files->get($name);
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
158 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
159
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
160 //Working with a stub
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
161 return $this->files->get($this->getStub());
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
162 }
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
163
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
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 * 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
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 * @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
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 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
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 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
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
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
174 /**
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
175 * 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
176 */
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
177 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
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 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
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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
184 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
185 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
186 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
187 return $this->getTables();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
188 }
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
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 /**
ca36acd2bef2 Have a base going, there is 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 * 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
192 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
193 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
194 {
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
195 if (is_null($this->tables)) {
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
196 $this->tables = collect($this->getSchema()->listTableNames())->all();
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
197 }
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
198
2
cf9993c5c7df Updated .vimrc for some helper commands.
luka
parents: 1
diff changeset
199 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
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
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
202 /**
3
6468684362c2 It works! Created a controller, no update insert but it works
luka
parents: 2
diff changeset
203 * 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
204 */
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
205 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
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 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
208 $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
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
ca36acd2bef2 Have a base going, there is 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 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
212 }
ca36acd2bef2 Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
luka
parents:
diff changeset
213 }