Salah3id /
address-domains
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Salah3id\Domains\Commands; |
||
| 4 | |||
| 5 | use Illuminate\Support\Str; |
||
| 6 | use Salah3id\Domains\Support\Config\GenerateConfigReader; |
||
| 7 | use Salah3id\Domains\Support\Stub; |
||
| 8 | use Salah3id\Domains\Traits\DomainCommandTrait; |
||
| 9 | use Symfony\Component\Console\Input\InputArgument; |
||
| 10 | |||
| 11 | class RuleMakeCommand extends GeneratorCommand |
||
| 12 | { |
||
| 13 | use DomainCommandTrait; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The name of argument name. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $argumentName = 'name'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command name. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $name = 'domain:make-rule'; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The console command description. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $description = 'Create a new validation rule for the specified domain.'; |
||
| 35 | |||
| 36 | public function getDefaultNamespace(): string |
||
| 37 | { |
||
| 38 | $domain = $this->laravel['domains']; |
||
| 39 | |||
| 40 | return $domain->config('paths.generator.rules.namespace') ?: $domain->config('paths.generator.rules.path', 'Rules'); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Get the console command arguments. |
||
| 45 | * |
||
| 46 | * @return array |
||
| 47 | */ |
||
| 48 | protected function getArguments() |
||
| 49 | { |
||
| 50 | return [ |
||
| 51 | ['name', InputArgument::REQUIRED, 'The name of the rule class.'], |
||
| 52 | ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
||
| 53 | ]; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return mixed |
||
| 58 | */ |
||
| 59 | protected function getTemplateContents() |
||
| 60 | { |
||
| 61 | $domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
||
| 62 | |||
| 63 | return (new Stub('/rule.stub', [ |
||
| 64 | 'NAMESPACE' => $this->getClassNamespace($domain), |
||
| 65 | 'CLASS' => $this->getFileName(), |
||
| 66 | ]))->render(); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return mixed |
||
| 71 | */ |
||
| 72 | protected function getDestinationFilePath() |
||
| 73 | { |
||
| 74 | $path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
||
| 75 | |||
| 76 | $rulePath = GenerateConfigReader::read('rules'); |
||
| 77 | |||
| 78 | return $path . $rulePath->getPath() . '/' . $this->getFileName() . '.php'; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | private function getFileName() |
||
| 85 | { |
||
| 86 | return Str::studly($this->argument('name')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 87 | } |
||
| 88 | } |
||
| 89 |