Mercurial > packages > magicforger
comparison src/Generator/Model/ModelGenerator.php @ 4:a20439b1c9d3
Added Model generator and other updates.
| author | luka |
|---|---|
| date | Tue, 27 Jun 2023 20:16:55 -0400 |
| parents | |
| children | b0b2e79ad8e6 |
comparison
equal
deleted
inserted
replaced
| 3:6468684362c2 | 4:a20439b1c9d3 |
|---|---|
| 1 <?php | |
| 2 | |
| 3 namespace Wizzard\MagicForger\Generator\Controller; | |
| 4 | |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | |
| 6 use Wizzard\MagicForger\Generator\BaseGenerator; | |
| 7 use Wizzard\MagicForger\Replacer; | |
| 8 use Illuminate\Support\Str; | |
| 9 | |
| 10 #[AsCommand(name: 'mf:model')] | |
| 11 class ModelGenerator extends BaseGenerator | |
| 12 { | |
| 13 /** | |
| 14 * The name and signature of the console command. | |
| 15 * | |
| 16 * @var string | |
| 17 */ | |
| 18 protected $name = 'mf:model'; | |
| 19 | |
| 20 /** | |
| 21 * The console command description. | |
| 22 * | |
| 23 * @var string | |
| 24 */ | |
| 25 protected $description = 'Generates the Model File for a table.'; | |
| 26 | |
| 27 /** | |
| 28 * The type of class being generated. | |
| 29 * | |
| 30 * @var string | |
| 31 */ | |
| 32 protected $type = 'Model'; | |
| 33 | |
| 34 /** | |
| 35 * Execute the console command. | |
| 36 */ | |
| 37 public function handle() | |
| 38 { | |
| 39 parent::handle(); | |
| 40 } | |
| 41 | |
| 42 /** | |
| 43 * Get the stub file for the generator. | |
| 44 * | |
| 45 * @return string | |
| 46 */ | |
| 47 protected function getStub() | |
| 48 { | |
| 49 return $this->resolveStubPath('/stubs/model.stub'); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Resolve the fully-qualified path to the stub. | |
| 54 * | |
| 55 * @param string $stub | |
| 56 * @return string | |
| 57 */ | |
| 58 protected function resolveStubPath($stub) | |
| 59 { | |
| 60 return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) | |
| 61 ? $customPath | |
| 62 : __DIR__.$stub; | |
| 63 } | |
| 64 | |
| 65 protected function getClassName($name) | |
| 66 { | |
| 67 return $this->model_name($name); | |
| 68 } | |
| 69 | |
| 70 /** | |
| 71 * Get the stub file for the generator. | |
| 72 * | |
| 73 * @return string | |
| 74 */ | |
| 75 protected function getPath($name = null) | |
| 76 { | |
| 77 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getModelNamespace() . '/' . $this->model_name($this->getTableInput()) . '.php'); | |
| 78 } | |
| 79 } |
