|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Lomkit\Rest\Console\Commands; |
| 4 | + |
| 5 | +use Illuminate\Console\GeneratorCommand; |
| 6 | +use Illuminate\Contracts\Console\PromptsForMissingInput; |
| 7 | +use Illuminate\Database\Migrations\MigrationCreator; |
| 8 | +use Illuminate\Support\Composer; |
| 9 | +use Illuminate\Support\Str; |
| 10 | +use Lomkit\Rest\Console\ResolvesStubPath; |
| 11 | + |
| 12 | +class ResponseCommand extends GeneratorCommand implements PromptsForMissingInput |
| 13 | +{ |
| 14 | + use ResolvesStubPath; |
| 15 | + |
| 16 | + /** |
| 17 | + * The console command signature. |
| 18 | + * |
| 19 | + * @var string |
| 20 | + */ |
| 21 | + protected $signature = 'rest:response {name : The name of the response} |
| 22 | + {--path= : The location where the response file should be created}'; |
| 23 | + |
| 24 | + /** |
| 25 | + * The type of class being generated. |
| 26 | + * |
| 27 | + * @var string |
| 28 | + */ |
| 29 | + protected $type = 'Response'; |
| 30 | + |
| 31 | + /** |
| 32 | + * The console command description. |
| 33 | + * |
| 34 | + * @var string |
| 35 | + */ |
| 36 | + protected $description = 'Create a new response class'; |
| 37 | + |
| 38 | + public function handle() |
| 39 | + { |
| 40 | + parent::handle(); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * Build the class with the given name. |
| 45 | + * |
| 46 | + * @param string $name |
| 47 | + * @return string |
| 48 | + */ |
| 49 | + protected function buildClass($name) |
| 50 | + { |
| 51 | + $replace = []; |
| 52 | + |
| 53 | + return str_replace( |
| 54 | + array_keys($replace), array_values($replace), parent::buildClass($name) |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Get the stub file for the generator. |
| 60 | + * |
| 61 | + * @return string |
| 62 | + */ |
| 63 | + protected function getStub() |
| 64 | + { |
| 65 | + return $this->resolveStubPath('/stubs/rest/response.stub'); |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Get the default namespace for the class. |
| 70 | + * |
| 71 | + * @param string $rootNamespace |
| 72 | + * @return string |
| 73 | + */ |
| 74 | + protected function getDefaultNamespace($rootNamespace) |
| 75 | + { |
| 76 | + return $rootNamespace.'\Rest\Responses'; |
| 77 | + } |
| 78 | +} |
0 commit comments