1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules\Commands\Generators; |
4
|
|
|
|
5
|
|
|
use Rawilk\LaravelModules\Support\Config\GenerateConfigReader; |
6
|
|
|
use Rawilk\LaravelModules\Support\Stub; |
7
|
|
|
use Rawilk\LaravelModules\Traits\ModuleCommands; |
8
|
|
|
|
9
|
|
|
class JobMakeCommand extends GeneratorCommand |
10
|
|
|
{ |
11
|
|
|
use ModuleCommands; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
protected $argumentName = 'name'; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $signature = 'module:make-job |
18
|
|
|
{name : The name of the job} |
19
|
|
|
{module? : The name of the module to create the job for} |
20
|
|
|
{--sync : Indicates the job should be synchronous}'; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $description = 'Create a new job class for the specified module.'; |
24
|
|
|
|
25
|
|
|
protected function getDefaultNamespace(): string |
26
|
|
|
{ |
27
|
|
|
/** @var \Rawilk\LaravelModules\Contracts\Repository $module */ |
28
|
|
|
$module = $this->laravel['modules']; |
29
|
|
|
|
30
|
|
|
return $module->config('paths.generator.jobs.namespace') ?: $module->config('paths.generator.jobs.path', 'Jobs'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function getDestinationFilePath(): string |
34
|
|
|
{ |
35
|
|
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName()); |
36
|
|
|
|
37
|
|
|
$jobPath = GenerateConfigReader::read('jobs'); |
38
|
|
|
|
39
|
|
|
return $path . $jobPath->getPath() . '/' . $this->getFileName() . '.php'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function getTemplateContents(): string |
43
|
|
|
{ |
44
|
|
|
/** @var \Rawilk\LaravelModules\Module $module */ |
45
|
|
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName()); |
46
|
|
|
|
47
|
|
|
return (new Stub($this->getStubName(), [ |
48
|
|
|
'NAMESPACE' => $this->getClassNamespace($module), |
49
|
|
|
'CLASS' => $this->getClass(), |
50
|
|
|
]))->render(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function getStubName(): string |
54
|
|
|
{ |
55
|
|
|
if ($this->option('sync')) { |
56
|
|
|
return '/job.stub'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return '/job-queued.stub'; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|