Mercurial > packages > magicforger
annotate src/Generator/Generator.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 | |
| children | b0b2e79ad8e6 4bb4daa9e3f1 |
| rev | line source |
|---|---|
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
1 <?php |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
2 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
3 namespace Wizzard\MagicForger\Generator; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
4 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
5 use DB; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
6 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
7 use Symfony\Component\Console\Attribute\AsCommand; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
8 use Symfony\Component\Console\Input\InputInterface; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
9 use Symfony\Component\Console\Input\InputOption; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
10 use Symfony\Component\Console\Output\OutputInterface; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
11 use Illuminate\Support\Str; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
12 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
13 use Wizzard\MagicForger\Generator\BaseGenerator; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
14 use Wizzard\MagicForger\Replacer; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
15 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
16 #[AsCommand(name: 'mf')] |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
17 class Generator extends BaseGenerator |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
18 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
19 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
20 * The name and signature of the console command. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
21 * |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
22 * @var string |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
23 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
24 protected $name = 'mf'; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
25 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
26 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
27 * The console command description. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
28 * |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
29 * @var string |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
30 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
31 protected $description = 'Generates any (or all) of the available files.'; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
32 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
33 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
34 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
35 * Execute the console command. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
36 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
37 public function handle() |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
38 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
39 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
40 // First we need to ensure that the table exists, then we can |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
41 if (!$this->tableExists($this->getTableInput())) { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
42 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
43 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
44 return false; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
45 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
46 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
47 if ($this->option('all')) { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
48 /* $this->input->setOption('factory', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
49 /* $this->input->setOption('seed', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
50 /* $this->input->setOption('migration', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
51 $this->input->setOption('controller', true); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
52 /* $this->input->setOption('model', true); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
53 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
54 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
55 /* if ($this->option('factory')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
56 /* $this->createFactory(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
57 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
58 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
59 /* if ($this->option('migration')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
60 /* $this->createMigration(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
61 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
62 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
63 /* if ($this->option('seed')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
64 /* $this->createSeeder(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
65 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
66 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
67 if ($this->option('controller')) { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
68 $this->createController(); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
69 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
70 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
71 /* if ($this->option('model')) { */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
72 /* $this->createModel(); */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
73 /* } */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
74 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
75 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
76 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
77 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
78 * Get the console command options. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
79 * |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
80 * @return array |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
81 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
82 protected function getOptions() |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
83 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
84 return [ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
85 ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
86 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
87 ]; |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
88 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
89 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
90 /** |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
91 * Interact further with the user if they were prompted for missing arguments. |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
92 * |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
93 * @return void |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
94 */ |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
95 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
96 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
97 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
98 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
99 protected function getStub() |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
100 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
101 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
102 |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
103 protected function createController() |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
104 { |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
105 $this->call('mf:controller', ['table' => $this->getTableInput()]); |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
106 } |
|
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
diff
changeset
|
107 } |
