Mercurial > packages > magicforger
comparison src/Generator/Controller/ControllerGenerator.php @ 34:f65ab84ee47f default
merge with codex
| author | luka |
|---|---|
| date | Wed, 10 Sep 2025 21:00:47 -0400 |
| parents | 827efbf4d73c |
| children |
comparison
equal
deleted
inserted
replaced
| 10:a9ff874afdbd | 34:f65ab84ee47f |
|---|---|
| 1 <?php | 1 <?php |
| 2 | 2 |
| 3 namespace Wizzard\MagicForger\Generator\Controller; | 3 namespace Wizard\MagicForger\Generator\Controller; |
| 4 | 4 |
| 5 use Symfony\Component\Console\Attribute\AsCommand; | 5 use Symfony\Component\Console\Attribute\AsCommand; |
| 6 use Wizzard\MagicForger\Generator\BaseGenerator; | 6 use Wizard\MagicForger\Generator\BaseGenerator; |
| 7 | 7 |
| 8 #[AsCommand(name: 'mf:controller')] | 8 #[AsCommand(name: 'mf:controller')] |
| 9 class ControllerGenerator extends BaseGenerator | 9 class ControllerGenerator extends BaseGenerator |
| 10 { | 10 { |
| 11 /** | 11 /** |
| 30 protected $type = 'Controller'; | 30 protected $type = 'Controller'; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Execute the console command. | 33 * Execute the console command. |
| 34 */ | 34 */ |
| 35 public function handle() | 35 public function handle(): void |
| 36 { | 36 { |
| 37 parent::handle(); | 37 parent::handle(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 /** | 40 /** |
| 41 * Get the stub file for the generator. | 41 * Get the stub file for the generator. |
| 42 * | |
| 43 * @return string | |
| 44 */ | 42 */ |
| 45 protected function getStub() | 43 protected function getStub(): string |
| 46 { | 44 { |
| 47 return $this->resolveStubPath('/stubs/controller.stub'); | 45 return $this->resolveStubPath('/stubs/controller.stub'); |
| 48 } | 46 } |
| 49 | 47 |
| 50 /** | 48 /** |
| 51 * Resolve the fully-qualified path to the stub. | 49 * Resolve the fully-qualified path to the stub. |
| 52 * | |
| 53 * @param string $stub | |
| 54 * | |
| 55 * @return string | |
| 56 */ | 50 */ |
| 57 protected function resolveStubPath($stub) | 51 protected function resolveStubPath(string $stub): string |
| 58 { | 52 { |
| 59 return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) | 53 $customPath = $this->laravel->basePath(trim($stub, '/')); |
| 60 ? $customPath | 54 |
| 61 : __DIR__.$stub; | 55 return is_file($customPath) ? $customPath : __DIR__.$stub; |
| 62 } | 56 } |
| 63 | 57 |
| 64 protected function getClassName($name) | 58 /** |
| 59 * Get the path for the generated file. | |
| 60 */ | |
| 61 protected function getPath($name = null) | |
| 62 { | |
| 63 return str_replace( | |
| 64 ['App\\', '\\'], | |
| 65 ['app/', '/'], | |
| 66 $this->getControllerNamespace().'/'.$this->controller_name($this->getTableInput()).'.php' | |
| 67 ); | |
| 68 } | |
| 69 | |
| 70 /** | |
| 71 * Get the class name for the controller. | |
| 72 */ | |
| 73 protected function getClassName(string $name): string | |
| 65 { | 74 { |
| 66 return $this->controller_name($name); | 75 return $this->controller_name($name); |
| 67 } | 76 } |
| 68 | |
| 69 /** | |
| 70 * Get the stub file for the generator. | |
| 71 * | |
| 72 * @return string | |
| 73 */ | |
| 74 protected function getPath($name = null) | |
| 75 { | |
| 76 return str_replace(['App\\', '\\'], ['app/', '/'], $this->getControllerNamespace().'/'.$this->controller_name($this->getTableInput()).'.php'); | |
| 77 } | |
| 78 } | 77 } |
