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