Mercurial > packages > magicforger
annotate examples/ExampleGenerator.php.stub @ 4:a20439b1c9d3
Added Model generator and other updates.
| author | luka |
|---|---|
| date | Tue, 27 Jun 2023 20:16:55 -0400 |
| parents | 6468684362c2 |
| children | b0b2e79ad8e6 |
| rev | line source |
|---|---|
| 2 | 1 <?php |
| 2 | |
| 4 | 3 namespace Wizzard\MagicForger\Generator\Controller; |
| 2 | 4 |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | |
| 6 use Wizzard\MagicForger\Generator\BaseGenerator; | |
| 7 use Wizzard\MagicForger\Replacer; | |
| 4 | 8 use Illuminate\Support\Str; |
| 2 | 9 |
| 10 #[AsCommand(name: 'mf:{{ Command Name }}')] | |
| 11 class {{ Class Name }}Generator extends BaseGenerator | |
| 12 { | |
| 13 /** | |
| 14 * The name and signature of the console command. | |
| 15 * | |
| 16 * @var string | |
| 17 */ | |
| 18 protected $name = 'mf:{{ Command Name }}'; | |
| 19 | |
| 20 /** | |
| 21 * The console command description. | |
| 22 * | |
| 23 * @var string | |
| 24 */ | |
| 25 protected $description = 'Generates the {{ Class Name }} File for a table.'; | |
| 26 | |
| 27 /** | |
| 28 * The type of class being generated. | |
| 29 * | |
| 30 * @var string | |
| 31 */ | |
| 32 protected $type = '{{ Class Name }}'; | |
| 33 | |
| 34 /** | |
| 35 * Execute the console command. | |
| 36 */ | |
| 37 public function handle() | |
| 38 { | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
39 parent::handle(); |
| 2 | 40 } |
| 41 | |
| 42 /** | |
| 43 * Get the stub file for the generator. | |
| 44 * | |
| 45 * @return string | |
| 46 */ | |
| 47 protected function getStub() | |
| 48 { | |
| 4 | 49 return $this->resolveStubPath('/stubs/{{ Command Name }}.stub'); |
| 2 | 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 } | |
| 4 | 64 |
| 65 protected function getClassName($name) | |
| 66 { | |
| 67 return $this->{{ Command Name }}_name($name); | |
| 68 } | |
| 69 | |
| 2 | 70 /** |
| 4 | 71 * Get the stub file for the generator. |
| 2 | 72 * |
| 73 * @return string | |
| 74 */ | |
| 4 | 75 protected function getPath($name = null) |
| 2 | 76 { |
| 4 | 77 return str_replace(['App\\', '\\'], ['app/', '/'], $this->get{{ Class Name }}Namespace() . '/' . $this->{{ Command Name }}_name($this->getTableInput()) . '.php'); |
| 2 | 78 } |
| 79 } | |
| 80 |
