1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pheanstalk\Structure; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* A job in a EvQueue server. |
7
|
|
|
* |
8
|
|
|
* @author Valentin Corre |
9
|
|
|
* @package Pheanstalk |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php |
11
|
|
|
*/ |
12
|
|
|
class Task extends ParameterManipulations |
13
|
|
|
{ |
14
|
|
|
const OUTPUT_TEXT = "TEXT"; |
15
|
|
|
const PARAMETER_MODE_CMD = "CMDLINE"; |
16
|
|
|
const STRING_TRUE = 'yes'; |
17
|
|
|
const STRING_FALSE = 'no'; |
18
|
|
|
|
19
|
|
|
/** @var string $outputMethod */ |
20
|
|
|
protected $outputMethod; |
21
|
|
|
|
22
|
|
|
/** @var string $parametersMode */ |
23
|
|
|
protected $parametersMode; |
24
|
|
|
|
25
|
|
|
/** @var string $path */ |
26
|
|
|
protected $path; |
27
|
|
|
|
28
|
|
|
/** @var string string $queue */ |
29
|
|
|
protected $queue; |
30
|
|
|
|
31
|
|
|
/** @var string|null $host */ |
32
|
|
|
protected $host; |
33
|
|
|
|
34
|
|
|
/** @var string|null $user */ |
35
|
|
|
protected $user; |
36
|
|
|
|
37
|
|
|
/** @var bool */ |
38
|
|
|
protected $useAgent; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $path The command that should be executed by the server |
42
|
|
|
* @param string $queue The queue used by the Task |
43
|
|
|
* @param bool $useAgent Tell if you want to use the EvQueue Agent (Used to send status of tasks) |
44
|
|
|
* @param string|null $user The user that will execute the command |
45
|
|
|
* @param string|null $host The Ip address where to execute the command |
46
|
|
|
* @param string $outputMethod The output mode |
47
|
|
|
* @param string $parametersMode The type of parameters |
48
|
|
|
*/ |
49
|
22 |
|
public function __construct( |
50
|
|
|
$path, |
51
|
|
|
$queue, |
52
|
|
|
$useAgent = false, |
53
|
|
|
$user = null, |
54
|
|
|
$host = null, |
55
|
|
|
$outputMethod = self::OUTPUT_TEXT, |
56
|
|
|
$parametersMode = self::PARAMETER_MODE_CMD |
57
|
|
|
) { |
58
|
22 |
|
$this->path = $path; |
59
|
22 |
|
$this->queue = $queue; |
60
|
22 |
|
$this->useAgent = $useAgent; |
61
|
22 |
|
$this->user = $user; |
62
|
22 |
|
$this->host = $host; |
63
|
22 |
|
$this->outputMethod = $outputMethod; |
64
|
22 |
|
$this->parametersMode = $parametersMode; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
8 |
|
public function getOutputMethod(): string |
71
|
|
|
{ |
72
|
8 |
|
return $this->outputMethod; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param string $outputMethod |
77
|
|
|
* |
78
|
|
|
* @return Task |
79
|
|
|
*/ |
80
|
1 |
|
public function setOutputMethod(string $outputMethod): Task |
81
|
|
|
{ |
82
|
1 |
|
$this->outputMethod = $outputMethod; |
83
|
1 |
|
return $this; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
8 |
|
public function getParametersMode(): string |
90
|
|
|
{ |
91
|
8 |
|
return $this->parametersMode; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $parametersMode |
96
|
|
|
* |
97
|
|
|
* @return Task |
98
|
|
|
*/ |
99
|
1 |
|
public function setParametersMode(string $parametersMode): Task |
100
|
|
|
{ |
101
|
1 |
|
$this->parametersMode = $parametersMode; |
102
|
1 |
|
return $this; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return string |
107
|
|
|
*/ |
108
|
8 |
|
public function getPath(): string |
109
|
|
|
{ |
110
|
8 |
|
return $this->path; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $path |
115
|
|
|
* |
116
|
|
|
* @return Task |
117
|
|
|
*/ |
118
|
2 |
|
public function setPath(string $path): Task |
119
|
|
|
{ |
120
|
2 |
|
$this->path = $path; |
121
|
2 |
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return string |
126
|
|
|
*/ |
127
|
8 |
|
public function getQueue(): string |
128
|
|
|
{ |
129
|
8 |
|
return $this->queue; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param string $queue |
134
|
|
|
* |
135
|
|
|
* @return Task |
136
|
|
|
*/ |
137
|
1 |
|
public function setQueue(string $queue): Task |
138
|
|
|
{ |
139
|
1 |
|
$this->queue = $queue; |
140
|
1 |
|
return $this; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string|null |
145
|
|
|
*/ |
146
|
8 |
|
public function getHost(): ?string |
147
|
|
|
{ |
148
|
8 |
|
return $this->host; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param string|null $host |
153
|
|
|
* |
154
|
|
|
* @return Task |
155
|
|
|
*/ |
156
|
1 |
|
public function setHost(?string $host): Task |
157
|
|
|
{ |
158
|
1 |
|
$this->host = $host; |
159
|
1 |
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @return string|null |
164
|
|
|
*/ |
165
|
8 |
|
public function getUser(): ?string |
166
|
|
|
{ |
167
|
8 |
|
return $this->user; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param string|null $user |
172
|
|
|
* |
173
|
|
|
* @return Task |
174
|
|
|
*/ |
175
|
1 |
|
public function setUser(?string $user): Task |
176
|
|
|
{ |
177
|
1 |
|
$this->user = $user; |
178
|
1 |
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @param bool $string |
183
|
|
|
* |
184
|
|
|
* @return bool|string |
185
|
|
|
*/ |
186
|
8 |
|
public function getUseAgent($string = true) |
187
|
|
|
{ |
188
|
8 |
|
if ($string) { |
189
|
8 |
|
return $this->useAgent ? self::STRING_TRUE : self::STRING_FALSE; |
190
|
|
|
} |
191
|
1 |
|
return $this->useAgent; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param bool $agent |
196
|
|
|
* |
197
|
|
|
* @return Task |
198
|
|
|
*/ |
199
|
1 |
|
public function setUseAgent(bool $agent): Task |
200
|
|
|
{ |
201
|
1 |
|
$this->useAgent = $agent; |
202
|
1 |
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @return \DOMDocument |
207
|
|
|
* @throws \ReflectionException |
208
|
|
|
*/ |
209
|
7 |
|
public function getXml() |
210
|
|
|
{ |
211
|
7 |
|
$reflection = new \ReflectionClass($this); |
212
|
7 |
|
$dom = new \DOMDocument("1.0", "utf-8"); |
213
|
7 |
|
$root = $dom->createElement("task"); |
214
|
7 |
|
foreach ($reflection->getProperties() as $property) { |
215
|
7 |
|
$value = $this->{'get'.ucfirst($property->getName())}(); |
216
|
7 |
|
$root->setAttribute($this->fromCamelCase($property->getName(), '-'), $value); |
217
|
|
|
} |
218
|
7 |
|
$dom->appendChild($root); |
219
|
7 |
|
return $dom; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|