| @@ 9-86 (lines=78) @@ | ||
| 6 | use Nwidart\Modules\Traits\ModuleCommandTrait; |
|
| 7 | use Symfony\Component\Console\Input\InputArgument; |
|
| 8 | ||
| 9 | class GenerateJobCommand extends GeneratorCommand |
|
| 10 | { |
|
| 11 | use ModuleCommandTrait; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * The console command name. |
|
| 15 | * |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | protected $name = 'module:make-job'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The console command description. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Generate a new Job Class for the specified module'; |
|
| 26 | ||
| 27 | protected $argumentName = 'name'; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Get the console command arguments. |
|
| 31 | * |
|
| 32 | * @return array |
|
| 33 | */ |
|
| 34 | protected function getArguments() |
|
| 35 | { |
|
| 36 | return [ |
|
| 37 | ['name', InputArgument::REQUIRED, 'The name of the job.'], |
|
| 38 | ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
|
| 39 | ]; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Get template contents. |
|
| 44 | * |
|
| 45 | * @return string |
|
| 46 | */ |
|
| 47 | protected function getTemplateContents() |
|
| 48 | { |
|
| 49 | $module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
| 50 | ||
| 51 | return (new Stub('/job.stub', [ |
|
| 52 | 'NAMESPACE' => $this->getClassNamespace($module), |
|
| 53 | 'CLASS' => $this->getClass(), |
|
| 54 | ]))->render(); |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * Get the destination file path. |
|
| 59 | * |
|
| 60 | * @return string |
|
| 61 | */ |
|
| 62 | protected function getDestinationFilePath() |
|
| 63 | { |
|
| 64 | $path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
| 65 | ||
| 66 | $jobPath = $this->laravel['modules']->config('paths.generator.jobs'); |
|
| 67 | ||
| 68 | return $path . $jobPath . '/' . $this->getFileName() . '.php'; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @return string |
|
| 73 | */ |
|
| 74 | private function getFileName() |
|
| 75 | { |
|
| 76 | return studly_case($this->argument('name')); |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @return string |
|
| 81 | */ |
|
| 82 | public function getDefaultNamespace() |
|
| 83 | { |
|
| 84 | return 'Jobs'; |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||
| @@ 9-86 (lines=78) @@ | ||
| 6 | use Nwidart\Modules\Traits\ModuleCommandTrait; |
|
| 7 | use Symfony\Component\Console\Input\InputArgument; |
|
| 8 | ||
| 9 | class GenerateMailCommand extends GeneratorCommand |
|
| 10 | { |
|
| 11 | use ModuleCommandTrait; |
|
| 12 | ||
| 13 | /** |
|
| 14 | * The console command name. |
|
| 15 | * |
|
| 16 | * @var string |
|
| 17 | */ |
|
| 18 | protected $name = 'module:make-mail'; |
|
| 19 | ||
| 20 | /** |
|
| 21 | * The console command description. |
|
| 22 | * |
|
| 23 | * @var string |
|
| 24 | */ |
|
| 25 | protected $description = 'Generate a new Mailable Class for the specified module'; |
|
| 26 | ||
| 27 | protected $argumentName = 'name'; |
|
| 28 | ||
| 29 | /** |
|
| 30 | * Get the console command arguments. |
|
| 31 | * |
|
| 32 | * @return array |
|
| 33 | */ |
|
| 34 | protected function getArguments() |
|
| 35 | { |
|
| 36 | return [ |
|
| 37 | ['name', InputArgument::REQUIRED, 'The name of the mailable.'], |
|
| 38 | ['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
|
| 39 | ]; |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * Get template contents. |
|
| 44 | * |
|
| 45 | * @return string |
|
| 46 | */ |
|
| 47 | protected function getTemplateContents() |
|
| 48 | { |
|
| 49 | $module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
|
| 50 | ||
| 51 | return (new Stub('/mail.stub', [ |
|
| 52 | 'NAMESPACE' => $this->getClassNamespace($module), |
|
| 53 | 'CLASS' => $this->getClass(), |
|
| 54 | ]))->render(); |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * Get the destination file path. |
|
| 59 | * |
|
| 60 | * @return string |
|
| 61 | */ |
|
| 62 | protected function getDestinationFilePath() |
|
| 63 | { |
|
| 64 | $path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
|
| 65 | ||
| 66 | $mailPath = $this->laravel['modules']->config('paths.generator.mail'); |
|
| 67 | ||
| 68 | return $path . $mailPath . '/' . $this->getFileName() . '.php'; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @return string |
|
| 73 | */ |
|
| 74 | private function getFileName() |
|
| 75 | { |
|
| 76 | return studly_case($this->argument('name')); |
|
| 77 | } |
|
| 78 | ||
| 79 | /** |
|
| 80 | * @return string |
|
| 81 | */ |
|
| 82 | public function getDefaultNamespace() |
|
| 83 | { |
|
| 84 | return 'Mail'; |
|
| 85 | } |
|
| 86 | } |
|
| 87 | ||