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