Mercurial > packages > magicforger
comparison src/Generator/Generator.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 | 6468684362c2 |
| children | 769a17898cc0 |
comparison
equal
deleted
inserted
replaced
| 4:a20439b1c9d3 | 5:b0b2e79ad8e6 |
|---|---|
| 9 use Symfony\Component\Console\Input\InputOption; | 9 use Symfony\Component\Console\Input\InputOption; |
| 10 use Symfony\Component\Console\Output\OutputInterface; | 10 use Symfony\Component\Console\Output\OutputInterface; |
| 11 use Illuminate\Support\Str; | 11 use Illuminate\Support\Str; |
| 12 | 12 |
| 13 use Wizzard\MagicForger\Generator\BaseGenerator; | 13 use Wizzard\MagicForger\Generator\BaseGenerator; |
| 14 use Wizzard\MagicForger\Replacer; | |
| 15 | 14 |
| 16 #[AsCommand(name: 'mf')] | 15 #[AsCommand(name: 'mf')] |
| 17 class Generator extends BaseGenerator | 16 class Generator extends BaseGenerator |
| 18 { | 17 { |
| 19 /** | 18 /** |
| 42 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); | 41 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
| 43 | 42 |
| 44 return false; | 43 return false; |
| 45 } | 44 } |
| 46 | 45 |
| 46 $this->setCurrentTable($this->getTableInput()); | |
| 47 dd($this->getCurrentTable()->getForeignKeys()); | |
| 48 | |
| 47 if ($this->option('all')) { | 49 if ($this->option('all')) { |
| 48 /* $this->input->setOption('factory', true); */ | 50 /* $this->input->setOption('factory', true); */ |
| 49 /* $this->input->setOption('seed', true); */ | 51 /* $this->input->setOption('seed', true); */ |
| 50 /* $this->input->setOption('migration', true); */ | 52 /* $this->input->setOption('migration', true); */ |
| 51 $this->input->setOption('controller', true); | 53 $this->input->setOption('controller', true); |
| 52 /* $this->input->setOption('model', true); */ | 54 $this->input->setOption('model', true); |
| 55 $this->input->setOption('request', true); | |
| 56 $this->input->setOption('route', true); | |
| 53 } | 57 } |
| 54 | 58 |
| 55 /* if ($this->option('factory')) { */ | 59 /* if ($this->option('factory')) { */ |
| 56 /* $this->createFactory(); */ | 60 /* $this->createFactory(); */ |
| 57 /* } */ | 61 /* } */ |
| 66 | 70 |
| 67 if ($this->option('controller')) { | 71 if ($this->option('controller')) { |
| 68 $this->createController(); | 72 $this->createController(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 /* if ($this->option('model')) { */ | 75 if ($this->option('model')) { |
| 72 /* $this->createModel(); */ | 76 $this->createModel(); |
| 73 /* } */ | 77 } |
| 78 | |
| 79 if ($this->option('request')) { | |
| 80 $this->createRequest(); | |
| 81 } | |
| 82 | |
| 83 if ($this->option('route')) { | |
| 84 $this->createRoute(); | |
| 85 } | |
| 74 | 86 |
| 75 } | 87 } |
| 76 | 88 |
| 77 /** | 89 /** |
| 78 * Get the console command options. | 90 * Get the console command options. |
| 79 * | 91 * |
| 80 * @return array | 92 * @return array |
| 81 */ | 93 */ |
| 82 protected function getOptions() | 94 protected function getOptions() |
| 83 { | 95 { |
| 84 return [ | 96 return array_merge(parent::getOptions(), [ |
| 85 ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], | 97 ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], |
| 86 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], | 98 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], |
| 87 ]; | 99 ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], |
| 100 ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], | |
| 101 ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], | |
| 102 ]); | |
| 88 } | 103 } |
| 89 | 104 |
| 90 /** | 105 /** |
| 91 * Interact further with the user if they were prompted for missing arguments. | 106 * Interact further with the user if they were prompted for missing arguments. |
| 92 * | 107 * |
| 100 { | 115 { |
| 101 } | 116 } |
| 102 | 117 |
| 103 protected function createController() | 118 protected function createController() |
| 104 { | 119 { |
| 105 $this->call('mf:controller', ['table' => $this->getTableInput()]); | 120 $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
| 121 } | |
| 122 | |
| 123 protected function createModel() | |
| 124 { | |
| 125 $this->call('mf:model', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | |
| 126 } | |
| 127 | |
| 128 protected function createRequest() | |
| 129 { | |
| 130 $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); | |
| 131 } | |
| 132 | |
| 133 protected function createRoute() | |
| 134 { | |
| 135 $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | |
| 106 } | 136 } |
| 107 } | 137 } |
