|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Foundation\Generator\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Foundation\Generator\Abstracts\AbstractGeneratorCommand; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
|
|
8
|
|
|
class JobMakeCommand extends AbstractGeneratorCommand |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* The console command name. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $name = 'larapi:make:job'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Create a new job class for the specified module'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The name of the generated resource. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $generatorName = 'job'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* The file path. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $filePath = '/Jobs'; |
|
38
|
|
|
|
|
39
|
|
|
protected function stubOptions(): array |
|
40
|
|
|
{ |
|
41
|
|
|
return [ |
|
42
|
|
|
'NAMESPACE' => $this->getClassNamespace(), |
|
43
|
|
|
'CLASS' => $this->getClassName(), |
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Get the console command options. |
|
49
|
|
|
* |
|
50
|
|
|
* @return array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function getOptions() |
|
53
|
|
|
{ |
|
54
|
|
|
return [ |
|
55
|
|
|
['sync', null, InputOption::VALUE_NONE, 'Indicates that job should be synchronous.'], |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
protected function isJobSynchronous(): bool |
|
60
|
|
|
{ |
|
61
|
|
|
return once(function () { |
|
62
|
|
|
$option = $this->option('sync'); |
|
63
|
|
|
return app()->runningInConsole() && !$option ? $this->confirm('Should the job run Synchronously?',false) : $option; |
|
|
|
|
|
|
64
|
|
|
}); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @return string |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function stubName(): string |
|
71
|
|
|
{ |
|
72
|
|
|
if ($this->isJobSynchronous()) { |
|
73
|
|
|
return 'job.stub'; |
|
74
|
|
|
} |
|
75
|
|
|
return 'job-queued.stub'; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|