1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MyBuilder\Cronos\Formatter; |
4
|
|
|
|
5
|
|
|
class Job |
6
|
|
|
{ |
7
|
|
|
/** @var Cron */ |
8
|
|
|
private $cron; |
9
|
|
|
|
10
|
|
|
/** @var Time */ |
11
|
|
|
private $time; |
12
|
|
|
|
13
|
|
|
/** @var string */ |
14
|
|
|
private $command; |
15
|
|
|
|
16
|
|
|
/** @var Output */ |
17
|
|
|
private $output; |
18
|
|
|
|
19
|
|
|
public function __construct(string $command, Cron $cron) |
20
|
|
|
{ |
21
|
|
|
$this->cron = $cron; |
22
|
|
|
$this->time = new Time; |
23
|
|
|
$this->command = $command; |
24
|
|
|
$this->output = new Output; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** @see Time::setMinute */ |
28
|
|
|
public function setMinute(string $value): self |
29
|
|
|
{ |
30
|
|
|
$this->time->setMinute($value); |
31
|
|
|
|
32
|
|
|
return $this; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** @see Time::setHour */ |
36
|
|
|
public function setHour(string $value): self |
37
|
|
|
{ |
38
|
|
|
$this->time->setHour($value); |
39
|
|
|
|
40
|
|
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** @see Time::setDayOfMonth */ |
44
|
|
|
public function setDayOfMonth(string $value): self |
45
|
|
|
{ |
46
|
|
|
$this->time->setDayOfMonth($value); |
47
|
|
|
|
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** @see Time::setMonth */ |
52
|
|
|
public function setMonth(string $value): self |
53
|
|
|
{ |
54
|
|
|
$this->time->setMonth($value); |
55
|
|
|
|
56
|
|
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** @see Time::setDayOfWeek */ |
60
|
|
|
public function setDayOfWeek(string$value): self |
61
|
|
|
{ |
62
|
|
|
$this->time->setDayOfWeek($value); |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Suppress the output of this command when executed |
69
|
|
|
* |
70
|
|
|
* @see Output::suppressOutput |
71
|
|
|
*/ |
72
|
|
|
public function suppressOutput(): self |
73
|
|
|
{ |
74
|
|
|
$this->output->suppressOutput(); |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** @see Output::setStandardOutFile */ |
80
|
|
|
public function setStandardOutFile(string $filePath): self |
81
|
|
|
{ |
82
|
|
|
$this->output->setStandardOutFile($filePath); |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** @see Output::appendStandardOutToFile */ |
88
|
|
|
public function appendStandardOutToFile(string $filePath): self |
89
|
|
|
{ |
90
|
|
|
$this->output->appendStandardOutToFile($filePath); |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** @see Output::setStandardErrorFile */ |
96
|
|
|
public function setStandardErrorFile(string $filePath): self |
97
|
|
|
{ |
98
|
|
|
$this->output->setStandardErrorFile($filePath); |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** @see Output::appendStandardErrorToFile */ |
104
|
|
|
public function appendStandardErrorToFile(string $filePath): self |
105
|
|
|
{ |
106
|
|
|
$this->output->appendStandardErrorToFile($filePath); |
107
|
|
|
|
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function end(): Cron |
112
|
|
|
{ |
113
|
|
|
return $this->cron; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function format(): string |
117
|
|
|
{ |
118
|
|
|
return |
119
|
|
|
$this->time->format() . |
120
|
|
|
$this->command . |
121
|
|
|
$this->output->format() . |
122
|
|
|
\PHP_EOL; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|