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 | use Symfony\Component\Console\Input\InputOption; |
||
| 11 | |||
| 12 | class JobMakeCommand extends GeneratorCommand |
||
| 13 | { |
||
| 14 | use DomainCommandTrait; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The console command name. |
||
| 18 | * |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected $name = 'domain:make-job'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The console command description. |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $description = 'Create a new job class for the specified domain'; |
||
| 29 | |||
| 30 | protected $argumentName = 'name'; |
||
| 31 | |||
| 32 | public function getDefaultNamespace(): string |
||
| 33 | { |
||
| 34 | $domain = $this->laravel['domains']; |
||
| 35 | |||
| 36 | return $domain->config('paths.generator.jobs.namespace') ?: $domain->config('paths.generator.jobs.path', 'Jobs'); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Get the console command arguments. |
||
| 41 | * |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | protected function getArguments() |
||
| 45 | { |
||
| 46 | return [ |
||
| 47 | ['name', InputArgument::REQUIRED, 'The name of the job.'], |
||
| 48 | ['domain', InputArgument::OPTIONAL, 'The name of domain will be used.'], |
||
| 49 | ]; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Get the console command options. |
||
| 54 | * |
||
| 55 | * @return array |
||
| 56 | */ |
||
| 57 | protected function getOptions() |
||
| 58 | { |
||
| 59 | return [ |
||
| 60 | ['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'], |
||
| 61 | ]; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get template contents. |
||
| 66 | * |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | protected function getTemplateContents() |
||
| 70 | { |
||
| 71 | $domain = $this->laravel['domains']->findOrFail($this->getDomainName()); |
||
| 72 | |||
| 73 | return (new Stub($this->getStubName(), [ |
||
| 74 | 'NAMESPACE' => $this->getClassNamespace($domain), |
||
| 75 | 'CLASS' => $this->getClass(), |
||
| 76 | ]))->render(); |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Get the destination file path. |
||
| 81 | * |
||
| 82 | * @return string |
||
| 83 | */ |
||
| 84 | protected function getDestinationFilePath() |
||
| 85 | { |
||
| 86 | $path = $this->laravel['domains']->getDomainPath($this->getDomainName()); |
||
| 87 | |||
| 88 | $jobPath = GenerateConfigReader::read('jobs'); |
||
| 89 | |||
| 90 | return $path . $jobPath->getPath() . '/' . $this->getFileName() . '.php'; |
||
| 91 | } |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | private function getFileName() |
||
| 97 | { |
||
| 98 | return Str::studly($this->argument('name')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @return string |
||
| 103 | */ |
||
| 104 | protected function getStubName(): string |
||
| 105 | { |
||
| 106 | if ($this->option('sync')) { |
||
| 107 | return '/job.stub'; |
||
| 108 | } |
||
| 109 | |||
| 110 | return '/job-queued.stub'; |
||
| 111 | } |
||
| 112 | } |
||
| 113 |