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