Mercurial > packages > magicforger
comparison src/Generator/Generator.php @ 34:f65ab84ee47f default
merge with codex
| author | luka |
|---|---|
| date | Wed, 10 Sep 2025 21:00:47 -0400 |
| parents | 1a717c7b211f |
| children | 76584181267a |
comparison
equal
deleted
inserted
replaced
| 10:a9ff874afdbd | 34:f65ab84ee47f |
|---|---|
| 1 <?php | 1 <?php |
| 2 | 2 |
| 3 namespace Wizzard\MagicForger\Generator; | 3 namespace Wizard\MagicForger\Generator; |
| 4 | 4 |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | 5 use Symfony\Component\Console\Attribute\AsCommand; |
| 6 use Symfony\Component\Console\Input\InputInterface; | 6 use Symfony\Component\Console\Input\InputInterface; |
| 7 use Symfony\Component\Console\Input\InputOption; | 7 use Symfony\Component\Console\Input\InputOption; |
| 8 use Symfony\Component\Console\Output\OutputInterface; | 8 use Symfony\Component\Console\Output\OutputInterface; |
| 27 /** | 27 /** |
| 28 * Execute the console command. | 28 * Execute the console command. |
| 29 */ | 29 */ |
| 30 public function handle() | 30 public function handle() |
| 31 { | 31 { |
| 32 | |
| 32 // First we need to ensure that the table exists, then we can | 33 // First we need to ensure that the table exists, then we can |
| 33 if (!$this->tableExists($this->getTableInput())) { | 34 if (! $this->tableExists($this->getTableInput())) { |
| 34 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); | 35 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); |
| 35 | 36 |
| 36 return false; | 37 return false; |
| 37 } | 38 } |
| 38 | 39 |
| 44 /* $this->input->setOption('seed', true); */ | 45 /* $this->input->setOption('seed', true); */ |
| 45 /* $this->input->setOption('migration', true); */ | 46 /* $this->input->setOption('migration', true); */ |
| 46 $this->input->setOption('controller', true); | 47 $this->input->setOption('controller', true); |
| 47 $this->input->setOption('model', true); | 48 $this->input->setOption('model', true); |
| 48 $this->input->setOption('request', true); | 49 $this->input->setOption('request', true); |
| 50 $this->input->setOption('view', true); | |
| 49 $this->input->setOption('route', true); | 51 $this->input->setOption('route', true); |
| 50 } | 52 } |
| 51 | 53 |
| 52 /* if ($this->option('factory')) { */ | 54 /* if ($this->option('factory')) { */ |
| 53 /* $this->createFactory(); */ | 55 /* $this->createFactory(); */ |
| 71 | 73 |
| 72 if ($this->option('request')) { | 74 if ($this->option('request')) { |
| 73 $this->createRequest(); | 75 $this->createRequest(); |
| 74 } | 76 } |
| 75 | 77 |
| 78 if ($this->option('view')) { | |
| 79 $this->createView(); | |
| 80 } | |
| 81 | |
| 76 if ($this->option('route')) { | 82 if ($this->option('route')) { |
| 77 $this->createRoute(); | 83 $this->createRoute(); |
| 78 } | 84 } |
| 79 } | 85 } |
| 80 | 86 |
| 81 /** | 87 /** |
| 82 * Get the console command options. | 88 * Get the console command options. |
| 83 * | |
| 84 * @return array | |
| 85 */ | 89 */ |
| 86 protected function getOptions() | 90 protected function getOptions(): array |
| 87 { | 91 { |
| 88 return array_merge(parent::getOptions(), [ | 92 return array_merge(parent::getOptions(), [ |
| 89 ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], | 93 ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'], |
| 90 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], | 94 ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'], |
| 91 ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], | 95 ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'], |
| 92 ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], | 96 ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'], |
| 97 ['view', '', InputOption::VALUE_NONE, 'Generate base views for the table.'], | |
| 93 ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], | 98 ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'], |
| 94 ]); | 99 ]); |
| 95 } | 100 } |
| 96 | 101 |
| 97 /** | 102 /** |
| 98 * Interact further with the user if they were prompted for missing arguments. | 103 * Interact further with the user if they were prompted for missing arguments. |
| 99 * | |
| 100 * @return void | |
| 101 */ | 104 */ |
| 102 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output) | 105 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void {} |
| 103 { | |
| 104 } | |
| 105 | 106 |
| 106 protected function getStub() | 107 protected function getStub(): void {} |
| 107 { | |
| 108 } | |
| 109 | 108 |
| 110 protected function createController() | 109 protected function createController(): void |
| 111 { | 110 { |
| 112 $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | 111 $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
| 113 } | 112 } |
| 114 | 113 |
| 115 protected function createModel() | 114 protected function createModel() |
| 120 protected function createRequest() | 119 protected function createRequest() |
| 121 { | 120 { |
| 122 $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); | 121 $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); |
| 123 } | 122 } |
| 124 | 123 |
| 124 protected function createView() | |
| 125 { | |
| 126 $this->call('mf:view', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]); | |
| 127 } | |
| 128 | |
| 125 protected function createRoute() | 129 protected function createRoute() |
| 126 { | 130 { |
| 127 $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); | 131 $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]); |
| 128 } | 132 } |
| 129 } | 133 } |
