Mercurial > packages > magicforger
annotate examples/ExampleGenerator.php.stub @ 3:6468684362c2
It works! Created a controller, no update insert but it works
| author | luka |
|---|---|
| date | Tue, 27 Jun 2023 15:32:47 -0400 |
| parents | cf9993c5c7df |
| children | a20439b1c9d3 |
| rev | line source |
|---|---|
| 2 | 1 <?php |
| 2 | |
| 3 namespace App\Console\Commands; | |
| 4 | |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | |
| 6 use Wizzard\MagicForger\Generator\BaseGenerator; | |
| 7 use Wizzard\MagicForger\Replacer; | |
| 8 //use Illuminate\Console\Concerns\CreatesMatchingTest; | |
| 9 | |
| 10 #[AsCommand(name: 'mf:{{ Command Name }}')] | |
| 11 class {{ Class Name }}Generator extends BaseGenerator | |
| 12 { | |
| 13 //use CreatesMatchingTest; | |
| 14 | |
| 15 /** | |
| 16 * The name and signature of the console command. | |
| 17 * | |
| 18 * @var string | |
| 19 */ | |
| 20 protected $name = 'mf:{{ Command Name }}'; | |
| 21 | |
| 22 /** | |
| 23 * The console command description. | |
| 24 * | |
| 25 * @var string | |
| 26 */ | |
| 27 protected $description = 'Generates the {{ Class Name }} File for a table.'; | |
| 28 | |
| 29 /** | |
| 30 * The type of class being generated. | |
| 31 * | |
| 32 * @var string | |
| 33 */ | |
| 34 protected $type = '{{ Class Name }}'; | |
| 35 | |
| 36 | |
| 37 /** | |
| 38 * Execute the console command. | |
| 39 */ | |
| 40 public function handle() | |
| 41 { | |
|
3
6468684362c2
It works! Created a controller, no update insert but it works
luka
parents:
2
diff
changeset
|
42 parent::handle(); |
| 2 | 43 } |
| 44 | |
| 45 /** | |
| 46 * Get the stub file for the generator. | |
| 47 * | |
| 48 * @return string | |
| 49 */ | |
| 50 protected function getStub() | |
| 51 { | |
| 52 return $this->resolveStubPath('/stubs/seeder.stub'); | |
| 53 } | |
| 54 | |
| 55 /** | |
| 56 * Resolve the fully-qualified path to the stub. | |
| 57 * | |
| 58 * @param string $stub | |
| 59 * @return string | |
| 60 */ | |
| 61 protected function resolveStubPath($stub) | |
| 62 { | |
| 63 return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) | |
| 64 ? $customPath | |
| 65 : __DIR__.$stub; | |
| 66 } | |
| 67 /** | |
| 68 * Parse the class name and format according to the root namespace. | |
| 69 * | |
| 70 * @param string $name | |
| 71 * @return string | |
| 72 */ | |
| 73 protected function qualifyClass($name) | |
| 74 { | |
| 75 $name = ltrim($name, '\\/'); | |
| 76 | |
| 77 $name = str_replace('/', '\\', $name); | |
| 78 | |
| 79 $rootNamespace = $this->rootNamespace(); | |
| 80 | |
| 81 if (Str::startsWith($name, $rootNamespace)) { | |
| 82 return $name; | |
| 83 } | |
| 84 | |
| 85 return $this->qualifyClass( | |
| 86 $this->getDefaultNamespace(trim($rootNamespace, '\\')).'\\'.$name | |
| 87 ); | |
| 88 } | |
| 89 } | |
| 90 |
