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