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 MailMakeCommand extends GeneratorCommand |
||
| 12 | { |
||
| 13 | use DomainCommandTrait; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The console command name. |
||
| 17 | * |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | protected $name = 'domain:make-mail'; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The console command description. |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $description = 'Create a new email class for the specified domain'; |
||
| 28 | |||
| 29 | protected $argumentName = 'name'; |
||
| 30 | |||
| 31 | public function getDefaultNamespace(): string |
||
| 32 | { |
||
| 33 | $domain = $this->laravel['domains']; |
||
| 34 | |||
| 35 | return $domain->config('paths.generator.emails.namespace') ?: $domain->config('paths.generator.emails.path', 'Emails'); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Get the console command arguments. |
||
| 40 | * |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | protected function getArguments() |
||
| 44 | { |
||
| 45 | return [ |
||
| 46 | ['name', InputArgument::REQUIRED, 'The name of the mailable.'], |
||
| 47 | ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
||
| 48 | ]; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Get template contents. |
||
| 53 | * |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | protected function getTemplateContents() |
||
| 57 | { |
||
| 58 | $domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
||
| 59 | |||
| 60 | return (new Stub('/mail.stub', [ |
||
| 61 | 'NAMESPACE' => $this->getClassNamespace($domain), |
||
| 62 | 'CLASS' => $this->getClass(), |
||
| 63 | ]))->render(); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get the destination file path. |
||
| 68 | * |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | protected function getDestinationFilePath() |
||
| 72 | { |
||
| 73 | $path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
||
| 74 | |||
| 75 | $mailPath = GenerateConfigReader::read('emails'); |
||
| 76 | |||
| 77 | return $path . $mailPath->getPath() . '/' . $this->getFileName() . '.php'; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | private function getFileName() |
||
| 84 | { |
||
| 85 | return Str::studly($this->argument('name')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 86 | } |
||
| 87 | } |
||
| 88 |