Mercurial > packages > magicforger
comparison src/Generator/View/ViewGenerator.php @ 25:1a717c7b211f codex
added support for some basic views
| author | Luka Sitas <sitas.luka.97@gmail.com> |
|---|---|
| date | Sun, 11 May 2025 21:03:51 -0400 |
| parents | |
| children | 555bfaa500ac |
comparison
equal
deleted
inserted
replaced
| 24:31109c61ce02 | 25:1a717c7b211f |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Wizard\MagicForger\Generator\View; | |
| 4 | |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | |
| 6 use Symfony\Component\Console\Input\InputInterface; | |
| 7 use Symfony\Component\Console\Input\InputOption; | |
| 8 use Symfony\Component\Console\Output\OutputInterface; | |
| 9 use Wizard\MagicForger\Generator\BaseGenerator; | |
| 10 | |
| 11 #[AsCommand(name: 'mf:view')] | |
| 12 class ViewGenerator extends BaseGenerator | |
| 13 { | |
| 14 /** | |
| 15 * The name and signature of the console command. | |
| 16 * | |
| 17 * @var string | |
| 18 */ | |
| 19 protected $name = 'mf:view'; | |
| 20 | |
| 21 /** | |
| 22 * The console command description. | |
| 23 * | |
| 24 * @var string | |
| 25 */ | |
| 26 protected $description = 'Generates the View File for a table.'; | |
| 27 | |
| 28 /** | |
| 29 * The type of class being generated. | |
| 30 * | |
| 31 * @var string | |
| 32 */ | |
| 33 protected $type = 'View'; | |
| 34 | |
| 35 /** | |
| 36 * Execute the console command. | |
| 37 */ | |
| 38 public function handle() | |
| 39 { | |
| 40 // First we need to ensure that the table exists, then we can | |
| 41 if (! $this->tableExists($this->getTableInput())) { | |
| 42 $this->components->error('The table: "'.$this->getTableInput().'" does not exist in the database.'); | |
| 43 | |
| 44 return false; | |
| 45 } | |
| 46 | |
| 47 if ($this->option('all')) { | |
| 48 $this->input->setOption('index_view', true); | |
| 49 $this->input->setOption('create_edit_view', true); | |
| 50 $this->input->setOption('show_view', true); | |
| 51 } | |
| 52 | |
| 53 if ($this->option('index_view')) { | |
| 54 $this->createIndexView(); | |
| 55 } | |
| 56 | |
| 57 if ($this->option('create_edit_view')) { | |
| 58 $this->createCreateEditView(); | |
| 59 } | |
| 60 | |
| 61 if ($this->option('show_view')) { | |
| 62 $this->createShowView(); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 /** | |
| 67 * Get the console command options. | |
| 68 */ | |
| 69 protected function getOptions(): array | |
| 70 { | |
| 71 return array_merge(parent::getOptions(), [ | |
| 72 ['all', 'a', InputOption::VALUE_NONE, 'Generate all views for the table.'], | |
| 73 ['index_view', 'i', InputOption::VALUE_NONE, 'Generate index view for the table.'], | |
| 74 ['create_edit_view', 'c', InputOption::VALUE_NONE, 'Generate create_edit view for the table.'], | |
| 75 ['show_view', 's', InputOption::VALUE_NONE, 'Generate show view for the table.'], | |
| 76 ]); | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Interact further with the user if they were prompted for missing arguments. | |
| 81 */ | |
| 82 protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output): void {} | |
| 83 | |
| 84 /** | |
| 85 * Get the stub file for the generator. | |
| 86 * | |
| 87 * @return string | |
| 88 */ | |
| 89 protected function getStub() {} | |
| 90 | |
| 91 protected function createIndexView() | |
| 92 { | |
| 93 $this->call('mf:index_view', ['table' => $this->getTableInput()]); | |
| 94 } | |
| 95 | |
| 96 protected function createCreateEditView() | |
| 97 { | |
| 98 $this->call('mf:create_edit_view', ['table' => $this->getTableInput()]); | |
| 99 } | |
| 100 | |
| 101 protected function createShowView() | |
| 102 { | |
| 103 $this->call('mf:show_view', ['table' => $this->getTableInput()]); | |
| 104 } | |
| 105 } |
